3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
13 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
15 * SPDX-License-Identifier: GPL-2.0+
19 #include <asm/arch/ixp425.h>
22 #include <linux/compiler.h>
26 * Baud Rate = --------------
29 #define SERIAL_CLOCK 921600
31 DECLARE_GLOBAL_DATA_PTR;
33 static void ixp_serial_setbrg(void)
35 unsigned int quot = 0;
36 int uart = CONFIG_SYS_IXP425_CONSOLE;
38 if ((gd->baudrate <= SERIAL_CLOCK) && (SERIAL_CLOCK % gd->baudrate == 0))
39 quot = SERIAL_CLOCK / gd->baudrate;
43 IER(uart) = 0; /* Disable for now */
44 FCR(uart) = 0; /* No fifos enabled */
47 LCR(uart) = LCR_WLS0 | LCR_WLS1 | LCR_DLAB;
48 DLL(uart) = quot & 0xff;
49 DLH(uart) = quot >> 8;
50 LCR(uart) = LCR_WLS0 | LCR_WLS1;
51 #ifdef CONFIG_SERIAL_RTS_ACTIVE
52 MCR(uart) = MCR_RTS; /* set RTS active */
54 MCR(uart) = 0; /* set RTS inactive */
60 * Initialise the serial port with the given baudrate. The settings
61 * are always 8 data bits, no parity, 1 stop bit, no start bits.
64 static int ixp_serial_init(void)
73 * Output a single byte to the serial port.
75 static void ixp_serial_putc(const char c)
77 /* wait for room in the tx FIFO on UART */
78 while ((LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_TEMT) == 0)
79 WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */
81 THR(CONFIG_SYS_IXP425_CONSOLE) = c;
83 /* If \n, also do \r */
89 * Read a single byte from the serial port. Returns 1 on success, 0
90 * otherwise. When the function is succesfull, the character read is
91 * written into its argument c.
93 static int ixp_serial_tstc(void)
95 return LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR;
99 * Read a single byte from the serial port. Returns 1 on success, 0
100 * otherwise. When the function is succesfull, the character read is
101 * written into its argument c.
103 static int ixp_serial_getc(void)
105 while (!(LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR))
106 WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */
108 return (char) RBR(CONFIG_SYS_IXP425_CONSOLE) & 0xff;
111 static struct serial_device ixp_serial_drv = {
112 .name = "ixp_serial",
113 .start = ixp_serial_init,
115 .setbrg = ixp_serial_setbrg,
116 .putc = ixp_serial_putc,
117 .puts = default_serial_puts,
118 .getc = ixp_serial_getc,
119 .tstc = ixp_serial_tstc,
122 void ixp_serial_initialize(void)
124 serial_register(&ixp_serial_drv);
127 __weak struct serial_device *default_serial_console(void)
129 return &ixp_serial_drv;