[RESEND PATCH v3] serial/arc-uart: Add new driver

2012-10-11 Thread Vineet.Gupta1
From: Vineet Gupta 

Driver for non-standard on-chip UART, instantiated in the ARC (Synopsys)
FPGA Boards such as ARCAngel4/ML50x

Signed-off-by: Vineet Gupta 
---
 drivers/tty/serial/Kconfig|   25 ++
 drivers/tty/serial/Makefile   |1 +
 drivers/tty/serial/arc_uart.c |  747 +
 include/linux/serial_core.h   |3 +
 4 files changed, 776 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/serial/arc_uart.c

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 233fbaa..0a87741 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1423,4 +1423,29 @@ config SERIAL_EFM32_UART_CONSOLE
depends on SERIAL_EFM32_UART=y
select SERIAL_CORE_CONSOLE
 
+config SERIAL_ARC
+   bool "ARC UART driver support"
+   select SERIAL_CORE
+   default y
+   help
+ Driver for on-chip UART for ARC(Synopsys) for the legacy
+ FPGA Boards (ML50x/ARCAngel4)
+
+config SERIAL_ARC_CONSOLE
+   bool
+   select SERIAL_CORE_CONSOLE
+   depends on SERIAL_ARC=y
+   default y
+   help
+ Enable system Console on ARC UART
+
+config SERIAL_ARC_NR_PORTS
+   int 'Number of ports'
+   range 1 3
+   default 1
+   depends on SERIAL_ARC
+   help
+ Set this to the number of serial ports you want the driver
+ to support.
+
 endmenu
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 4f694da..df1b998 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -82,3 +82,4 @@ obj-$(CONFIG_SERIAL_XILINX_PS_UART) += xilinx_uartps.o
 obj-$(CONFIG_SERIAL_SIRFSOC) += sirfsoc_uart.o
 obj-$(CONFIG_SERIAL_AR933X)   += ar933x_uart.o
 obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
+obj-$(CONFIG_SERIAL_ARC)   += arc_uart.o
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
new file mode 100644
index 000..9215bf4
--- /dev/null
+++ b/drivers/tty/serial/arc_uart.c
@@ -0,0 +1,747 @@
+/*
+ * ARC On-Chip(fpga) UART Driver
+ *
+ * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * vineetg: July 10th 2012
+ *  -Decoupled the driver from arch/arc
+ *+Using platform_get_resource() for irq/membase (thx to bfin_uart.c)
+ *+Using early_platform_xxx() for early console (thx to mach-shmobile/xxx)
+ *
+ * Vineetg: Aug 21st 2010
+ *  -Is uart_tx_stopped() not done in tty write path as it has already been
+ *   taken care of, in serial core
+ *
+ * Vineetg: Aug 18th 2010
+ *  -New Serial Core based ARC UART driver
+ *  -Derived largely from blackfin driver albiet with some major tweaks
+ *
+ * TODO:
+ *  -check if sysreq works
+ */
+
+#if defined(CONFIG_SERIAL_ARC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * ARC UART Hardware Specs
+ /
+#define ARC_UART_TX_FIFO_SIZE  1
+
+/*
+ * UART Register set (this is not a Standards Compliant IP)
+ * Also each reg is Word aligned, but only 8 bits wide
+ */
+#define R_ID0  0
+#define R_ID1  1
+#define R_ID2  2
+#define R_ID3  3
+#define R_DATA 4
+#define R_STS  5
+#define R_BAUDL6
+#define R_BAUDH7
+
+/* Bits for UART Status Reg (R/W) */
+#define RXIENB  0x04   /* Receive Interrupt Enable */
+#define TXIENB  0x40   /* Transmit Interrupt Enable */
+
+#define RXEMPTY 0x20   /* Receive FIFO Empty: No char receivede */
+#define TXEMPTY 0x80   /* Transmit FIFO Empty, thus char can be written into */
+
+#define RXFULL  0x08   /* Receive FIFO full */
+#define RXFULL1 0x10   /* Receive FIFO has space for 1 char (tot space=4) */
+
+#define RXFERR  0x01   /* Frame Error: Stop Bit not detected */
+#define RXOERR  0x02   /* OverFlow Err: Char recv but RXFULL still set */
+
+/* Uart bit fiddling helpers: lowest level */
+#define RBASE(uart, reg)  ((unsigned int *)uart->port.membase + reg)
+#define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
+#define UART_REG_GET(u, r)readb(RBASE(u, r))
+
+#define UART_REG_OR(u, r, v)  UART_REG_SET(u, r, UART_REG_GET(u, r) | (v))
+#define UART_REG_CLR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) & ~(v))
+
+/* Uart bit fiddling helpers: API level */
+#define UART_SET_DATA(uart, val)   UART_REG_SET(uart, R_DATA, val)
+#define UART_GET_DATA(uart)UART_REG_GET(uart, R_DATA)
+
+#define UART_SET_BAUDH(uart, val)  UART_REG_SET(uart, R_BAUDH, val)
+#define UART_SET_BAUDL(uart, val)  UART_REG_SET(uart, R_BAUDL, val)
+
+#define UART_CLR_STATUS(uart, val) UART_REG_CLR(uart, R_STS, val)
+#define UART_GET_STATUS(uart)  UART_REG_GET(uart, R_STS)
+
+#define UART_ALL_IRQ_DISABLE(uart) UART_REG_CLR(uart, 

