2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <linux/compiler.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 /*------------------------------------------------------------------
34 * JTAG acts as the serial port
35 *-----------------------------------------------------------------*/
36 static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
38 static void altera_jtag_serial_setbrg(void)
42 static int altera_jtag_serial_init(void)
47 static void altera_jtag_serial_putc(char c)
50 unsigned st = readl(&jtag->control);
51 if (NIOS_JTAG_WSPACE(st))
53 #ifdef CONFIG_ALTERA_JTAG_UART_BYPASS
54 if (!(st & NIOS_JTAG_AC)) /* no connection */
59 writel ((unsigned char)c, &jtag->data);
62 static void altera_jtag_serial_puts(const char *s)
68 static int altera_jtag_serial_tstc(void)
70 return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
73 static int altera_jtag_serial_getc(void)
80 val = readl (&jtag->data);
81 if (val & NIOS_JTAG_RVALID)
88 static struct serial_device altera_jtag_serial_drv = {
89 .name = "altera_jtag_uart",
90 .start = altera_jtag_serial_init,
92 .setbrg = altera_jtag_serial_setbrg,
93 .putc = altera_jtag_serial_putc,
94 .puts = altera_jtag_serial_puts,
95 .getc = altera_jtag_serial_getc,
96 .tstc = altera_jtag_serial_tstc,
99 void altera_jtag_serial_initialize(void)
101 serial_register(&altera_jtag_serial_drv);
104 __weak struct serial_device *default_serial_console(void)
106 return &altera_jtag_serial_drv;