]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/serial/altera_jtag_uart.c
Licenses: introduce SPDX Unique Lincense Identifiers
[people/ms/u-boot.git] / drivers / serial / altera_jtag_uart.c
CommitLineData
c9d4f46b
SM
1/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <watchdog.h>
26#include <asm/io.h>
27#include <nios2-io.h>
8c085757
MV
28#include <linux/compiler.h>
29#include <serial.h>
c9d4f46b
SM
30
31DECLARE_GLOBAL_DATA_PTR;
32
33/*------------------------------------------------------------------
34 * JTAG acts as the serial port
35 *-----------------------------------------------------------------*/
36static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
37
8c085757
MV
38static void altera_jtag_serial_setbrg(void)
39{
40}
41
42static int altera_jtag_serial_init(void)
43{
44 return 0;
45}
c9d4f46b 46
8c085757 47static void altera_jtag_serial_putc(char c)
c9d4f46b 48{
99485296
TC
49 while (1) {
50 unsigned st = readl(&jtag->control);
51 if (NIOS_JTAG_WSPACE(st))
52 break;
53#ifdef CONFIG_ALTERA_JTAG_UART_BYPASS
54 if (!(st & NIOS_JTAG_AC)) /* no connection */
55 return;
56#endif
57 WATCHDOG_RESET();
58 }
3ea0037f 59 writel ((unsigned char)c, &jtag->data);
c9d4f46b
SM
60}
61
8c085757 62static int altera_jtag_serial_tstc(void)
c9d4f46b
SM
63{
64 return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
65}
66
8c085757 67static int altera_jtag_serial_getc(void)
c9d4f46b
SM
68{
69 int c;
70 unsigned val;
71
72 while (1) {
73 WATCHDOG_RESET ();
74 val = readl (&jtag->data);
75 if (val & NIOS_JTAG_RVALID)
76 break;
77 }
78 c = val & 0x0ff;
79 return (c);
80}
8c085757 81
8c085757
MV
82static struct serial_device altera_jtag_serial_drv = {
83 .name = "altera_jtag_uart",
84 .start = altera_jtag_serial_init,
85 .stop = NULL,
86 .setbrg = altera_jtag_serial_setbrg,
87 .putc = altera_jtag_serial_putc,
ec3fd689 88 .puts = default_serial_puts,
8c085757
MV
89 .getc = altera_jtag_serial_getc,
90 .tstc = altera_jtag_serial_tstc,
91};
92
93void altera_jtag_serial_initialize(void)
94{
95 serial_register(&altera_jtag_serial_drv);
96}
97
98__weak struct serial_device *default_serial_console(void)
99{
100 return &altera_jtag_serial_drv;
101}