2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/compiler.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 /*------------------------------------------------------------------
19 * UART the serial port
20 *-----------------------------------------------------------------*/
22 static nios_uart_t *uart = (nios_uart_t *) CONFIG_SYS_NIOS_CONSOLE;
24 #if defined(CONFIG_SYS_NIOS_FIXEDBAUD)
27 * Everything's already setup for fixed-baud PTF
30 static void altera_serial_setbrg(void)
34 static int altera_serial_init(void)
41 static void altera_serial_setbrg(void)
45 div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
46 writel (div, &uart->divisor);
49 static int altera_serial_init(void)
55 #endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
57 /*-----------------------------------------------------------------------
59 *---------------------------------------------------------------------*/
60 static void altera_serial_putc(char c)
64 while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
66 writel ((unsigned char)c, &uart->txdata);
69 static int altera_serial_tstc(void)
71 return (readl (&uart->status) & NIOS_UART_RRDY);
74 static int altera_serial_getc(void)
76 while (serial_tstc () == 0)
78 return (readl (&uart->rxdata) & 0x00ff );
81 static struct serial_device altera_serial_drv = {
82 .name = "altera_serial",
83 .start = altera_serial_init,
85 .setbrg = altera_serial_setbrg,
86 .putc = altera_serial_putc,
87 .puts = default_serial_puts,
88 .getc = altera_serial_getc,
89 .tstc = altera_serial_tstc,
92 void altera_serial_initialize(void)
94 serial_register(&altera_serial_drv);
97 __weak struct serial_device *default_serial_console(void)
99 return &altera_serial_drv;