]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/serial/serial_ixp.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / drivers / serial / serial_ixp.c
1 /*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4 *
5 * (C) Copyright 2002
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
8 *
9 * (C) Copyright 2002
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
12 *
13 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
14 *
15 * SPDX-License-Identifier: GPL-2.0+
16 */
17
18 #include <common.h>
19 #include <asm/arch/ixp425.h>
20 #include <watchdog.h>
21 #include <serial.h>
22 #include <linux/compiler.h>
23
24 /*
25 * 14.7456 MHz
26 * Baud Rate = --------------
27 * 16 x Divisor
28 */
29 #define SERIAL_CLOCK 921600
30
31 DECLARE_GLOBAL_DATA_PTR;
32
33 static void ixp_serial_setbrg(void)
34 {
35 unsigned int quot = 0;
36 int uart = CONFIG_SYS_IXP425_CONSOLE;
37
38 if ((gd->baudrate <= SERIAL_CLOCK) && (SERIAL_CLOCK % gd->baudrate == 0))
39 quot = SERIAL_CLOCK / gd->baudrate;
40 else
41 hang ();
42
43 IER(uart) = 0; /* Disable for now */
44 FCR(uart) = 0; /* No fifos enabled */
45
46 /* set baud rate */
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 */
53 #else
54 MCR(uart) = 0; /* set RTS inactive */
55 #endif
56 IER(uart) = IER_UUE;
57 }
58
59 /*
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.
62 *
63 */
64 static int ixp_serial_init(void)
65 {
66 serial_setbrg ();
67
68 return (0);
69 }
70
71
72 /*
73 * Output a single byte to the serial port.
74 */
75 static void ixp_serial_putc(const char c)
76 {
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 */
80
81 THR(CONFIG_SYS_IXP425_CONSOLE) = c;
82
83 /* If \n, also do \r */
84 if (c == '\n')
85 serial_putc ('\r');
86 }
87
88 /*
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.
92 */
93 static int ixp_serial_tstc(void)
94 {
95 return LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR;
96 }
97
98 /*
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.
102 */
103 static int ixp_serial_getc(void)
104 {
105 while (!(LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR))
106 WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */
107
108 return (char) RBR(CONFIG_SYS_IXP425_CONSOLE) & 0xff;
109 }
110
111 static struct serial_device ixp_serial_drv = {
112 .name = "ixp_serial",
113 .start = ixp_serial_init,
114 .stop = NULL,
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,
120 };
121
122 void ixp_serial_initialize(void)
123 {
124 serial_register(&ixp_serial_drv);
125 }
126
127 __weak struct serial_device *default_serial_console(void)
128 {
129 return &ixp_serial_drv;
130 }