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+
21 #include <linux/compiler.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 static void sa1100_serial_setbrg(void)
29 if (gd->baudrate == 1200)
31 else if (gd->baudrate == 9600)
33 else if (gd->baudrate == 19200)
35 else if (gd->baudrate == 38400)
37 else if (gd->baudrate == 57600)
39 else if (gd->baudrate == 115200)
45 /* SA1110 uart function */
46 Ser1SDCR0 |= SDCR0_SUS;
48 /* Wait until port is ready ... */
49 while(Ser1UTSR1 & UTSR1_TBY) {}
51 /* init serial serial 1 */
54 Ser1UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData );
57 Ser1UTCR3 = ( UTCR3_RXE | UTCR3_TXE );
58 #elif defined(CONFIG_SERIAL3)
59 /* Wait until port is ready ... */
60 while (Ser3UTSR1 & UTSR1_TBY) {
63 /* init serial serial 3 */
66 Ser3UTCR0 = (UTCR0_1StpBit | UTCR0_8BitData);
68 Ser3UTCR2 = (u32) reg;
69 Ser3UTCR3 = (UTCR3_RXE | UTCR3_TXE);
71 #error "Bad: you didn't configured serial ..."
77 * Initialise the serial port with the given baudrate. The settings
78 * are always 8 data bits, no parity, 1 stop bit, no start bits.
81 static int sa1100_serial_init(void)
90 * Output a single byte to the serial port.
92 static void sa1100_serial_putc(const char c)
95 /* wait for room in the tx FIFO on SERIAL1 */
96 while ((Ser1UTSR0 & UTSR0_TFS) == 0);
99 #elif defined(CONFIG_SERIAL3)
100 /* wait for room in the tx FIFO on SERIAL3 */
101 while ((Ser3UTSR0 & UTSR0_TFS) == 0);
106 /* If \n, also do \r */
112 * Read a single byte from the serial port. Returns 1 on success, 0
113 * otherwise. When the function is succesfull, the character read is
114 * written into its argument c.
116 static int sa1100_serial_tstc(void)
118 #ifdef CONFIG_SERIAL1
119 return Ser1UTSR1 & UTSR1_RNE;
120 #elif defined(CONFIG_SERIAL3)
121 return Ser3UTSR1 & UTSR1_RNE;
126 * Read a single byte from the serial port. Returns 1 on success, 0
127 * otherwise. When the function is succesfull, the character read is
128 * written into its argument c.
130 static int sa1100_serial_getc(void)
132 #ifdef CONFIG_SERIAL1
133 while (!(Ser1UTSR1 & UTSR1_RNE));
135 return (char) Ser1UTDR & 0xff;
136 #elif defined(CONFIG_SERIAL3)
137 while (!(Ser3UTSR1 & UTSR1_RNE));
139 return (char) Ser3UTDR & 0xff;
143 static struct serial_device sa1100_serial_drv = {
144 .name = "sa1100_serial",
145 .start = sa1100_serial_init,
147 .setbrg = sa1100_serial_setbrg,
148 .putc = sa1100_serial_putc,
149 .puts = default_serial_puts,
150 .getc = sa1100_serial_getc,
151 .tstc = sa1100_serial_tstc,
154 void sa1100_serial_initialize(void)
156 serial_register(&sa1100_serial_drv);
159 __weak struct serial_device *default_serial_console(void)
161 return &sa1100_serial_drv;