]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/serial/serial_ixp.c
ARM: NET: Remove the IXP NPE ethernet driver
[people/ms/u-boot.git] / drivers / serial / serial_ixp.c
CommitLineData
2d5b561e
WD
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 *
1a459660 15 * SPDX-License-Identifier: GPL-2.0+
2d5b561e
WD
16 */
17
18#include <common.h>
19#include <asm/arch/ixp425.h>
009e4648 20#include <watchdog.h>
b6cd0fef
MV
21#include <serial.h>
22#include <linux/compiler.h>
2d5b561e 23
7b74ebe7
JCPV
24/*
25 * 14.7456 MHz
26 * Baud Rate = --------------
27 * 16 x Divisor
28 */
07eb0268 29#define SERIAL_CLOCK 921600
7b74ebe7 30
d87080b7
WD
31DECLARE_GLOBAL_DATA_PTR;
32
b6cd0fef 33static void ixp_serial_setbrg(void)
2d5b561e 34{
2d5b561e 35 unsigned int quot = 0;
6d0f6bcf 36 int uart = CONFIG_SYS_IXP425_CONSOLE;
07eb0268 37
7b74ebe7
JCPV
38 if ((gd->baudrate <= SERIAL_CLOCK) && (SERIAL_CLOCK % gd->baudrate == 0))
39 quot = SERIAL_CLOCK / gd->baudrate;
2d5b561e
WD
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;
96bd4629
MS
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
2d5b561e
WD
56 IER(uart) = IER_UUE;
57}
58
2d5b561e
WD
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 */
b6cd0fef 64static int ixp_serial_init(void)
2d5b561e
WD
65{
66 serial_setbrg ();
67
68 return (0);
69}
70
71
72/*
73 * Output a single byte to the serial port.
74 */
b6cd0fef 75static void ixp_serial_putc(const char c)
2d5b561e
WD
76{
77 /* wait for room in the tx FIFO on UART */
009e4648
MS
78 while ((LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_TEMT) == 0)
79 WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */
2d5b561e 80
6d0f6bcf 81 THR(CONFIG_SYS_IXP425_CONSOLE) = c;
2d5b561e
WD
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 */
b6cd0fef 93static int ixp_serial_tstc(void)
2d5b561e 94{
6d0f6bcf 95 return LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR;
2d5b561e
WD
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 */
b6cd0fef 103static int ixp_serial_getc(void)
2d5b561e 104{
009e4648
MS
105 while (!(LSR(CONFIG_SYS_IXP425_CONSOLE) & LSR_DR))
106 WATCHDOG_RESET(); /* Reset HW Watchdog, if needed */
2d5b561e 107
6d0f6bcf 108 return (char) RBR(CONFIG_SYS_IXP425_CONSOLE) & 0xff;
2d5b561e
WD
109}
110
b6cd0fef
MV
111static 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,
ec3fd689 117 .puts = default_serial_puts,
b6cd0fef
MV
118 .getc = ixp_serial_getc,
119 .tstc = ixp_serial_tstc,
120};
121
122void 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}