2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/compiler.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 /*------------------------------------------------------------------
18 * JTAG acts as the serial port
19 *-----------------------------------------------------------------*/
20 static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
22 static void altera_jtag_serial_setbrg(void)
26 static int altera_jtag_serial_init(void)
31 static void altera_jtag_serial_putc(char c)
34 unsigned st = readl(&jtag->control);
35 if (NIOS_JTAG_WSPACE(st))
37 #ifdef CONFIG_ALTERA_JTAG_UART_BYPASS
38 if (!(st & NIOS_JTAG_AC)) /* no connection */
43 writel ((unsigned char)c, &jtag->data);
46 static int altera_jtag_serial_tstc(void)
48 return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
51 static int altera_jtag_serial_getc(void)
58 val = readl (&jtag->data);
59 if (val & NIOS_JTAG_RVALID)
66 static struct serial_device altera_jtag_serial_drv = {
67 .name = "altera_jtag_uart",
68 .start = altera_jtag_serial_init,
70 .setbrg = altera_jtag_serial_setbrg,
71 .putc = altera_jtag_serial_putc,
72 .puts = default_serial_puts,
73 .getc = altera_jtag_serial_getc,
74 .tstc = altera_jtag_serial_tstc,
77 void altera_jtag_serial_initialize(void)
79 serial_register(&altera_jtag_serial_drv);
82 __weak struct serial_device *default_serial_console(void)
84 return &altera_jtag_serial_drv;