This patch moves the altera jtaguart driver from cpu/nios2/serial.c to
drivers/serial/altera_jtaguart.c.

The registers access is changed from "volatile struct" to readl()/
writel(). This is consistent with Altera HAL and Linux.

Signed-off-by: Thomas Chou <tho...@wytron.com.tw>
---
 drivers/serial/Makefile          |    1 +
 drivers/serial/altera_jtaguart.c |  107 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/altera_jtaguart.c

diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 7ce920d..a7278ae 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB    := $(obj)libserial.a
 
+COBJS-$(CONFIG_ALTERA_JTAGUART) += altera_jtaguart.o
 COBJS-$(CONFIG_ALTERA_UART) += altera_uart.o
 COBJS-$(CONFIG_ARM_DCC) += arm_dcc.o
 COBJS-$(CONFIG_AT91RM9200_USART) += at91rm9200_usart.o
diff --git a/drivers/serial/altera_jtaguart.c b/drivers/serial/altera_jtaguart.c
new file mode 100644
index 0000000..de58356
--- /dev/null
+++ b/drivers/serial/altera_jtaguart.c
@@ -0,0 +1,107 @@
+/*
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcn...@psyent.com>
+ * (C) Copyright 2008, Thomas Chou <tho...@wytron.com.tw>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <asm/io.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Altera JTAG UART register definitions according to the Altera JTAG UART
+ * datasheet: http://www.altera.com/literature/hb/nios2/n2cpu_nii51009.pdf
+ */
+
+#define ALTERA_JTAGUART_SIZE                   8
+
+#define ALTERA_JTAGUART_DATA_REG               0
+
+#define ALTERA_JTAGUART_DATA_DATA_MSK          0x000000FF
+#define ALTERA_JTAGUART_DATA_RVALID_MSK                0x00008000
+#define ALTERA_JTAGUART_DATA_RAVAIL_MSK                0xFFFF0000
+#define ALTERA_JTAGUART_DATA_RAVAIL_OFF                16
+
+#define ALTERA_JTAGUART_CONTROL_REG            4
+
+#define ALTERA_JTAGUART_CONTROL_RE_MSK         0x00000001
+#define ALTERA_JTAGUART_CONTROL_WE_MSK         0x00000002
+#define ALTERA_JTAGUART_CONTROL_RI_MSK         0x00000100
+#define ALTERA_JTAGUART_CONTROL_RI_OFF         8
+#define ALTERA_JTAGUART_CONTROL_WI_MSK         0x00000200
+#define ALTERA_JTAGUART_CONTROL_AC_MSK         0x00000400
+#define ALTERA_JTAGUART_CONTROL_RRDY_MSK       0x00001000
+#define ALTERA_JTAGUART_CONTROL_WSPACE_MSK     0xFFFF0000
+#define ALTERA_JTAGUART_CONTROL_WSPACE_OFF     16
+
+void serial_setbrg(void)
+{
+}
+
+int serial_init(void)
+{
+       serial_setbrg();
+       return 0;
+}
+
+void serial_putc(char c)
+{
+       unsigned status;
+       while (((status =
+                readl(CONFIG_SYS_JTAGUART_BASE + ALTERA_JTAGUART_CONTROL_REG))
+               & ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0) {
+               if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) == 0)
+                       return; /* no connection, bypass */
+               WATCHDOG_RESET();
+       }
+       writel((unsigned char)c,
+              CONFIG_SYS_JTAGUART_BASE + ALTERA_JTAGUART_DATA_REG);
+}
+
+void serial_puts(const char *s)
+{
+       while (*s != 0)
+               serial_putc(*s++);
+}
+
+int serial_tstc(void)
+{
+       return readl(CONFIG_SYS_JTAGUART_BASE + ALTERA_JTAGUART_CONTROL_REG)
+               & ALTERA_JTAGUART_CONTROL_RRDY_MSK;
+}
+
+int serial_getc(void)
+{
+       int c;
+       unsigned val;
+
+       while (1) {
+               WATCHDOG_RESET();
+               val =
+                   readl(CONFIG_SYS_JTAGUART_BASE + ALTERA_JTAGUART_DATA_REG);
+               if (val & ALTERA_JTAGUART_DATA_RVALID_MSK)
+                       break;
+       }
+       c = val & 0x0ff;
+       return c;
+}
-- 
1.6.6.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to