[RESEND PATCH v3] serial/arc-uart: Add new driver

2012-10-11 Thread Vineet.Gupta1
From: Vineet Gupta 

Hi,

Please find following ARC UART driver with all the review comments incorporated.
It's rebased off of current tip (commit 12250d843e)

Please consider merging.

Thx,
-Vineet

v3:
* Removed empty arc_serial_set_ldisc()
* More set_termios fixes - CSIZE forced to CS8 (for 8N1)
* global @running_on_iss replaced with platform data, saved in device
  specific port structure.

v2:
* ttyARC used as device name
* Dynamic assignment of major/minor numbers.
* Ref counting tty in rx routine to prevent it from disappearing in
  case of a hangup
* set_termios fixes:
  - hardware flow control/parity are marked as unsupported
  - baud written back to termios
* cosmetics such as commenting the need for @running_on_iss, empty lines
  etc

Vineet Gupta (1):
  serial/arc-uart: Add new driver

 drivers/tty/serial/Kconfig|   25 ++
 drivers/tty/serial/Makefile   |1 +
 drivers/tty/serial/arc_uart.c |  747 +
 include/linux/serial_core.h   |3 +
 4 files changed, 776 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/serial/arc_uart.c

-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH v3] serial/arc-uart: Add new driver

2012-10-11 Thread Vineet.Gupta1
From: Vineet Gupta vgu...@synopsys.com

Hi,

Please find following ARC UART driver with all the review comments incorporated.
It's rebased off of current tip (commit 12250d843e)

Please consider merging.

Thx,
-Vineet

v3:
* Removed empty arc_serial_set_ldisc()
* More set_termios fixes - CSIZE forced to CS8 (for 8N1)
* global @running_on_iss replaced with platform data, saved in device
  specific port structure.

v2:
* ttyARC used as device name
* Dynamic assignment of major/minor numbers.
* Ref counting tty in rx routine to prevent it from disappearing in
  case of a hangup
* set_termios fixes:
  - hardware flow control/parity are marked as unsupported
  - baud written back to termios
* cosmetics such as commenting the need for @running_on_iss, empty lines
  etc

Vineet Gupta (1):
  serial/arc-uart: Add new driver

 drivers/tty/serial/Kconfig|   25 ++
 drivers/tty/serial/Makefile   |1 +
 drivers/tty/serial/arc_uart.c |  747 +
 include/linux/serial_core.h   |3 +
 4 files changed, 776 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/serial/arc_uart.c

-- 
1.7.4.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH v3] serial/arc-uart: Add new driver

2012-10-11 Thread Vineet.Gupta1
From: Vineet Gupta vgu...@synopsys.com

Driver for non-standard on-chip UART, instantiated in the ARC (Synopsys)
FPGA Boards such as ARCAngel4/ML50x

Signed-off-by: Vineet Gupta vgu...@synopsys.com
---
 drivers/tty/serial/Kconfig|   25 ++
 drivers/tty/serial/Makefile   |1 +
 drivers/tty/serial/arc_uart.c |  747 +
 include/linux/serial_core.h   |3 +
 4 files changed, 776 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/serial/arc_uart.c

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 233fbaa..0a87741 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1423,4 +1423,29 @@ config SERIAL_EFM32_UART_CONSOLE
depends on SERIAL_EFM32_UART=y
select SERIAL_CORE_CONSOLE
 
