1 From 6c489656b09998ed6a6f857e01ccf630e29358dd Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Fri, 18 Jul 2008 19:35:55 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add serial driver for bcm63xx integrated UART.
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
8 arch/mips/bcm63xx/Makefile | 1 +
9 arch/mips/bcm63xx/dev-uart.c | 41 +
10 drivers/serial/Kconfig | 19 +
11 drivers/serial/Makefile | 1 +
12 drivers/serial/bcm63xx_uart.c | 890 ++++++++++++++++++++++
13 include/asm-mips/mach-bcm63xx/bcm63xx_dev_uart.h | 6 +
14 include/linux/serial_core.h | 2 +
15 7 files changed, 960 insertions(+), 0 deletions(-)
16 create mode 100644 arch/mips/bcm63xx/dev-uart.c
17 create mode 100644 drivers/serial/bcm63xx_uart.c
18 create mode 100644 include/asm-mips/mach-bcm63xx/bcm63xx_dev_uart.h
20 diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
21 index 4fc0a1c..8f3299e 100644
22 --- a/arch/mips/bcm63xx/Makefile
23 +++ b/arch/mips/bcm63xx/Makefile
25 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
27 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
28 diff --git a/arch/mips/bcm63xx/dev-uart.c b/arch/mips/bcm63xx/dev-uart.c
30 index 0000000..5f3d89c
32 +++ b/arch/mips/bcm63xx/dev-uart.c
35 + * This file is subject to the terms and conditions of the GNU General Public
36 + * License. See the file "COPYING" in the main directory of this archive
39 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
42 +#include <linux/init.h>
43 +#include <linux/kernel.h>
44 +#include <linux/platform_device.h>
45 +#include <bcm63xx_cpu.h>
46 +#include <bcm63xx_dev_uart.h>
48 +static struct resource uart_resources[] = {
50 + .start = -1, /* filled at runtime */
51 + .end = -1, /* filled at runtime */
52 + .flags = IORESOURCE_MEM,
55 + .start = -1, /* filled at runtime */
56 + .flags = IORESOURCE_IRQ,
60 +static struct platform_device bcm63xx_uart_device = {
61 + .name = "bcm63xx_uart",
63 + .num_resources = ARRAY_SIZE(uart_resources),
64 + .resource = uart_resources,
67 +int __init bcm63xx_uart_register(void)
69 + uart_resources[0].start = bcm63xx_regset_address(RSET_UART0);
70 + uart_resources[0].end = uart_resources[0].start;
71 + uart_resources[0].end += RSET_UART_SIZE - 1;
72 + uart_resources[1].start = bcm63xx_get_irq_number(IRQ_UART0);
73 + return platform_device_register(&bcm63xx_uart_device);
75 diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
76 index 77cb342..52b31a4 100644
77 --- a/drivers/serial/Kconfig
78 +++ b/drivers/serial/Kconfig
79 @@ -1421,4 +1421,23 @@ config SPORT_BAUD_RATE
80 default 19200 if (SERIAL_SPORT_BAUD_RATE_19200)
81 default 9600 if (SERIAL_SPORT_BAUD_RATE_9600)
83 +config SERIAL_BCM63XX
84 + tristate "bcm63xx serial port support"
88 + If you have a bcm63xx CPU, you can enable its onboard
89 + serial port by enabling this options.
91 + To compile this driver as a module, choose M here: the
92 + module will be called bcm963xx_uart.
94 +config SERIAL_BCM63XX_CONSOLE
95 + bool "Console on bcm63xx serial port"
96 + depends on SERIAL_BCM63XX
97 + select SERIAL_CORE_CONSOLE
99 + If you have enabled the serial port on the bcm63xx CPU
100 + you can make it the console by answering Y to this option.
103 diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
104 index 7e7383e..84f6cfc 100644
105 --- a/drivers/serial/Makefile
106 +++ b/drivers/serial/Makefile
107 @@ -24,6 +24,7 @@ obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
108 obj-$(CONFIG_SERIAL_PXA) += pxa.o
109 obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
110 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
111 +obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o
112 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
113 obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
114 obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o
115 diff --git a/drivers/serial/bcm63xx_uart.c b/drivers/serial/bcm63xx_uart.c
117 index 0000000..606f4d6
119 +++ b/drivers/serial/bcm63xx_uart.c
122 + * This file is subject to the terms and conditions of the GNU General Public
123 + * License. See the file "COPYING" in the main directory of this archive
124 + * for more details.
126 + * Derived from many drivers using generic_serial interface.
128 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
130 + * Serial driver for BCM63xx integrated UART.
132 + * Hardware flow control was _not_ tested since I only have RX/TX on
136 +#if defined(CONFIG_SERIAL_BCM63XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
137 +#define SUPPORT_SYSRQ
140 +#include <linux/kernel.h>
141 +#include <linux/platform_device.h>
142 +#include <linux/init.h>
143 +#include <linux/delay.h>
144 +#include <linux/module.h>
145 +#include <linux/console.h>
146 +#include <linux/clk.h>
147 +#include <linux/tty.h>
148 +#include <linux/tty_flip.h>
149 +#include <linux/sysrq.h>
150 +#include <linux/serial.h>
151 +#include <linux/serial_core.h>
153 +#include <bcm63xx_clk.h>
154 +#include <bcm63xx_irq.h>
155 +#include <bcm63xx_regs.h>
156 +#include <bcm63xx_io.h>
158 +#define BCM63XX_NR_UARTS 1
160 +static struct uart_port ports[BCM63XX_NR_UARTS];
163 + * rx interrupt mask / stat
167 + * - rx fifo above threshold
168 + * - rx fifo not empty for too long
170 +#define UART_RX_INT_MASK (UART_IR_MASK(UART_IR_RXOVER) | \
171 + UART_IR_MASK(UART_IR_RXTHRESH) | \
172 + UART_IR_MASK(UART_IR_RXTIMEOUT))
174 +#define UART_RX_INT_STAT (UART_IR_STAT(UART_IR_RXOVER) | \
175 + UART_IR_STAT(UART_IR_RXTHRESH) | \
176 + UART_IR_STAT(UART_IR_RXTIMEOUT))
179 + * tx interrupt mask / stat
183 + * - tx fifo below threshold
185 +#define UART_TX_INT_MASK (UART_IR_MASK(UART_IR_TXEMPTY) | \
186 + UART_IR_MASK(UART_IR_TXTRESH))
188 +#define UART_TX_INT_STAT (UART_IR_STAT(UART_IR_TXEMPTY) | \
189 + UART_IR_STAT(UART_IR_TXTRESH))
192 + * external input interrupt
194 + * mask: any edge on CTS, DCD
196 +#define UART_EXTINP_INT_MASK (UART_EXTINP_IRMASK(UART_EXTINP_IR_CTS) | \
197 + UART_EXTINP_IRMASK(UART_EXTINP_IR_DCD))
200 + * handy uart register accessor
202 +static inline unsigned int bcm_uart_readl(struct uart_port *port,
203 + unsigned int offset)
205 + return bcm_readl(port->membase + offset);
208 +static inline void bcm_uart_writel(struct uart_port *port,
209 + unsigned int value, unsigned int offset)
211 + bcm_writel(value, port->membase + offset);
215 + * serial core request to check if uart tx fifo is empty
217 +static unsigned int bcm_uart_tx_empty(struct uart_port *port)
221 + val = bcm_uart_readl(port, UART_IR_REG);
222 + return (val & UART_IR_STAT(UART_IR_TXEMPTY)) ? 1 : 0;
226 + * serial core request to set RTS and DTR pin state and loopback mode
228 +static void bcm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
232 + val = bcm_uart_readl(port, UART_MCTL_REG);
233 + val &= ~(UART_MCTL_DTR_MASK | UART_MCTL_RTS_MASK);
234 + /* invert of written value is reflected on the pin */
235 + if (!(mctrl & TIOCM_DTR))
236 + val |= UART_MCTL_DTR_MASK;
237 + if (!(mctrl & TIOCM_RTS))
238 + val |= UART_MCTL_RTS_MASK;
239 + bcm_uart_writel(port, val, UART_MCTL_REG);
241 + val = bcm_uart_readl(port, UART_CTL_REG);
242 + if (mctrl & TIOCM_LOOP)
243 + val |= UART_CTL_LOOPBACK_MASK;
245 + val &= ~UART_CTL_LOOPBACK_MASK;
246 + bcm_uart_writel(port, val, UART_CTL_REG);
250 + * serial core request to return RI, CTS, DCD and DSR pin state
252 +static unsigned int bcm_uart_get_mctrl(struct uart_port *port)
254 + unsigned int val, mctrl;
257 + val = bcm_uart_readl(port, UART_EXTINP_REG);
258 + if (val & UART_EXTINP_RI_MASK)
260 + if (val & UART_EXTINP_CTS_MASK)
261 + mctrl |= TIOCM_CTS;
262 + if (val & UART_EXTINP_DCD_MASK)
264 + if (val & UART_EXTINP_DSR_MASK)
265 + mctrl |= TIOCM_DSR;
270 + * serial core request to disable tx ASAP (used for flow control)
272 +static void bcm_uart_stop_tx(struct uart_port *port)
276 + val = bcm_uart_readl(port, UART_CTL_REG);
277 + val &= ~(UART_CTL_TXEN_MASK);
278 + bcm_uart_writel(port, val, UART_CTL_REG);
280 + val = bcm_uart_readl(port, UART_IR_REG);
281 + val &= ~UART_TX_INT_MASK;
282 + bcm_uart_writel(port, val, UART_IR_REG);
286 + * serial core request to (re)enable tx
288 +static void bcm_uart_start_tx(struct uart_port *port)
292 + val = bcm_uart_readl(port, UART_IR_REG);
293 + val |= UART_TX_INT_MASK;
294 + bcm_uart_writel(port, val, UART_IR_REG);
296 + val = bcm_uart_readl(port, UART_CTL_REG);
297 + val |= UART_CTL_TXEN_MASK;
298 + bcm_uart_writel(port, val, UART_CTL_REG);
302 + * serial core request to stop rx, called before port shutdown
304 +static void bcm_uart_stop_rx(struct uart_port *port)
308 + val = bcm_uart_readl(port, UART_IR_REG);
309 + val &= ~UART_RX_INT_MASK;
310 + bcm_uart_writel(port, val, UART_IR_REG);
314 + * serial core request to enable modem status interrupt reporting
316 +static void bcm_uart_enable_ms(struct uart_port *port)
320 + val = bcm_uart_readl(port, UART_IR_REG);
321 + val |= UART_IR_MASK(UART_IR_EXTIP);
322 + bcm_uart_writel(port, val, UART_IR_REG);
326 + * serial core request to start/stop emitting break char
328 +static void bcm_uart_break_ctl(struct uart_port *port, int ctl)
330 + unsigned long flags;
333 + spin_lock_irqsave(&port->lock, flags);
335 + val = bcm_uart_readl(port, UART_CTL_REG);
337 + val |= UART_CTL_XMITBRK_MASK;
339 + val &= ~UART_CTL_XMITBRK_MASK;
340 + bcm_uart_writel(port, val, UART_CTL_REG);
342 + spin_unlock_irqrestore(&port->lock, flags);
346 + * return port type in string format
348 +static const char *bcm_uart_type(struct uart_port *port)
350 + return (port->type == PORT_BCM63XX) ? "bcm63xx_uart" : NULL;
354 + * read all chars in rx fifo and send them to core
356 +static void bcm_uart_do_rx(struct uart_port *port)
358 + struct tty_struct *tty;
359 + unsigned int max_count;
361 + /* limit number of char read in interrupt, should not be
362 + * higher than fifo size anyway since we're much faster than
365 + tty = port->info->port.tty;
367 + unsigned int iestat, c, cstat;
370 + /* get overrun/fifo empty information from ier
372 + iestat = bcm_uart_readl(port, UART_IR_REG);
373 + if (!(iestat & UART_IR_STAT(UART_IR_RXNOTEMPTY)))
376 + cstat = c = bcm_uart_readl(port, UART_FIFO_REG);
381 + if (unlikely((cstat & UART_FIFO_ANYERR_MASK))) {
382 + /* do stats first */
383 + if (cstat & UART_FIFO_BRKDET_MASK) {
384 + port->icount.brk++;
385 + if (uart_handle_break(port))
389 + if (cstat & UART_FIFO_PARERR_MASK)
390 + port->icount.parity++;
391 + if (cstat & UART_FIFO_FRAMEERR_MASK)
392 + port->icount.frame++;
394 + /* update flag wrt read_status_mask */
395 + cstat &= port->read_status_mask;
396 + if (cstat & UART_FIFO_BRKDET_MASK)
398 + if (cstat & UART_FIFO_FRAMEERR_MASK)
400 + if (cstat & UART_FIFO_PARERR_MASK)
404 + if (uart_handle_sysrq_char(port, c))
407 + if (unlikely(iestat & UART_IR_STAT(UART_IR_RXOVER))) {
408 + port->icount.overrun++;
409 + tty_insert_flip_char(tty, 0, TTY_OVERRUN);
412 + if ((cstat & port->ignore_status_mask) == 0)
413 + tty_insert_flip_char(tty, c, flag);
415 + } while (--max_count);
417 + tty_flip_buffer_push(tty);
421 + * fill tx fifo with chars to send, stop when fifo is about to be full
422 + * or when all chars have been sent.
424 +static void bcm_uart_do_tx(struct uart_port *port)
426 + struct circ_buf *xmit;
427 + unsigned int val, max_count;
429 + if (port->x_char) {
430 + bcm_uart_writel(port, port->x_char, UART_FIFO_REG);
436 + if (uart_tx_stopped(port)) {
437 + bcm_uart_stop_tx(port);
441 + xmit = &port->info->xmit;
442 + if (uart_circ_empty(xmit))
445 + val = bcm_uart_readl(port, UART_MCTL_REG);
446 + val = (val & UART_MCTL_TXFIFOFILL_MASK) >> UART_MCTL_TXFIFOFILL_SHIFT;
447 + max_count = port->fifosize - val;
449 + while (max_count--) {
452 + c = xmit->buf[xmit->tail];
453 + bcm_uart_writel(port, c, UART_FIFO_REG);
454 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
456 + if (uart_circ_empty(xmit))
460 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
461 + uart_write_wakeup(port);
463 + if (uart_circ_empty(xmit))
468 + /* nothing to send, disable transmit interrupt */
469 + val = bcm_uart_readl(port, UART_IR_REG);
470 + val &= ~UART_TX_INT_MASK;
471 + bcm_uart_writel(port, val, UART_IR_REG);
476 + * process uart interrupt
478 +static irqreturn_t bcm_uart_interrupt(int irq, void *dev_id)
480 + struct uart_port *port;
481 + unsigned int irqstat;
484 + spin_lock(&port->lock);
486 + irqstat = bcm_uart_readl(port, UART_IR_REG);
487 + if (irqstat & UART_RX_INT_STAT)
488 + bcm_uart_do_rx(port);
490 + if (irqstat & UART_TX_INT_STAT)
491 + bcm_uart_do_tx(port);
493 + if (irqstat & UART_IR_MASK(UART_IR_EXTIP)) {
494 + unsigned int estat;
496 + estat = bcm_uart_readl(port, UART_EXTINP_REG);
497 + if (estat & UART_EXTINP_IRSTAT(UART_EXTINP_IR_CTS))
498 + uart_handle_cts_change(port,
499 + estat & UART_EXTINP_CTS_MASK);
500 + if (estat & UART_EXTINP_IRSTAT(UART_EXTINP_IR_DCD))
501 + uart_handle_dcd_change(port,
502 + estat & UART_EXTINP_DCD_MASK);
505 + spin_unlock(&port->lock);
506 + return IRQ_HANDLED;
510 + * enable rx & tx operation on uart
512 +static void bcm_uart_enable(struct uart_port *port)
516 + val = bcm_uart_readl(port, UART_CTL_REG);
517 + val |= (UART_CTL_BRGEN_MASK | UART_CTL_TXEN_MASK | UART_CTL_RXEN_MASK);
518 + bcm_uart_writel(port, val, UART_CTL_REG);
522 + * disable rx & tx operation on uart
524 +static void bcm_uart_disable(struct uart_port *port)
528 + val = bcm_uart_readl(port, UART_CTL_REG);
529 + val &= ~(UART_CTL_BRGEN_MASK | UART_CTL_TXEN_MASK |
530 + UART_CTL_RXEN_MASK);
531 + bcm_uart_writel(port, val, UART_CTL_REG);
535 + * clear all unread data in rx fifo and unsent data in tx fifo
537 +static void bcm_uart_flush(struct uart_port *port)
541 + /* empty rx and tx fifo */
542 + val = bcm_uart_readl(port, UART_CTL_REG);
543 + val |= UART_CTL_RSTRXFIFO_MASK | UART_CTL_RSTTXFIFO_MASK;
544 + bcm_uart_writel(port, val, UART_CTL_REG);
546 + /* read any pending char to make sure all irq status are
548 + (void)bcm_uart_readl(port, UART_FIFO_REG);
552 + * serial core request to initialize uart and start rx operation
554 +static int bcm_uart_startup(struct uart_port *port)
559 + /* mask all irq and flush port */
560 + bcm_uart_disable(port);
561 + bcm_uart_writel(port, 0, UART_IR_REG);
562 + bcm_uart_flush(port);
564 + /* clear any pending external input interrupt */
565 + (void)bcm_uart_readl(port, UART_EXTINP_REG);
567 + /* set rx/tx fifo thresh to fifo half size */
568 + val = bcm_uart_readl(port, UART_MCTL_REG);
569 + val &= ~(UART_MCTL_RXFIFOTHRESH_MASK | UART_MCTL_TXFIFOTHRESH_MASK);
570 + val |= (port->fifosize / 2) << UART_MCTL_RXFIFOTHRESH_SHIFT;
571 + val |= (port->fifosize / 2) << UART_MCTL_TXFIFOTHRESH_SHIFT;
572 + bcm_uart_writel(port, val, UART_MCTL_REG);
574 + /* set rx fifo timeout to 1 char time */
575 + val = bcm_uart_readl(port, UART_CTL_REG);
576 + val &= ~UART_CTL_RXTMOUTCNT_MASK;
577 + val |= 1 << UART_CTL_RXTMOUTCNT_SHIFT;
578 + bcm_uart_writel(port, val, UART_CTL_REG);
580 + /* report any edge on dcd and cts */
581 + val = UART_EXTINP_INT_MASK;
582 + val |= UART_EXTINP_DCD_NOSENSE_MASK;
583 + val |= UART_EXTINP_CTS_NOSENSE_MASK;
584 + bcm_uart_writel(port, val, UART_EXTINP_REG);
586 + /* register irq and enable rx interrupts */
587 + ret = request_irq(port->irq, bcm_uart_interrupt, 0,
588 + bcm_uart_type(port), port);
591 + bcm_uart_writel(port, UART_RX_INT_MASK, UART_IR_REG);
592 + bcm_uart_enable(port);
597 + * serial core request to flush & disable uart
599 +static void bcm_uart_shutdown(struct uart_port *port)
601 + unsigned long flags;
603 + spin_lock_irqsave(&port->lock, flags);
604 + bcm_uart_writel(port, 0, UART_IR_REG);
605 + spin_unlock_irqrestore(&port->lock, flags);
607 + bcm_uart_disable(port);
608 + bcm_uart_flush(port);
609 + free_irq(port->irq, port);
613 + * serial core request to change current uart setting
615 +static void bcm_uart_set_termios(struct uart_port *port,
616 + struct ktermios *new,
617 + struct ktermios *old)
619 + unsigned int ctl, baud, quot, ier;
620 + unsigned long flags;
622 + spin_lock_irqsave(&port->lock, flags);
624 + /* disable uart while changing speed */
625 + bcm_uart_disable(port);
626 + bcm_uart_flush(port);
628 + /* update Control register */
629 + ctl = bcm_uart_readl(port, UART_CTL_REG);
630 + ctl &= ~UART_CTL_BITSPERSYM_MASK;
632 + switch (new->c_cflag & CSIZE) {
634 + ctl |= (0 << UART_CTL_BITSPERSYM_SHIFT);
637 + ctl |= (1 << UART_CTL_BITSPERSYM_SHIFT);
640 + ctl |= (2 << UART_CTL_BITSPERSYM_SHIFT);
643 + ctl |= (3 << UART_CTL_BITSPERSYM_SHIFT);
647 + ctl &= ~UART_CTL_STOPBITS_MASK;
648 + if (new->c_cflag & CSTOPB)
649 + ctl |= UART_CTL_STOPBITS_2;
651 + ctl |= UART_CTL_STOPBITS_1;
653 + ctl &= ~(UART_CTL_RXPAREN_MASK | UART_CTL_TXPAREN_MASK);
654 + if (new->c_cflag & PARENB)
655 + ctl |= (UART_CTL_RXPAREN_MASK | UART_CTL_TXPAREN_MASK);
656 + ctl &= ~(UART_CTL_RXPAREVEN_MASK | UART_CTL_TXPAREVEN_MASK);
657 + if (new->c_cflag & PARODD)
658 + ctl |= (UART_CTL_RXPAREVEN_MASK | UART_CTL_TXPAREVEN_MASK);
659 + bcm_uart_writel(port, ctl, UART_CTL_REG);
661 + /* update Baudword register */
662 + baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
663 + quot = uart_get_divisor(port, baud) - 1;
664 + bcm_uart_writel(port, quot, UART_BAUD_REG);
666 + /* update Interrupt register */
667 + ier = bcm_uart_readl(port, UART_IR_REG);
669 + ier &= ~UART_IR_MASK(UART_IR_EXTIP);
670 + if (UART_ENABLE_MS(port, new->c_cflag))
671 + ier |= UART_IR_MASK(UART_IR_EXTIP);
673 + bcm_uart_writel(port, ier, UART_IR_REG);
675 + /* update read/ignore mask */
676 + port->read_status_mask = UART_FIFO_VALID_MASK;
677 + if (new->c_iflag & INPCK) {
678 + port->read_status_mask |= UART_FIFO_FRAMEERR_MASK;
679 + port->read_status_mask |= UART_FIFO_PARERR_MASK;
681 + if (new->c_iflag & (BRKINT))
682 + port->read_status_mask |= UART_FIFO_BRKDET_MASK;
684 + port->ignore_status_mask = 0;
685 + if (new->c_iflag & IGNPAR)
686 + port->ignore_status_mask |= UART_FIFO_PARERR_MASK;
687 + if (new->c_iflag & IGNBRK)
688 + port->ignore_status_mask |= UART_FIFO_BRKDET_MASK;
689 + if (!(new->c_cflag & CREAD))
690 + port->ignore_status_mask |= UART_FIFO_VALID_MASK;
692 + uart_update_timeout(port, new->c_cflag, baud);
693 + bcm_uart_enable(port);
694 + spin_unlock_irqrestore(&port->lock, flags);
698 + * serial core request to claim uart iomem
700 +static int bcm_uart_request_port(struct uart_port *port)
704 + size = RSET_UART_SIZE;
705 + if (!request_mem_region(port->mapbase, size, "bcm63xx")) {
706 + dev_err(port->dev, "Memory region busy\n");
710 + port->membase = ioremap(port->mapbase, size);
711 + if (!port->membase) {
712 + dev_err(port->dev, "Unable to map registers\n");
713 + release_mem_region(port->mapbase, size);
720 + * serial core request to release uart iomem
722 +static void bcm_uart_release_port(struct uart_port *port)
724 + release_mem_region(port->mapbase, RSET_UART_SIZE);
725 + iounmap(port->membase);
729 + * serial core request to do any port required autoconfiguration
731 +static void bcm_uart_config_port(struct uart_port *port, int flags)
733 + if (flags & UART_CONFIG_TYPE) {
734 + if (bcm_uart_request_port(port))
736 + port->type = PORT_BCM63XX;
741 + * serial core request to check that port information in serinfo are
744 +static int bcm_uart_verify_port(struct uart_port *port,
745 + struct serial_struct *serinfo)
747 + if (port->type != PORT_BCM63XX)
749 + if (port->irq != serinfo->irq)
751 + if (port->iotype != serinfo->io_type)
753 + if (port->mapbase != (unsigned long)serinfo->iomem_base)
758 +/* serial core callbacks */
759 +static struct uart_ops bcm_uart_ops = {
760 + .tx_empty = bcm_uart_tx_empty,
761 + .get_mctrl = bcm_uart_get_mctrl,
762 + .set_mctrl = bcm_uart_set_mctrl,
763 + .start_tx = bcm_uart_start_tx,
764 + .stop_tx = bcm_uart_stop_tx,
765 + .stop_rx = bcm_uart_stop_rx,
766 + .enable_ms = bcm_uart_enable_ms,
767 + .break_ctl = bcm_uart_break_ctl,
768 + .startup = bcm_uart_startup,
769 + .shutdown = bcm_uart_shutdown,
770 + .set_termios = bcm_uart_set_termios,
771 + .type = bcm_uart_type,
772 + .release_port = bcm_uart_release_port,
773 + .request_port = bcm_uart_request_port,
774 + .config_port = bcm_uart_config_port,
775 + .verify_port = bcm_uart_verify_port,
780 +#ifdef CONFIG_SERIAL_BCM63XX_CONSOLE
781 +static inline void wait_for_xmitr(struct uart_port *port)
783 + unsigned int tmout;
785 + /* Wait up to 10ms for the character(s) to be sent. */
790 + val = bcm_uart_readl(port, UART_IR_REG);
791 + if (val & UART_IR_STAT(UART_IR_TXEMPTY))
796 + /* Wait up to 1s for flow control if necessary */
797 + if (port->flags & UPF_CONS_FLOW) {
802 + val = bcm_uart_readl(port, UART_EXTINP_REG);
803 + if (val & UART_EXTINP_CTS_MASK)
811 + * output given char
813 +static void bcm_console_putchar(struct uart_port *port, int ch)
815 + wait_for_xmitr(port);
816 + bcm_uart_writel(port, ch, UART_FIFO_REG);
820 + * console core request to output given string
822 +static void bcm_console_write(struct console *co, const char *s,
823 + unsigned int count)
825 + struct uart_port *port;
826 + unsigned long flags;
829 + port = &ports[co->index];
831 + local_irq_save(flags);
833 + /* bcm_uart_interrupt() already took the lock */
835 + } else if (oops_in_progress) {
836 + locked = spin_trylock(&port->lock);
838 + spin_lock(&port->lock);
842 + /* call helper to deal with \r\n */
843 + uart_console_write(port, s, count, bcm_console_putchar);
845 + /* and wait for char to be transmitted */
846 + wait_for_xmitr(port);
849 + spin_unlock(&port->lock);
850 + local_irq_restore(flags);
854 + * console core request to setup given console, find matching uart
855 + * port and setup it.
857 +static int bcm_console_setup(struct console *co, char *options)
859 + struct uart_port *port;
865 + if (co->index < 0 || co->index >= BCM63XX_NR_UARTS)
867 + port = &ports[co->index];
868 + if (!port->membase)
871 + uart_parse_options(options, &baud, &parity, &bits, &flow);
873 + return uart_set_options(port, co, baud, parity, bits, flow);
876 +static struct uart_driver bcm_uart_driver;
878 +static struct console bcm63xx_console = {
880 + .write = bcm_console_write,
881 + .device = uart_console_device,
882 + .setup = bcm_console_setup,
883 + .flags = CON_PRINTBUFFER,
885 + .data = &bcm_uart_driver,
888 +static int __init bcm63xx_console_init(void)
890 + register_console(&bcm63xx_console);
894 +console_initcall(bcm63xx_console_init);
896 +#define BCM63XX_CONSOLE &bcm63xx_console
898 +#define BCM63XX_CONSOLE NULL
899 +#endif /* CONFIG_SERIAL_BCM63XX_CONSOLE */
901 +static struct uart_driver bcm_uart_driver = {
902 + .owner = THIS_MODULE,
903 + .driver_name = "bcm63xx_uart",
904 + .dev_name = "ttyS",
905 + .major = TTY_MAJOR,
908 + .cons = BCM63XX_CONSOLE,
912 + * platform driver probe/remove callback
914 +static int __devinit bcm_uart_probe(struct platform_device *pdev)
916 + struct resource *res_mem, *res_irq;
917 + struct uart_port *port;
921 + if (pdev->id < 0 || pdev->id >= BCM63XX_NR_UARTS)
924 + if (ports[pdev->id].membase)
927 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
931 + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
935 + clk = clk_get(&pdev->dev, "periph");
939 + port = &ports[pdev->id];
940 + memset(port, 0, sizeof(*port));
941 + port->iotype = UPIO_MEM;
942 + port->mapbase = res_mem->start;
943 + port->irq = res_irq->start;
944 + port->ops = &bcm_uart_ops;
945 + port->flags = UPF_BOOT_AUTOCONF;
946 + port->dev = &pdev->dev;
947 + port->fifosize = 16;
948 + port->uartclk = clk_get_rate(clk) / 2;
951 + ret = uart_add_one_port(&bcm_uart_driver, port);
956 + platform_set_drvdata(pdev, port);
960 +static int __devexit bcm_uart_remove(struct platform_device *pdev)
962 + struct uart_port *port;
964 + port = platform_get_drvdata(pdev);
965 + uart_remove_one_port(&bcm_uart_driver, port);
966 + platform_set_drvdata(pdev, NULL);
967 + /* mark port as free */
968 + ports[pdev->id].membase = 0;
973 + * platform driver stuff
975 +static struct platform_driver bcm_uart_platform_driver = {
976 + .probe = bcm_uart_probe,
977 + .remove = __devexit_p(bcm_uart_remove),
979 + .owner = THIS_MODULE,
980 + .name = "bcm63xx_uart",
984 +static int __init bcm_uart_init(void)
988 + ret = uart_register_driver(&bcm_uart_driver);
992 + ret = platform_driver_register(&bcm_uart_platform_driver);
994 + uart_unregister_driver(&bcm_uart_driver);
999 +static void __exit bcm_uart_exit(void)
1001 + platform_driver_unregister(&bcm_uart_platform_driver);
1002 + uart_unregister_driver(&bcm_uart_driver);
1005 +module_init(bcm_uart_init);
1006 +module_exit(bcm_uart_exit);
1008 +MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
1009 +MODULE_DESCRIPTION("Broadcom 63<xx integrated uart driver");
1010 +MODULE_LICENSE("GPL");
1011 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_dev_uart.h b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_uart.h
1012 new file mode 100644
1013 index 0000000..bf348f5
1015 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_uart.h
1017 +#ifndef BCM63XX_DEV_UART_H_
1018 +#define BCM63XX_DEV_UART_H_
1020 +int bcm63xx_uart_register(void);
1022 +#endif /* BCM63XX_DEV_UART_H_ */
1023 diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
1024 index 3b2f6c0..f49ddff 100644
1025 --- a/include/linux/serial_core.h
1026 +++ b/include/linux/serial_core.h
1029 #define PORT_SC26XX 82
1031 +#define PORT_BCM63XX 83
1035 #include <linux/compiler.h>