Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Fri, 18 Sep 2009
 05:06:12 -0600
Received: from mail1.lsil.com (mail1.lsil.com [147.145.40.21])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id n8IB693R023705	for
 <andy.sharp@lsi.com>; Fri, 18 Sep 2009 04:06:11 -0700
Received: from psmtp.com (na3sys009amx160.postini.com [74.125.149.86])	by
 mail1.lsil.com (8.12.11/8.12.11) with SMTP id n8IB5sQM008599	for
 <andy.sharp@lsi.com>; Fri, 18 Sep 2009 04:06:07 -0700 (PDT)
Received: from source ([78.24.191.182]) by na3sys009amx160.postini.com
 ([74.125.148.14]) with SMTP;	Fri, 18 Sep 2009 04:06:07 PDT
Received: from localhost.localdomain ([127.0.0.1]:38982 "EHLO
	eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S1492759AbZIRLFf (ORCPT <rfc822;andy.sharp@lsi.com>);	Fri, 18 Sep
 2009 13:05:35 +0200
Received: with ECARTIS (v1.0.0; list linux-mips); Fri, 18 Sep 2009 13:05:17
 +0200 (CEST)
Received: from smtp6-g21.free.fr ([212.27.42.6]:44595 "EHLO smtp6-g21.free.fr"
	rhost-flags-OK-OK-OK-OK) by ftp.linux-mips.org with ESMTP	id S1492728AbZIRLFL
 (ORCPT <rfc822;linux-mips@linux-mips.org>);	Fri, 18 Sep 2009 13:05:11 +0200
Received: from smtp6-g21.free.fr (localhost [127.0.0.1])	by smtp6-g21.free.fr
 (Postfix) with ESMTP id 23325E08104;	Fri, 18 Sep 2009 13:05:01 +0200 (CEST)
Received: from [213.228.1.107] (sakura.staff.proxad.net [213.228.1.107])	by
 smtp6-g21.free.fr (Postfix) with ESMTP id 35950E08048;	Fri, 18 Sep 2009
 13:04:59 +0200 (CEST)
From: Maxime Bizon <mbizon@freebox.fr>
To: Greg Kroah-Hartman <gregkh@suse.de>
CC: "linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	"linux-mips@linux-mips.org" <linux-mips@linux-mips.org>, Ralf Baechle
	<ralf@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Fri, 18 Sep 2009 05:04:58 -0600
Subject: [PATCH] MIPS: BCM63xx: Add serial driver for bcm63xx integrated
 UART.
Thread-Topic: [PATCH] MIPS: BCM63xx: Add serial driver for bcm63xx
 integrated UART.
Thread-Index: Aco4UAkXpNuUnvipTUOqLlKEIRmsEA==
Message-ID: <1253271898.1627.272.camel@sakura.staff.proxad.net>
Reply-To: "mbizon@freebox.fr" <mbizon@freebox.fr>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-neptune: 1/1/1.00/79
x-pstn-levels: (S:10.66369/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <mbizon@freebox.fr> [db-null] 
x-archive-position: 24046
x-ecartis-version: Ecartis v1.0.0
x-original-sender: mbizon@freebox.fr
x-list: linux-mips
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


Hi Greg,

This is a serial driver for the bcm63xx mips SOCs, it was already posted
twice:

one year ago: http://marc.info/?l=3Dlinux-serial&m=3D122438266322439&w=3D2
three months ago: http://lkml.org/lkml/2009/7/1/370

but got no review or ack.


Linus merged the SOC support patch from Ralf tree yesterday, but without
serial support.

Could you please have a look at it ? Is it ok if it goes upstream
through Ralf tree ?

Thanks !



Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
---

diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
index aaa585c..cff75de 100644
--- a/arch/mips/bcm63xx/Makefile
+++ b/arch/mips/bcm63xx/Makefile
@@ -1,5 +1,5 @@
 obj-y          +=3D clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
-                  dev-dsp.o dev-enet.o
+                  dev-dsp.o dev-enet.o dev-uart.o
 obj-$(CONFIG_EARLY_PRINTK)     +=3D early_printk.o

 obj-y          +=3D boards/
diff --git a/arch/mips/bcm63xx/boards/board_bcm963xx.c b/arch/mips/bcm63xx/=
boards/board_bcm963xx.c
index fd77f54..d3fdf27 100644
--- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
+++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
@@ -24,6 +24,7 @@
 #include <bcm63xx_dev_pci.h>
 #include <bcm63xx_dev_enet.h>
 #include <bcm63xx_dev_dsp.h>
+#include <bcm63xx_dev_uart.h>
 #include <board_bcm963xx.h>

 #define PFX    "board_bcm963xx: "
@@ -793,6 +794,8 @@ int __init board_register_devices(void)
 {
        u32 val;

+       bcm63xx_uart_register();
+
        if (board.has_enet0 &&
            !board_get_mac_address(board.enet0.mac_addr))
                bcm63xx_enet_register(0, &board.enet0);
diff --git a/arch/mips/bcm63xx/dev-uart.c b/arch/mips/bcm63xx/dev-uart.c
new file mode 100644
index 0000000..5f3d89c
--- /dev/null
+++ b/arch/mips/bcm63xx/dev-uart.c
@@ -0,0 +1,41 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Pub=
lic
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <bcm63xx_cpu.h>
+#include <bcm63xx_dev_uart.h>
+
+static struct resource uart_resources[] =3D {
+       {
+               .start          =3D -1, /* filled at runtime */
+               .end            =3D -1, /* filled at runtime */
+               .flags          =3D IORESOURCE_MEM,
+       },
+       {
+               .start          =3D -1, /* filled at runtime */
+               .flags          =3D IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bcm63xx_uart_device =3D {
+       .name           =3D "bcm63xx_uart",
+       .id             =3D 0,
+       .num_resources  =3D ARRAY_SIZE(uart_resources),
+       .resource       =3D uart_resources,
+};
+
+int __init bcm63xx_uart_register(void)
+{
+       uart_resources[0].start =3D bcm63xx_regset_address(RSET_UART0);
+       uart_resources[0].end =3D uart_resources[0].start;
+       uart_resources[0].end +=3D RSET_UART_SIZE - 1;
+       uart_resources[1].start =3D bcm63xx_get_irq_number(IRQ_UART0);
+       return platform_device_register(&bcm63xx_uart_device);
+}
diff --git a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_uart.h b/arch/m=
ips/include/asm/mach-bcm63xx/bcm63xx_dev_uart.h
new file mode 100644
index 0000000..bf348f5
--- /dev/null
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_uart.h
@@ -0,0 +1,6 @@
+#ifndef BCM63XX_DEV_UART_H_
+#define BCM63XX_DEV_UART_H_
+
+int bcm63xx_uart_register(void);
+
+#endif /* BCM63XX_DEV_UART_H_ */
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 03422ce..e707120 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -1458,4 +1458,23 @@ config SERIAL_TIMBERDALE
        ---help---
        Add support for UART controller on timberdale.

+config SERIAL_BCM63XX
+       tristate "bcm63xx serial port support"
+       select SERIAL_CORE
+       depends on BCM63XX
+       help
+         If you have a bcm63xx CPU, you can enable its onboard
+         serial port by enabling this options.
+
+          To compile this driver as a module, choose M here: the
+          module will be called bcm963xx_uart.
+
+config SERIAL_BCM63XX_CONSOLE
+       bool "Console on bcm63xx serial port"
+       depends on SERIAL_BCM63XX=3Dy
+       select SERIAL_CORE_CONSOLE
+       help
+         If you have enabled the serial port on the bcm63xx CPU
+         you can make it the console by answering Y to this option.
+
 endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 97f6fcc..d21d5dd 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_SERIAL_CLPS711X) +=3D clps711x.o
 obj-$(CONFIG_SERIAL_PXA) +=3D pxa.o
 obj-$(CONFIG_SERIAL_PNX8XXX) +=3D pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) +=3D sa1100.o
+obj-$(CONFIG_SERIAL_BCM63XX) +=3D bcm63xx_uart.o
 obj-$(CONFIG_SERIAL_BFIN) +=3D bfin_5xx.o
 obj-$(CONFIG_SERIAL_BFIN_SPORT) +=3D bfin_sport_uart.o
 obj-$(CONFIG_SERIAL_SAMSUNG) +=3D samsung.o
diff --git a/drivers/serial/bcm63xx_uart.c b/drivers/serial/bcm63xx_uart.c
new file mode 100644
index 0000000..beddaa6
--- /dev/null
+++ b/drivers/serial/bcm63xx_uart.c
@@ -0,0 +1,890 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Pub=
lic
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Derived from many drivers using generic_serial interface.
+ *
+ * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
+ *
+ *  Serial driver for BCM63xx integrated UART.
+ *
+ * Hardware flow control was _not_ tested since I only have RX/TX on
+ * my board.
+ */
+
+#if defined(CONFIG_SERIAL_BCM63XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/console.h>
+#include <linux/clk.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/sysrq.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+
+#include <bcm63xx_clk.h>
+#include <bcm63xx_irq.h>
+#include <bcm63xx_regs.h>
+#include <bcm63xx_io.h>
+
+#define BCM63XX_NR_UARTS       1
+
+static struct uart_port ports[BCM63XX_NR_UARTS];
+
+/*
+ * rx interrupt mask / stat
+ *
+ * mask:
+ *  - rx fifo full
+ *  - rx fifo above threshold
+ *  - rx fifo not empty for too long
+ */
+#define UART_RX_INT_MASK       (UART_IR_MASK(UART_IR_RXOVER) |         \
+                               UART_IR_MASK(UART_IR_RXTHRESH) |        \
+                               UART_IR_MASK(UART_IR_RXTIMEOUT))
+
+#define UART_RX_INT_STAT       (UART_IR_STAT(UART_IR_RXOVER) |         \
+                               UART_IR_STAT(UART_IR_RXTHRESH) |        \
+                               UART_IR_STAT(UART_IR_RXTIMEOUT))
+
+/*
+ * tx interrupt mask / stat
+ *
+ * mask:
+ * - tx fifo empty
+ * - tx fifo below threshold
+ */
+#define UART_TX_INT_MASK       (UART_IR_MASK(UART_IR_TXEMPTY) |        \
+                               UART_IR_MASK(UART_IR_TXTRESH))
+
+#define UART_TX_INT_STAT       (UART_IR_STAT(UART_IR_TXEMPTY) |        \
+                               UART_IR_STAT(UART_IR_TXTRESH))
+
+/*
+ * external input interrupt
+ *
+ * mask: any edge on CTS, DCD
+ */
+#define UART_EXTINP_INT_MASK   (UART_EXTINP_IRMASK(UART_EXTINP_IR_CTS) | \
+                                UART_EXTINP_IRMASK(UART_EXTINP_IR_DCD))
+
+/*
+ * handy uart register accessor
+ */
+static inline unsigned int bcm_uart_readl(struct uart_port *port,
+                                        unsigned int offset)
+{
+       return bcm_readl(port->membase + offset);
+}
+
+static inline void bcm_uart_writel(struct uart_port *port,
+                                 unsigned int value, unsigned int offset)
+{
+       bcm_writel(value, port->membase + offset);
+}
+
+/*
+ * serial core request to check if uart tx fifo is empty
+ */
+static unsigned int bcm_uart_tx_empty(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       return (val & UART_IR_STAT(UART_IR_TXEMPTY)) ? 1 : 0;
+}
+
+/*
+ * serial core request to set RTS and DTR pin state and loopback mode
+ */
+static void bcm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_MCTL_REG);
+       val &=3D ~(UART_MCTL_DTR_MASK | UART_MCTL_RTS_MASK);
+       /* invert of written value is reflected on the pin */
+       if (!(mctrl & TIOCM_DTR))
+               val |=3D UART_MCTL_DTR_MASK;
+       if (!(mctrl & TIOCM_RTS))
+               val |=3D UART_MCTL_RTS_MASK;
+       bcm_uart_writel(port, val, UART_MCTL_REG);
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       if (mctrl & TIOCM_LOOP)
+               val |=3D UART_CTL_LOOPBACK_MASK;
+       else
+               val &=3D ~UART_CTL_LOOPBACK_MASK;
+       bcm_uart_writel(port, val, UART_CTL_REG);
+}
+
+/*
+ * serial core request to return RI, CTS, DCD and DSR pin state
+ */
+static unsigned int bcm_uart_get_mctrl(struct uart_port *port)
+{
+       unsigned int val, mctrl;
+
+       mctrl =3D 0;
+       val =3D bcm_uart_readl(port, UART_EXTINP_REG);
+       if (val & UART_EXTINP_RI_MASK)
+               mctrl |=3D TIOCM_RI;
+       if (val & UART_EXTINP_CTS_MASK)
+               mctrl |=3D TIOCM_CTS;
+       if (val & UART_EXTINP_DCD_MASK)
+               mctrl |=3D TIOCM_CD;
+       if (val & UART_EXTINP_DSR_MASK)
+               mctrl |=3D TIOCM_DSR;
+       return mctrl;
+}
+
+/*
+ * serial core request to disable tx ASAP (used for flow control)
+ */
+static void bcm_uart_stop_tx(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val &=3D ~(UART_CTL_TXEN_MASK);
+       bcm_uart_writel(port, val, UART_CTL_REG);
+
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       val &=3D ~UART_TX_INT_MASK;
+       bcm_uart_writel(port, val, UART_IR_REG);
+}
+
+/*
+ * serial core request to (re)enable tx
+ */
+static void bcm_uart_start_tx(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       val |=3D UART_TX_INT_MASK;
+       bcm_uart_writel(port, val, UART_IR_REG);
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val |=3D UART_CTL_TXEN_MASK;
+       bcm_uart_writel(port, val, UART_CTL_REG);
+}
+
+/*
+ * serial core request to stop rx, called before port shutdown
+ */
+static void bcm_uart_stop_rx(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       val &=3D ~UART_RX_INT_MASK;
+       bcm_uart_writel(port, val, UART_IR_REG);
+}
+
+/*
+ * serial core request to enable modem status interrupt reporting
+ */
+static void bcm_uart_enable_ms(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       val |=3D UART_IR_MASK(UART_IR_EXTIP);
+       bcm_uart_writel(port, val, UART_IR_REG);
+}
+
+/*
+ * serial core request to start/stop emitting break char
+ */
+static void bcm_uart_break_ctl(struct uart_port *port, int ctl)
+{
+       unsigned long flags;
+       unsigned int val;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       if (ctl)
+               val |=3D UART_CTL_XMITBRK_MASK;
+       else
+               val &=3D ~UART_CTL_XMITBRK_MASK;
+       bcm_uart_writel(port, val, UART_CTL_REG);
+
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+/*
+ * return port type in string format
+ */
+static const char *bcm_uart_type(struct uart_port *port)
+{
+       return (port->type =3D=3D PORT_BCM63XX) ? "bcm63xx_uart" : NULL;
+}
+
+/*
+ * read all chars in rx fifo and send them to core
+ */
+static void bcm_uart_do_rx(struct uart_port *port)
+{
+       struct tty_struct *tty;
+       unsigned int max_count;
+
+       /* limit number of char read in interrupt, should not be
+        * higher than fifo size anyway since we're much faster than
+        * serial port */
+       max_count =3D 32;
+       tty =3D port->info->port.tty;
+       do {
+               unsigned int iestat, c, cstat;
+               char flag;
+
+               /* get overrun/fifo empty information from ier
+                * register */
+               iestat =3D bcm_uart_readl(port, UART_IR_REG);
+               if (!(iestat & UART_IR_STAT(UART_IR_RXNOTEMPTY)))
+                       break;
+
+               cstat =3D c =3D bcm_uart_readl(port, UART_FIFO_REG);
+               port->icount.rx++;
+               flag =3D TTY_NORMAL;
+               c &=3D 0xff;
+
+               if (unlikely((cstat & UART_FIFO_ANYERR_MASK))) {
+                       /* do stats first */
+                       if (cstat & UART_FIFO_BRKDET_MASK) {
+                               port->icount.brk++;
+                               if (uart_handle_break(port))
+                                       continue;
+                       }
+
+                       if (cstat & UART_FIFO_PARERR_MASK)
+                               port->icount.parity++;
+                       if (cstat & UART_FIFO_FRAMEERR_MASK)
+                               port->icount.frame++;
+
+                       /* update flag wrt read_status_mask */
+                       cstat &=3D port->read_status_mask;
+                       if (cstat & UART_FIFO_BRKDET_MASK)
+                               flag =3D TTY_BREAK;
+                       if (cstat & UART_FIFO_FRAMEERR_MASK)
+                               flag =3D TTY_FRAME;
+                       if (cstat & UART_FIFO_PARERR_MASK)
+                               flag =3D TTY_PARITY;
+               }
+
+               if (uart_handle_sysrq_char(port, c))
+                       continue;
+
+               if (unlikely(iestat & UART_IR_STAT(UART_IR_RXOVER))) {
+                       port->icount.overrun++;
+                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+               }
+
+               if ((cstat & port->ignore_status_mask) =3D=3D 0)
+                       tty_insert_flip_char(tty, c, flag);
+
+       } while (--max_count);
+
+       tty_flip_buffer_push(tty);
+}
+
+/*
+ * fill tx fifo with chars to send, stop when fifo is about to be full
+ * or when all chars have been sent.
+ */
+static void bcm_uart_do_tx(struct uart_port *port)
+{
+       struct circ_buf *xmit;
+       unsigned int val, max_count;
+
+       if (port->x_char) {
+               bcm_uart_writel(port, port->x_char, UART_FIFO_REG);
+               port->icount.tx++;
+               port->x_char =3D 0;
+               return;
+       }
+
+       if (uart_tx_stopped(port)) {
+               bcm_uart_stop_tx(port);
+               return;
+       }
+
+       xmit =3D &port->info->xmit;
+       if (uart_circ_empty(xmit))
+               goto txq_empty;
+
+       val =3D bcm_uart_readl(port, UART_MCTL_REG);
+       val =3D (val & UART_MCTL_TXFIFOFILL_MASK) >> UART_MCTL_TXFIFOFILL_S=
HIFT;
+       max_count =3D port->fifosize - val;
+
+       while (max_count--) {
+               unsigned int c;
+
+               c =3D xmit->buf[xmit->tail];
+               bcm_uart_writel(port, c, UART_FIFO_REG);
+               xmit->tail =3D (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+               port->icount.tx++;
+               if (uart_circ_empty(xmit))
+                       break;
+       }
+
+       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+               uart_write_wakeup(port);
+
+       if (uart_circ_empty(xmit))
+               goto txq_empty;
+       return;
+
+txq_empty:
+       /* nothing to send, disable transmit interrupt */
+       val =3D bcm_uart_readl(port, UART_IR_REG);
+       val &=3D ~UART_TX_INT_MASK;
+       bcm_uart_writel(port, val, UART_IR_REG);
+       return;
+}
+
+/*
+ * process uart interrupt
+ */
+static irqreturn_t bcm_uart_interrupt(int irq, void *dev_id)
+{
+       struct uart_port *port;
+       unsigned int irqstat;
+
+       port =3D dev_id;
+       spin_lock(&port->lock);
+
+       irqstat =3D bcm_uart_readl(port, UART_IR_REG);
+       if (irqstat & UART_RX_INT_STAT)
+               bcm_uart_do_rx(port);
+
+       if (irqstat & UART_TX_INT_STAT)
+               bcm_uart_do_tx(port);
+
+       if (irqstat & UART_IR_MASK(UART_IR_EXTIP)) {
+               unsigned int estat;
+
+               estat =3D bcm_uart_readl(port, UART_EXTINP_REG);
+               if (estat & UART_EXTINP_IRSTAT(UART_EXTINP_IR_CTS))
+                       uart_handle_cts_change(port,
+                                              estat & UART_EXTINP_CTS_MASK=
);
+               if (estat & UART_EXTINP_IRSTAT(UART_EXTINP_IR_DCD))
+                       uart_handle_dcd_change(port,
+                                              estat & UART_EXTINP_DCD_MASK=
);
+       }
+
+       spin_unlock(&port->lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * enable rx & tx operation on uart
+ */
+static void bcm_uart_enable(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val |=3D (UART_CTL_BRGEN_MASK | UART_CTL_TXEN_MASK | UART_CTL_RXEN_=
MASK);
+       bcm_uart_writel(port, val, UART_CTL_REG);
+}
+
+/*
+ * disable rx & tx operation on uart
+ */
+static void bcm_uart_disable(struct uart_port *port)
+{
+       unsigned int val;
+
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val &=3D ~(UART_CTL_BRGEN_MASK | UART_CTL_TXEN_MASK |
+                UART_CTL_RXEN_MASK);
+       bcm_uart_writel(port, val, UART_CTL_REG);
+}
+
+/*
+ * clear all unread data in rx fifo and unsent data in tx fifo
+ */
+static void bcm_uart_flush(struct uart_port *port)
+{
+       unsigned int val;
+
+       /* empty rx and tx fifo */
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val |=3D UART_CTL_RSTRXFIFO_MASK | UART_CTL_RSTTXFIFO_MASK;
+       bcm_uart_writel(port, val, UART_CTL_REG);
+
+       /* read any pending char to make sure all irq status are
+        * cleared */
+       (void)bcm_uart_readl(port, UART_FIFO_REG);
+}
+
+/*
+ * serial core request to initialize uart and start rx operation
+ */
+static int bcm_uart_startup(struct uart_port *port)
+{
+       unsigned int val;
+       int ret;
+
+       /* mask all irq and flush port */
+       bcm_uart_disable(port);
+       bcm_uart_writel(port, 0, UART_IR_REG);
+       bcm_uart_flush(port);
+
+       /* clear any pending external input interrupt */
+       (void)bcm_uart_readl(port, UART_EXTINP_REG);
+
+       /* set rx/tx fifo thresh to fifo half size */
+       val =3D bcm_uart_readl(port, UART_MCTL_REG);
+       val &=3D ~(UART_MCTL_RXFIFOTHRESH_MASK | UART_MCTL_TXFIFOTHRESH_MAS=
K);
+       val |=3D (port->fifosize / 2) << UART_MCTL_RXFIFOTHRESH_SHIFT;
+       val |=3D (port->fifosize / 2) << UART_MCTL_TXFIFOTHRESH_SHIFT;
+       bcm_uart_writel(port, val, UART_MCTL_REG);
+
+       /* set rx fifo timeout to 1 char time */
+       val =3D bcm_uart_readl(port, UART_CTL_REG);
+       val &=3D ~UART_CTL_RXTMOUTCNT_MASK;
+       val |=3D 1 << UART_CTL_RXTMOUTCNT_SHIFT;
+       bcm_uart_writel(port, val, UART_CTL_REG);
+
+       /* report any edge on dcd and cts */
+       val =3D UART_EXTINP_INT_MASK;
+       val |=3D UART_EXTINP_DCD_NOSENSE_MASK;
+       val |=3D UART_EXTINP_CTS_NOSENSE_MASK;
+       bcm_uart_writel(port, val, UART_EXTINP_REG);
+
+       /* register irq and enable rx interrupts */
+       ret =3D request_irq(port->irq, bcm_uart_interrupt, 0,
+                         bcm_uart_type(port), port);
+       if (ret)
+               return ret;
+       bcm_uart_writel(port, UART_RX_INT_MASK, UART_IR_REG);
+       bcm_uart_enable(port);
+       return 0;
+}
+
+/*
+ * serial core request to flush & disable uart
+ */
+static void bcm_uart_shutdown(struct uart_port *port)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&port->lock, flags);
+       bcm_uart_writel(port, 0, UART_IR_REG);
+       spin_unlock_irqrestore(&port->lock, flags);
+
+       bcm_uart_disable(port);
+       bcm_uart_flush(port);
+       free_irq(port->irq, port);
+}
+
+/*
+ * serial core request to change current uart setting
+ */
+static void bcm_uart_set_termios(struct uart_port *port,
+                                struct ktermios *new,
+                                struct ktermios *old)
+{
+       unsigned int ctl, baud, quot, ier;
+       unsigned long flags;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       /* disable uart while changing speed */
+       bcm_uart_disable(port);
+       bcm_uart_flush(port);
+
+       /* update Control register */
+       ctl =3D bcm_uart_readl(port, UART_CTL_REG);
+       ctl &=3D ~UART_CTL_BITSPERSYM_MASK;
+
+       switch (new->c_cflag & CSIZE) {
+       case CS5:
+               ctl |=3D (0 << UART_CTL_BITSPERSYM_SHIFT);
+               break;
+       case CS6:
+               ctl |=3D (1 << UART_CTL_BITSPERSYM_SHIFT);
+               break;
+       case CS7:
+               ctl |=3D (2 << UART_CTL_BITSPERSYM_SHIFT);
+               break;
+       default:
+               ctl |=3D (3 << UART_CTL_BITSPERSYM_SHIFT);
+               break;
+       }
+
+       ctl &=3D ~UART_CTL_STOPBITS_MASK;
+       if (new->c_cflag & CSTOPB)
+               ctl |=3D UART_CTL_STOPBITS_2;
+       else
+               ctl |=3D UART_CTL_STOPBITS_1;
+
+       ctl &=3D ~(UART_CTL_RXPAREN_MASK | UART_CTL_TXPAREN_MASK);
+       if (new->c_cflag & PARENB)
+               ctl |=3D (UART_CTL_RXPAREN_MASK | UART_CTL_TXPAREN_MASK);
+       ctl &=3D ~(UART_CTL_RXPAREVEN_MASK | UART_CTL_TXPAREVEN_MASK);
+       if (new->c_cflag & PARODD)
+               ctl |=3D (UART_CTL_RXPAREVEN_MASK | UART_CTL_TXPAREVEN_MASK=
);
+       bcm_uart_writel(port, ctl, UART_CTL_REG);
+
+       /* update Baudword register */
+       baud =3D uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
+       quot =3D uart_get_divisor(port, baud) - 1;
+       bcm_uart_writel(port, quot, UART_BAUD_REG);
+
+       /* update Interrupt register */
+       ier =3D bcm_uart_readl(port, UART_IR_REG);
+
+       ier &=3D ~UART_IR_MASK(UART_IR_EXTIP);
+       if (UART_ENABLE_MS(port, new->c_cflag))
+               ier |=3D UART_IR_MASK(UART_IR_EXTIP);
+
+       bcm_uart_writel(port, ier, UART_IR_REG);
+
+       /* update read/ignore mask */
+       port->read_status_mask =3D UART_FIFO_VALID_MASK;
+       if (new->c_iflag & INPCK) {
+               port->read_status_mask |=3D UART_FIFO_FRAMEERR_MASK;
+               port->read_status_mask |=3D UART_FIFO_PARERR_MASK;
+       }
+       if (new->c_iflag & (BRKINT))
+               port->read_status_mask |=3D UART_FIFO_BRKDET_MASK;
+
+       port->ignore_status_mask =3D 0;
+       if (new->c_iflag & IGNPAR)
+               port->ignore_status_mask |=3D UART_FIFO_PARERR_MASK;
+       if (new->c_iflag & IGNBRK)
+               port->ignore_status_mask |=3D UART_FIFO_BRKDET_MASK;
+       if (!(new->c_cflag & CREAD))
+               port->ignore_status_mask |=3D UART_FIFO_VALID_MASK;
+
+       uart_update_timeout(port, new->c_cflag, baud);
+       bcm_uart_enable(port);
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+/*
+ * serial core request to claim uart iomem
+ */
+static int bcm_uart_request_port(struct uart_port *port)
+{
+       unsigned int size;
+
+       size =3D RSET_UART_SIZE;
+       if (!request_mem_region(port->mapbase, size, "bcm63xx")) {
+               dev_err(port->dev, "Memory region busy\n");
+               return -EBUSY;
+       }
+
+       port->membase =3D ioremap(port->mapbase, size);
+       if (!port->membase) {
+               dev_err(port->dev, "Unable to map registers\n");
+               release_mem_region(port->mapbase, size);
+               return -EBUSY;
+       }
+       return 0;
+}
+
+/*
+ * serial core request to release uart iomem
+ */
+static void bcm_uart_release_port(struct uart_port *port)
+{
+       release_mem_region(port->mapbase, RSET_UART_SIZE);
+       iounmap(port->membase);
+}
+
+/*
+ * serial core request to do any port required autoconfiguration
+ */
+static void bcm_uart_config_port(struct uart_port *port, int flags)
+{
+       if (flags & UART_CONFIG_TYPE) {
+               if (bcm_uart_request_port(port))
+                       return;
+               port->type =3D PORT_BCM63XX;
+       }
+}
+
+/*
+ * serial core request to check that port information in serinfo are
+ * suitable
+ */
+static int bcm_uart_verify_port(struct uart_port *port,
+                               struct serial_struct *serinfo)
+{
+       if (port->type !=3D PORT_BCM63XX)
+               return -EINVAL;
+       if (port->irq !=3D serinfo->irq)
+               return -EINVAL;
+       if (port->iotype !=3D serinfo->io_type)
+               return -EINVAL;
+       if (port->mapbase !=3D (unsigned long)serinfo->iomem_base)
+               return -EINVAL;
+       return 0;
+}
+
+/* serial core callbacks */
+static struct uart_ops bcm_uart_ops =3D {
+       .tx_empty       =3D bcm_uart_tx_empty,
+       .get_mctrl      =3D bcm_uart_get_mctrl,
+       .set_mctrl      =3D bcm_uart_set_mctrl,
+       .start_tx       =3D bcm_uart_start_tx,
+       .stop_tx        =3D bcm_uart_stop_tx,
+       .stop_rx        =3D bcm_uart_stop_rx,
+       .enable_ms      =3D bcm_uart_enable_ms,
+       .break_ctl      =3D bcm_uart_break_ctl,
+       .startup        =3D bcm_uart_startup,
+       .shutdown       =3D bcm_uart_shutdown,
+       .set_termios    =3D bcm_uart_set_termios,
+       .type           =3D bcm_uart_type,
+       .release_port   =3D bcm_uart_release_port,
+       .request_port   =3D bcm_uart_request_port,
+       .config_port    =3D bcm_uart_config_port,
+       .verify_port    =3D bcm_uart_verify_port,
+};
+
+
+
+#ifdef CONFIG_SERIAL_BCM63XX_CONSOLE
+static inline void wait_for_xmitr(struct uart_port *port)
+{
+       unsigned int tmout;
+
+       /* Wait up to 10ms for the character(s) to be sent. */
+       tmout =3D 10000;
+       while (--tmout) {
+               unsigned int val;
+
+               val =3D bcm_uart_readl(port, UART_IR_REG);
+               if (val & UART_IR_STAT(UART_IR_TXEMPTY))
+                       break;
+               udelay(1);
+       }
+
+       /* Wait up to 1s for flow control if necessary */
+       if (port->flags & UPF_CONS_FLOW) {
+               tmout =3D 1000000;
+               while (--tmout) {
+                       unsigned int val;
+
+                       val =3D bcm_uart_readl(port, UART_EXTINP_REG);
+                       if (val & UART_EXTINP_CTS_MASK)
+                               break;
+                       udelay(1);
+               }
+       }
+}
+
+/*
+ * output given char
+ */
+static void bcm_console_putchar(struct uart_port *port, int ch)
+{
+       wait_for_xmitr(port);
+       bcm_uart_writel(port, ch, UART_FIFO_REG);
+}
+
+/*
+ * console core request to output given string
+ */
+static void bcm_console_write(struct console *co, const char *s,
+                             unsigned int count)
+{
+       struct uart_port *port;
+       unsigned long flags;
+       int locked;
+
+       port =3D &ports[co->index];
+
+       local_irq_save(flags);
+       if (port->sysrq) {
+               /* bcm_uart_interrupt() already took the lock */
+               locked =3D 0;
+       } else if (oops_in_progress) {
+               locked =3D spin_trylock(&port->lock);
+       } else {
+               spin_lock(&port->lock);
+               locked =3D 1;
+       }
+
+       /* call helper to deal with \r\n */
+       uart_console_write(port, s, count, bcm_console_putchar);
+
+       /* and wait for char to be transmitted */
+       wait_for_xmitr(port);
+
+       if (locked)
+               spin_unlock(&port->lock);
+       local_irq_restore(flags);
+}
+
+/*
+ * console core request to setup given console, find matching uart
+ * port and setup it.
+ */
+static int bcm_console_setup(struct console *co, char *options)
+{
+       struct uart_port *port;
+       int baud =3D 9600;
+       int bits =3D 8;
+       int parity =3D 'n';
+       int flow =3D 'n';
+
+       if (co->index < 0 || co->index >=3D BCM63XX_NR_UARTS)
+               return -EINVAL;
+       port =3D &ports[co->index];
+       if (!port->membase)
+               return -ENODEV;
+       if (options)
+               uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+       return uart_set_options(port, co, baud, parity, bits, flow);
+}
+
+static struct uart_driver bcm_uart_driver;
+
+static struct console bcm63xx_console =3D {
+       .name           =3D "ttyS",
+       .write          =3D bcm_console_write,
+       .device         =3D uart_console_device,
+       .setup          =3D bcm_console_setup,
+       .flags          =3D CON_PRINTBUFFER,
+       .index          =3D -1,
+       .data           =3D &bcm_uart_driver,
+};
+
+static int __init bcm63xx_console_init(void)
+{
+       register_console(&bcm63xx_console);
+       return 0;
+}
+
+console_initcall(bcm63xx_console_init);
+
+#define BCM63XX_CONSOLE        (&bcm63xx_console)
+#else
+#define BCM63XX_CONSOLE        NULL
+#endif /* CONFIG_SERIAL_BCM63XX_CONSOLE */
+
+static struct uart_driver bcm_uart_driver =3D {
+       .owner          =3D THIS_MODULE,
+       .driver_name    =3D "bcm63xx_uart",
+       .dev_name       =3D "ttyS",
+       .major          =3D TTY_MAJOR,
+       .minor          =3D 64,
+       .nr             =3D 1,
+       .cons           =3D BCM63XX_CONSOLE,
+};
+
+/*
+ * platform driver probe/remove callback
+ */
+static int __devinit bcm_uart_probe(struct platform_device *pdev)
+{
+       struct resource *res_mem, *res_irq;
+       struct uart_port *port;
+       struct clk *clk;
+       int ret;
+
+       if (pdev->id < 0 || pdev->id >=3D BCM63XX_NR_UARTS)
+               return -EINVAL;
+
+       if (ports[pdev->id].membase)
+               return -EBUSY;
+
+       res_mem =3D platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res_mem)
+               return -ENODEV;
+
+       res_irq =3D platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (!res_irq)
+               return -ENODEV;
+
+       clk =3D clk_get(&pdev->dev, "periph");
+       if (IS_ERR(clk))
+               return -ENODEV;
+
+       port =3D &ports[pdev->id];
+       memset(port, 0, sizeof(*port));
+       port->iotype =3D UPIO_MEM;
+       port->mapbase =3D res_mem->start;
+       port->irq =3D res_irq->start;
+       port->ops =3D &bcm_uart_ops;
+       port->flags =3D UPF_BOOT_AUTOCONF;
+       port->dev =3D &pdev->dev;
+       port->fifosize =3D 16;
+       port->uartclk =3D clk_get_rate(clk) / 2;
+       clk_put(clk);
+
+       ret =3D uart_add_one_port(&bcm_uart_driver, port);
+       if (ret) {
+               kfree(port);
+               return ret;
+       }
+       platform_set_drvdata(pdev, port);
+       return 0;
+}
+
+static int __devexit bcm_uart_remove(struct platform_device *pdev)
+{
+       struct uart_port *port;
+
+       port =3D platform_get_drvdata(pdev);
+       uart_remove_one_port(&bcm_uart_driver, port);
+       platform_set_drvdata(pdev, NULL);
+       /* mark port as free */
+       ports[pdev->id].membase =3D 0;
+       return 0;
+}
+
+/*
+ * platform driver stuff
+ */
+static struct platform_driver bcm_uart_platform_driver =3D {
+       .probe  =3D bcm_uart_probe,
+       .remove =3D __devexit_p(bcm_uart_remove),
+       .driver =3D {
+               .owner =3D THIS_MODULE,
+               .name  =3D "bcm63xx_uart",
+       },
+};
+
+static int __init bcm_uart_init(void)
+{
+       int ret;
+
+       ret =3D uart_register_driver(&bcm_uart_driver);
+       if (ret)
+               return ret;
+
+       ret =3D platform_driver_register(&bcm_uart_platform_driver);
+       if (ret)
+               uart_unregister_driver(&bcm_uart_driver);
+
+       return ret;
+}
+
+static void __exit bcm_uart_exit(void)
+{
+       platform_driver_unregister(&bcm_uart_platform_driver);
+       uart_unregister_driver(&bcm_uart_driver);
+}
+
+module_init(bcm_uart_init);
+module_exit(bcm_uart_exit);
+
+MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
+MODULE_DESCRIPTION("Broadcom 63<xx integrated uart driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 23d2fb0..7abe73b 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -174,6 +174,9 @@
 /* Qualcomm MSM SoCs */
 #define PORT_MSM       88

+/* BCM63xx family SoCs */
+#define PORT_BCM63XX   89
+
 #ifdef __KERNEL__

 #include <linux/compiler.h>


--
Maxime