+config SERIAL_ARC
+   bool ARC UART driver support
+   select SERIAL_CORE
+   default y
+   help
+ Driver for on-chip UART for ARC(Synopsys) for the legacy
+ FPGA Boards (ML50x/ARCAngel4)
+
+config SERIAL_ARC_CONSOLE
+   bool
+   select SERIAL_CORE_CONSOLE
+   depends on SERIAL_ARC=y
+   default y
+   help
+ Enable system Console on ARC UART
+
+config SERIAL_ARC_NR_PORTS
+   int 'Number of ports'
+   range 1 3
+   default 1
+   depends on SERIAL_ARC
+   help
+ Set this to the number of serial ports you want the driver
+ to support.
+
 endmenu
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 4f694da..df1b998 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -82,3 +82,4 @@ obj-$(CONFIG_SERIAL_XILINX_PS_UART) += xilinx_uartps.o
 obj-$(CONFIG_SERIAL_SIRFSOC) += sirfsoc_uart.o
 obj-$(CONFIG_SERIAL_AR933X)   += ar933x_uart.o
 obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
+obj-$(CONFIG_SERIAL_ARC)   += arc_uart.o
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
new file mode 100644
index 000..9215bf4
--- /dev/null
+++ b/drivers/tty/serial/arc_uart.c
@@ -0,0 +1,747 @@
+/*
+ * ARC On-Chip(fpga) UART Driver
+ *
+ * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * vineetg: July 10th 2012
+ *  -Decoupled the driver from arch/arc
+ *+Using platform_get_resource() for irq/membase (thx to bfin_uart.c)
+ *+Using early_platform_xxx() for early console (thx to mach-shmobile/xxx)
+ *
+ * Vineetg: Aug 21st 2010
+ *  -Is uart_tx_stopped() not done in tty write path as it has already been
+ *   taken care of, in serial core
+ *
+ * Vineetg: Aug 18th 2010
+ *  -New Serial Core based ARC UART driver
+ *  -Derived largely from blackfin driver albiet with some major tweaks
+ *
+ * TODO:
+ *  -check if sysreq works
+ */
+
+#if defined(CONFIG_SERIAL_ARC_CONSOLE)  defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include linux/module.h
+#include linux/serial.h
+#include linux/console.h
+#include linux/sysrq.h
+#include linux/platform_device.h
+#include linux/tty.h
+#include linux/tty_flip.h
+#include linux/serial_core.h
+#include linux/io.h
+
+/*
+ * ARC UART Hardware Specs
+ /
+#define ARC_UART_TX_FIFO_SIZE  1
+
+/*
+ * UART Register set (this is not a Standards Compliant IP)
+ * Also each reg is Word aligned, but only 8 bits wide
+ */
+#define R_ID0  0
+#define R_ID1  1
+#define R_ID2  2
+#define R_ID3  3
+#define R_DATA 4
+#define R_STS  5
+#define R_BAUDL6
+#define R_BAUDH7
+
+/* Bits for UART Status Reg (R/W) */
+#define RXIENB  0x04   /* Receive Interrupt Enable */
+#define TXIENB  0x40   /* Transmit Interrupt Enable */
+
+#define RXEMPTY 0x20   /* Receive FIFO Empty: No char receivede */
+#define TXEMPTY 0x80   /* Transmit FIFO Empty, thus char can be written into */
+
+#define RXFULL  0x08   /* Receive FIFO full */
+#define RXFULL1 0x10   /* Receive FIFO has space for 1 char (tot space=4) */
+
+#define RXFERR  0x01   /* Frame Error: Stop Bit not detected */
+#define RXOERR  0x02   /* OverFlow Err: Char recv but RXFULL still set */
+
+/* Uart bit fiddling helpers: lowest level */
+#define RBASE(uart, reg)  ((unsigned int *)uart-port.membase + reg)
+#define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
+#define UART_REG_GET(u, r)readb(RBASE(u, r))
+
+#define UART_REG_OR(u, r, v)  UART_REG_SET(u, r, UART_REG_GET(u, r) | (v))
+#define UART_REG_CLR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r)  ~(v))
+
+/* Uart bit fiddling helpers: API level */
+#define UART_SET_DATA(uart, val)   UART_REG_SET(uart, R_DATA, val)
+#define UART_GET_DATA(uart)UART_REG_GET(uart, R_DATA)
+
+#define UART_SET_BAUDH(uart, val)  UART_REG_SET(uart, R_BAUDH, val)
+#define UART_SET_BAUDL(uart, val)  UART_REG_SET(uart, R_BAUDL, val)
+
+#define