2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Derived from many drivers using generic_serial interface.
8 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
10 * Serial driver for BCM63xx integrated UART.
12 * Hardware flow control was _not_ tested since I only have RX/TX on
16 #if defined(CONFIG_SERIAL_BCM63XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
20 #include <linux/kernel.h>
21 #include <linux/platform_device.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/module.h>
25 #include <linux/console.h>
26 #include <linux/clk.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/sysrq.h>
30 #include <linux/serial.h>
31 #include <linux/serial_core.h>
32 #include <linux/serial_bcm63xx.h>
34 #define BCM63XX_NR_UARTS 2
36 static struct uart_port ports
[BCM63XX_NR_UARTS
];
39 * rx interrupt mask / stat
43 * - rx fifo above threshold
44 * - rx fifo not empty for too long
46 #define UART_RX_INT_MASK (UART_IR_MASK(UART_IR_RXOVER) | \
47 UART_IR_MASK(UART_IR_RXTHRESH) | \
48 UART_IR_MASK(UART_IR_RXTIMEOUT))
50 #define UART_RX_INT_STAT (UART_IR_STAT(UART_IR_RXOVER) | \
51 UART_IR_STAT(UART_IR_RXTHRESH) | \
52 UART_IR_STAT(UART_IR_RXTIMEOUT))
55 * tx interrupt mask / stat
59 * - tx fifo below threshold
61 #define UART_TX_INT_MASK (UART_IR_MASK(UART_IR_TXEMPTY) | \
62 UART_IR_MASK(UART_IR_TXTRESH))
64 #define UART_TX_INT_STAT (UART_IR_STAT(UART_IR_TXEMPTY) | \
65 UART_IR_STAT(UART_IR_TXTRESH))
68 * external input interrupt
70 * mask: any edge on CTS, DCD
72 #define UART_EXTINP_INT_MASK (UART_EXTINP_IRMASK(UART_EXTINP_IR_CTS) | \
73 UART_EXTINP_IRMASK(UART_EXTINP_IR_DCD))
76 * handy uart register accessor
78 static inline unsigned int bcm_uart_readl(struct uart_port
*port
,
81 return __raw_readl(port
->membase
+ offset
);
84 static inline void bcm_uart_writel(struct uart_port
*port
,
85 unsigned int value
, unsigned int offset
)
87 __raw_writel(value
, port
->membase
+ offset
);
91 * serial core request to check if uart tx fifo is empty
93 static unsigned int bcm_uart_tx_empty(struct uart_port
*port
)
97 val
= bcm_uart_readl(port
, UART_IR_REG
);
98 return (val
& UART_IR_STAT(UART_IR_TXEMPTY
)) ? 1 : 0;
102 * serial core request to set RTS and DTR pin state and loopback mode
104 static void bcm_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
108 val
= bcm_uart_readl(port
, UART_MCTL_REG
);
109 val
&= ~(UART_MCTL_DTR_MASK
| UART_MCTL_RTS_MASK
);
110 /* invert of written value is reflected on the pin */
111 if (!(mctrl
& TIOCM_DTR
))
112 val
|= UART_MCTL_DTR_MASK
;
113 if (!(mctrl
& TIOCM_RTS
))
114 val
|= UART_MCTL_RTS_MASK
;
115 bcm_uart_writel(port
, val
, UART_MCTL_REG
);
117 val
= bcm_uart_readl(port
, UART_CTL_REG
);
118 if (mctrl
& TIOCM_LOOP
)
119 val
|= UART_CTL_LOOPBACK_MASK
;
121 val
&= ~UART_CTL_LOOPBACK_MASK
;
122 bcm_uart_writel(port
, val
, UART_CTL_REG
);
126 * serial core request to return RI, CTS, DCD and DSR pin state
128 static unsigned int bcm_uart_get_mctrl(struct uart_port
*port
)
130 unsigned int val
, mctrl
;
133 val
= bcm_uart_readl(port
, UART_EXTINP_REG
);
134 if (val
& UART_EXTINP_RI_MASK
)
136 if (val
& UART_EXTINP_CTS_MASK
)
138 if (val
& UART_EXTINP_DCD_MASK
)
140 if (val
& UART_EXTINP_DSR_MASK
)
146 * serial core request to disable tx ASAP (used for flow control)
148 static void bcm_uart_stop_tx(struct uart_port
*port
)
152 val
= bcm_uart_readl(port
, UART_CTL_REG
);
153 val
&= ~(UART_CTL_TXEN_MASK
);
154 bcm_uart_writel(port
, val
, UART_CTL_REG
);
156 val
= bcm_uart_readl(port
, UART_IR_REG
);
157 val
&= ~UART_TX_INT_MASK
;
158 bcm_uart_writel(port
, val
, UART_IR_REG
);
162 * serial core request to (re)enable tx
164 static void bcm_uart_start_tx(struct uart_port
*port
)
168 val
= bcm_uart_readl(port
, UART_IR_REG
);
169 val
|= UART_TX_INT_MASK
;
170 bcm_uart_writel(port
, val
, UART_IR_REG
);
172 val
= bcm_uart_readl(port
, UART_CTL_REG
);
173 val
|= UART_CTL_TXEN_MASK
;
174 bcm_uart_writel(port
, val
, UART_CTL_REG
);
178 * serial core request to stop rx, called before port shutdown
180 static void bcm_uart_stop_rx(struct uart_port
*port
)
184 val
= bcm_uart_readl(port
, UART_IR_REG
);
185 val
&= ~UART_RX_INT_MASK
;
186 bcm_uart_writel(port
, val
, UART_IR_REG
);
190 * serial core request to enable modem status interrupt reporting
192 static void bcm_uart_enable_ms(struct uart_port
*port
)
196 val
= bcm_uart_readl(port
, UART_IR_REG
);
197 val
|= UART_IR_MASK(UART_IR_EXTIP
);
198 bcm_uart_writel(port
, val
, UART_IR_REG
);
202 * serial core request to start/stop emitting break char
204 static void bcm_uart_break_ctl(struct uart_port
*port
, int ctl
)
209 spin_lock_irqsave(&port
->lock
, flags
);
211 val
= bcm_uart_readl(port
, UART_CTL_REG
);
213 val
|= UART_CTL_XMITBRK_MASK
;
215 val
&= ~UART_CTL_XMITBRK_MASK
;
216 bcm_uart_writel(port
, val
, UART_CTL_REG
);
218 spin_unlock_irqrestore(&port
->lock
, flags
);
222 * return port type in string format
224 static const char *bcm_uart_type(struct uart_port
*port
)
226 return (port
->type
== PORT_BCM63XX
) ? "bcm63xx_uart" : NULL
;
230 * read all chars in rx fifo and send them to core
232 static void bcm_uart_do_rx(struct uart_port
*port
)
234 struct tty_port
*tty_port
= &port
->state
->port
;
235 unsigned int max_count
;
237 /* limit number of char read in interrupt, should not be
238 * higher than fifo size anyway since we're much faster than
242 unsigned int iestat
, c
, cstat
;
245 /* get overrun/fifo empty information from ier
247 iestat
= bcm_uart_readl(port
, UART_IR_REG
);
249 if (unlikely(iestat
& UART_IR_STAT(UART_IR_RXOVER
))) {
252 /* fifo reset is required to clear
254 val
= bcm_uart_readl(port
, UART_CTL_REG
);
255 val
|= UART_CTL_RSTRXFIFO_MASK
;
256 bcm_uart_writel(port
, val
, UART_CTL_REG
);
258 port
->icount
.overrun
++;
259 tty_insert_flip_char(tty_port
, 0, TTY_OVERRUN
);
262 if (!(iestat
& UART_IR_STAT(UART_IR_RXNOTEMPTY
)))
265 cstat
= c
= bcm_uart_readl(port
, UART_FIFO_REG
);
270 if (unlikely((cstat
& UART_FIFO_ANYERR_MASK
))) {
272 if (cstat
& UART_FIFO_BRKDET_MASK
) {
274 if (uart_handle_break(port
))
278 if (cstat
& UART_FIFO_PARERR_MASK
)
279 port
->icount
.parity
++;
280 if (cstat
& UART_FIFO_FRAMEERR_MASK
)
281 port
->icount
.frame
++;
283 /* update flag wrt read_status_mask */
284 cstat
&= port
->read_status_mask
;
285 if (cstat
& UART_FIFO_BRKDET_MASK
)
287 if (cstat
& UART_FIFO_FRAMEERR_MASK
)
289 if (cstat
& UART_FIFO_PARERR_MASK
)
293 if (uart_handle_sysrq_char(port
, c
))
297 if ((cstat
& port
->ignore_status_mask
) == 0)
298 tty_insert_flip_char(tty_port
, c
, flag
);
300 } while (--max_count
);
302 spin_unlock(&port
->lock
);
303 tty_flip_buffer_push(tty_port
);
304 spin_lock(&port
->lock
);
308 * fill tx fifo with chars to send, stop when fifo is about to be full
309 * or when all chars have been sent.
311 static void bcm_uart_do_tx(struct uart_port
*port
)
313 struct circ_buf
*xmit
;
314 unsigned int val
, max_count
;
317 bcm_uart_writel(port
, port
->x_char
, UART_FIFO_REG
);
323 if (uart_tx_stopped(port
)) {
324 bcm_uart_stop_tx(port
);
328 xmit
= &port
->state
->xmit
;
329 if (uart_circ_empty(xmit
))
332 val
= bcm_uart_readl(port
, UART_MCTL_REG
);
333 val
= (val
& UART_MCTL_TXFIFOFILL_MASK
) >> UART_MCTL_TXFIFOFILL_SHIFT
;
334 max_count
= port
->fifosize
- val
;
336 while (max_count
--) {
339 c
= xmit
->buf
[xmit
->tail
];
340 bcm_uart_writel(port
, c
, UART_FIFO_REG
);
341 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
343 if (uart_circ_empty(xmit
))
347 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
348 uart_write_wakeup(port
);
350 if (uart_circ_empty(xmit
))
355 /* nothing to send, disable transmit interrupt */
356 val
= bcm_uart_readl(port
, UART_IR_REG
);
357 val
&= ~UART_TX_INT_MASK
;
358 bcm_uart_writel(port
, val
, UART_IR_REG
);
363 * process uart interrupt
365 static irqreturn_t
bcm_uart_interrupt(int irq
, void *dev_id
)
367 struct uart_port
*port
;
368 unsigned int irqstat
;
371 spin_lock(&port
->lock
);
373 irqstat
= bcm_uart_readl(port
, UART_IR_REG
);
374 if (irqstat
& UART_RX_INT_STAT
)
375 bcm_uart_do_rx(port
);
377 if (irqstat
& UART_TX_INT_STAT
)
378 bcm_uart_do_tx(port
);
380 if (irqstat
& UART_IR_MASK(UART_IR_EXTIP
)) {
383 estat
= bcm_uart_readl(port
, UART_EXTINP_REG
);
384 if (estat
& UART_EXTINP_IRSTAT(UART_EXTINP_IR_CTS
))
385 uart_handle_cts_change(port
,
386 estat
& UART_EXTINP_CTS_MASK
);
387 if (estat
& UART_EXTINP_IRSTAT(UART_EXTINP_IR_DCD
))
388 uart_handle_dcd_change(port
,
389 estat
& UART_EXTINP_DCD_MASK
);
392 spin_unlock(&port
->lock
);
397 * enable rx & tx operation on uart
399 static void bcm_uart_enable(struct uart_port
*port
)
403 val
= bcm_uart_readl(port
, UART_CTL_REG
);
404 val
|= (UART_CTL_BRGEN_MASK
| UART_CTL_TXEN_MASK
| UART_CTL_RXEN_MASK
);
405 bcm_uart_writel(port
, val
, UART_CTL_REG
);
409 * disable rx & tx operation on uart
411 static void bcm_uart_disable(struct uart_port
*port
)
415 val
= bcm_uart_readl(port
, UART_CTL_REG
);
416 val
&= ~(UART_CTL_BRGEN_MASK
| UART_CTL_TXEN_MASK
|
418 bcm_uart_writel(port
, val
, UART_CTL_REG
);
422 * clear all unread data in rx fifo and unsent data in tx fifo
424 static void bcm_uart_flush(struct uart_port
*port
)
428 /* empty rx and tx fifo */
429 val
= bcm_uart_readl(port
, UART_CTL_REG
);
430 val
|= UART_CTL_RSTRXFIFO_MASK
| UART_CTL_RSTTXFIFO_MASK
;
431 bcm_uart_writel(port
, val
, UART_CTL_REG
);
433 /* read any pending char to make sure all irq status are
435 (void)bcm_uart_readl(port
, UART_FIFO_REG
);
439 * serial core request to initialize uart and start rx operation
441 static int bcm_uart_startup(struct uart_port
*port
)
446 /* mask all irq and flush port */
447 bcm_uart_disable(port
);
448 bcm_uart_writel(port
, 0, UART_IR_REG
);
449 bcm_uart_flush(port
);
451 /* clear any pending external input interrupt */
452 (void)bcm_uart_readl(port
, UART_EXTINP_REG
);
454 /* set rx/tx fifo thresh to fifo half size */
455 val
= bcm_uart_readl(port
, UART_MCTL_REG
);
456 val
&= ~(UART_MCTL_RXFIFOTHRESH_MASK
| UART_MCTL_TXFIFOTHRESH_MASK
);
457 val
|= (port
->fifosize
/ 2) << UART_MCTL_RXFIFOTHRESH_SHIFT
;
458 val
|= (port
->fifosize
/ 2) << UART_MCTL_TXFIFOTHRESH_SHIFT
;
459 bcm_uart_writel(port
, val
, UART_MCTL_REG
);
461 /* set rx fifo timeout to 1 char time */
462 val
= bcm_uart_readl(port
, UART_CTL_REG
);
463 val
&= ~UART_CTL_RXTMOUTCNT_MASK
;
464 val
|= 1 << UART_CTL_RXTMOUTCNT_SHIFT
;
465 bcm_uart_writel(port
, val
, UART_CTL_REG
);
467 /* report any edge on dcd and cts */
468 val
= UART_EXTINP_INT_MASK
;
469 val
|= UART_EXTINP_DCD_NOSENSE_MASK
;
470 val
|= UART_EXTINP_CTS_NOSENSE_MASK
;
471 bcm_uart_writel(port
, val
, UART_EXTINP_REG
);
473 /* register irq and enable rx interrupts */
474 ret
= request_irq(port
->irq
, bcm_uart_interrupt
, 0,
475 bcm_uart_type(port
), port
);
478 bcm_uart_writel(port
, UART_RX_INT_MASK
, UART_IR_REG
);
479 bcm_uart_enable(port
);
484 * serial core request to flush & disable uart
486 static void bcm_uart_shutdown(struct uart_port
*port
)
490 spin_lock_irqsave(&port
->lock
, flags
);
491 bcm_uart_writel(port
, 0, UART_IR_REG
);
492 spin_unlock_irqrestore(&port
->lock
, flags
);
494 bcm_uart_disable(port
);
495 bcm_uart_flush(port
);
496 free_irq(port
->irq
, port
);
500 * serial core request to change current uart setting
502 static void bcm_uart_set_termios(struct uart_port
*port
,
503 struct ktermios
*new,
504 struct ktermios
*old
)
506 unsigned int ctl
, baud
, quot
, ier
;
509 spin_lock_irqsave(&port
->lock
, flags
);
511 /* disable uart while changing speed */
512 bcm_uart_disable(port
);
513 bcm_uart_flush(port
);
515 /* update Control register */
516 ctl
= bcm_uart_readl(port
, UART_CTL_REG
);
517 ctl
&= ~UART_CTL_BITSPERSYM_MASK
;
519 switch (new->c_cflag
& CSIZE
) {
521 ctl
|= (0 << UART_CTL_BITSPERSYM_SHIFT
);
524 ctl
|= (1 << UART_CTL_BITSPERSYM_SHIFT
);
527 ctl
|= (2 << UART_CTL_BITSPERSYM_SHIFT
);
530 ctl
|= (3 << UART_CTL_BITSPERSYM_SHIFT
);
534 ctl
&= ~UART_CTL_STOPBITS_MASK
;
535 if (new->c_cflag
& CSTOPB
)
536 ctl
|= UART_CTL_STOPBITS_2
;
538 ctl
|= UART_CTL_STOPBITS_1
;
540 ctl
&= ~(UART_CTL_RXPAREN_MASK
| UART_CTL_TXPAREN_MASK
);
541 if (new->c_cflag
& PARENB
)
542 ctl
|= (UART_CTL_RXPAREN_MASK
| UART_CTL_TXPAREN_MASK
);
543 ctl
&= ~(UART_CTL_RXPAREVEN_MASK
| UART_CTL_TXPAREVEN_MASK
);
544 if (new->c_cflag
& PARODD
)
545 ctl
|= (UART_CTL_RXPAREVEN_MASK
| UART_CTL_TXPAREVEN_MASK
);
546 bcm_uart_writel(port
, ctl
, UART_CTL_REG
);
548 /* update Baudword register */
549 baud
= uart_get_baud_rate(port
, new, old
, 0, port
->uartclk
/ 16);
550 quot
= uart_get_divisor(port
, baud
) - 1;
551 bcm_uart_writel(port
, quot
, UART_BAUD_REG
);
553 /* update Interrupt register */
554 ier
= bcm_uart_readl(port
, UART_IR_REG
);
556 ier
&= ~UART_IR_MASK(UART_IR_EXTIP
);
557 if (UART_ENABLE_MS(port
, new->c_cflag
))
558 ier
|= UART_IR_MASK(UART_IR_EXTIP
);
560 bcm_uart_writel(port
, ier
, UART_IR_REG
);
562 /* update read/ignore mask */
563 port
->read_status_mask
= UART_FIFO_VALID_MASK
;
564 if (new->c_iflag
& INPCK
) {
565 port
->read_status_mask
|= UART_FIFO_FRAMEERR_MASK
;
566 port
->read_status_mask
|= UART_FIFO_PARERR_MASK
;
568 if (new->c_iflag
& (BRKINT
))
569 port
->read_status_mask
|= UART_FIFO_BRKDET_MASK
;
571 port
->ignore_status_mask
= 0;
572 if (new->c_iflag
& IGNPAR
)
573 port
->ignore_status_mask
|= UART_FIFO_PARERR_MASK
;
574 if (new->c_iflag
& IGNBRK
)
575 port
->ignore_status_mask
|= UART_FIFO_BRKDET_MASK
;
576 if (!(new->c_cflag
& CREAD
))
577 port
->ignore_status_mask
|= UART_FIFO_VALID_MASK
;
579 uart_update_timeout(port
, new->c_cflag
, baud
);
580 bcm_uart_enable(port
);
581 spin_unlock_irqrestore(&port
->lock
, flags
);
585 * serial core request to claim uart iomem
587 static int bcm_uart_request_port(struct uart_port
*port
)
591 size
= RSET_UART_SIZE
;
592 if (!request_mem_region(port
->mapbase
, size
, "bcm63xx")) {
593 dev_err(port
->dev
, "Memory region busy\n");
597 port
->membase
= ioremap(port
->mapbase
, size
);
598 if (!port
->membase
) {
599 dev_err(port
->dev
, "Unable to map registers\n");
600 release_mem_region(port
->mapbase
, size
);
607 * serial core request to release uart iomem
609 static void bcm_uart_release_port(struct uart_port
*port
)
611 release_mem_region(port
->mapbase
, RSET_UART_SIZE
);
612 iounmap(port
->membase
);
616 * serial core request to do any port required autoconfiguration
618 static void bcm_uart_config_port(struct uart_port
*port
, int flags
)
620 if (flags
& UART_CONFIG_TYPE
) {
621 if (bcm_uart_request_port(port
))
623 port
->type
= PORT_BCM63XX
;
628 * serial core request to check that port information in serinfo are
631 static int bcm_uart_verify_port(struct uart_port
*port
,
632 struct serial_struct
*serinfo
)
634 if (port
->type
!= PORT_BCM63XX
)
636 if (port
->irq
!= serinfo
->irq
)
638 if (port
->iotype
!= serinfo
->io_type
)
640 if (port
->mapbase
!= (unsigned long)serinfo
->iomem_base
)
645 /* serial core callbacks */
646 static struct uart_ops bcm_uart_ops
= {
647 .tx_empty
= bcm_uart_tx_empty
,
648 .get_mctrl
= bcm_uart_get_mctrl
,
649 .set_mctrl
= bcm_uart_set_mctrl
,
650 .start_tx
= bcm_uart_start_tx
,
651 .stop_tx
= bcm_uart_stop_tx
,
652 .stop_rx
= bcm_uart_stop_rx
,
653 .enable_ms
= bcm_uart_enable_ms
,
654 .break_ctl
= bcm_uart_break_ctl
,
655 .startup
= bcm_uart_startup
,
656 .shutdown
= bcm_uart_shutdown
,
657 .set_termios
= bcm_uart_set_termios
,
658 .type
= bcm_uart_type
,
659 .release_port
= bcm_uart_release_port
,
660 .request_port
= bcm_uart_request_port
,
661 .config_port
= bcm_uart_config_port
,
662 .verify_port
= bcm_uart_verify_port
,
667 #ifdef CONFIG_SERIAL_BCM63XX_CONSOLE
668 static inline void wait_for_xmitr(struct uart_port
*port
)
672 /* Wait up to 10ms for the character(s) to be sent. */
677 val
= bcm_uart_readl(port
, UART_IR_REG
);
678 if (val
& UART_IR_STAT(UART_IR_TXEMPTY
))
683 /* Wait up to 1s for flow control if necessary */
684 if (port
->flags
& UPF_CONS_FLOW
) {
689 val
= bcm_uart_readl(port
, UART_EXTINP_REG
);
690 if (val
& UART_EXTINP_CTS_MASK
)
700 static void bcm_console_putchar(struct uart_port
*port
, int ch
)
702 wait_for_xmitr(port
);
703 bcm_uart_writel(port
, ch
, UART_FIFO_REG
);
707 * console core request to output given string
709 static void bcm_console_write(struct console
*co
, const char *s
,
712 struct uart_port
*port
;
716 port
= &ports
[co
->index
];
718 local_irq_save(flags
);
720 /* bcm_uart_interrupt() already took the lock */
722 } else if (oops_in_progress
) {
723 locked
= spin_trylock(&port
->lock
);
725 spin_lock(&port
->lock
);
729 /* call helper to deal with \r\n */
730 uart_console_write(port
, s
, count
, bcm_console_putchar
);
732 /* and wait for char to be transmitted */
733 wait_for_xmitr(port
);
736 spin_unlock(&port
->lock
);
737 local_irq_restore(flags
);
741 * console core request to setup given console, find matching uart
744 static int bcm_console_setup(struct console
*co
, char *options
)
746 struct uart_port
*port
;
752 if (co
->index
< 0 || co
->index
>= BCM63XX_NR_UARTS
)
754 port
= &ports
[co
->index
];
758 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
760 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
763 static struct uart_driver bcm_uart_driver
;
765 static struct console bcm63xx_console
= {
767 .write
= bcm_console_write
,
768 .device
= uart_console_device
,
769 .setup
= bcm_console_setup
,
770 .flags
= CON_PRINTBUFFER
,
772 .data
= &bcm_uart_driver
,
775 static int __init
bcm63xx_console_init(void)
777 register_console(&bcm63xx_console
);
781 console_initcall(bcm63xx_console_init
);
783 #define BCM63XX_CONSOLE (&bcm63xx_console)
785 #define BCM63XX_CONSOLE NULL
786 #endif /* CONFIG_SERIAL_BCM63XX_CONSOLE */
788 static struct uart_driver bcm_uart_driver
= {
789 .owner
= THIS_MODULE
,
790 .driver_name
= "bcm63xx_uart",
794 .nr
= BCM63XX_NR_UARTS
,
795 .cons
= BCM63XX_CONSOLE
,
799 * platform driver probe/remove callback
801 static int bcm_uart_probe(struct platform_device
*pdev
)
803 struct resource
*res_mem
, *res_irq
;
804 struct uart_port
*port
;
808 if (pdev
->id
< 0 || pdev
->id
>= BCM63XX_NR_UARTS
)
811 if (ports
[pdev
->id
].membase
)
814 res_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
818 res_irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
822 clk
= clk_get(&pdev
->dev
, "periph");
826 port
= &ports
[pdev
->id
];
827 memset(port
, 0, sizeof(*port
));
828 port
->iotype
= UPIO_MEM
;
829 port
->mapbase
= res_mem
->start
;
830 port
->irq
= res_irq
->start
;
831 port
->ops
= &bcm_uart_ops
;
832 port
->flags
= UPF_BOOT_AUTOCONF
;
833 port
->dev
= &pdev
->dev
;
835 port
->uartclk
= clk_get_rate(clk
) / 2;
836 port
->line
= pdev
->id
;
839 ret
= uart_add_one_port(&bcm_uart_driver
, port
);
841 ports
[pdev
->id
].membase
= 0;
844 platform_set_drvdata(pdev
, port
);
848 static int bcm_uart_remove(struct platform_device
*pdev
)
850 struct uart_port
*port
;
852 port
= platform_get_drvdata(pdev
);
853 uart_remove_one_port(&bcm_uart_driver
, port
);
854 /* mark port as free */
855 ports
[pdev
->id
].membase
= 0;
860 * platform driver stuff
862 static struct platform_driver bcm_uart_platform_driver
= {
863 .probe
= bcm_uart_probe
,
864 .remove
= bcm_uart_remove
,
866 .owner
= THIS_MODULE
,
867 .name
= "bcm63xx_uart",
871 static int __init
bcm_uart_init(void)
875 ret
= uart_register_driver(&bcm_uart_driver
);
879 ret
= platform_driver_register(&bcm_uart_platform_driver
);
881 uart_unregister_driver(&bcm_uart_driver
);
886 static void __exit
bcm_uart_exit(void)
888 platform_driver_unregister(&bcm_uart_platform_driver
);
889 uart_unregister_driver(&bcm_uart_driver
);
892 module_init(bcm_uart_init
);
893 module_exit(bcm_uart_exit
);
895 MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
896 MODULE_DESCRIPTION("Broadcom 63<xx integrated uart driver");
897 MODULE_LICENSE("GPL");