X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fserial%2Fmcfuart.c;h=407354fc4cdf2acac18fee8d014e4d92f63078f3;hb=876d4515e38dfcec4346968caf6a0c9c8176ea0b;hp=bc7077de79e5d0d82c71a496e0d7bf5aa93d135d;hpb=81735b2568cf634d601c0d4a1bbc3a3882bc8eda;p=u-boot diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c index bc7077de79..407354fc4c 100644 --- a/drivers/serial/mcfuart.c +++ b/drivers/serial/mcfuart.c @@ -2,24 +2,7 @@ * (C) Copyright 2004-2007 Freescale Semiconductor, Inc. * TsiChung Liew, Tsi-Chung.Liew@freescale.com. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -28,22 +11,24 @@ */ #include +#include +#include + #include #include DECLARE_GLOBAL_DATA_PTR; -#ifdef CONFIG_MCFUART -extern void uart_port_conf(void); +extern void uart_port_conf(int port); -int serial_init(void) +static int mcf_serial_init(void) { volatile uart_t *uart; u32 counter; - uart = (volatile uart_t *)(CFG_UART_BASE); + uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE); - uart_port_conf(); + uart_port_conf(CONFIG_SYS_UART_PORT); /* write to SICR: SIM2 = uart mode,dcd does not affect rx */ uart->ucr = UART_UCR_RESET_RX; @@ -61,8 +46,8 @@ int serial_init(void) uart->umr = UART_UMR_SB_STOP_BITS_1; /* Setting up BaudRate */ - counter = (u32) (gd->bus_clk / (gd->baudrate)); - counter >>= 5; + counter = (u32) ((gd->bus_clk / 32) + (gd->baudrate / 2)); + counter = counter / gd->baudrate; /* write to CTUR: divide counter upper byte */ uart->ubg1 = (u8) ((counter & 0xff00) >> 8); @@ -74,9 +59,9 @@ int serial_init(void) return (0); } -void serial_putc(const char c) +static void mcf_serial_putc(const char c) { - volatile uart_t *uart = (volatile uart_t *)(CFG_UART_BASE); + volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE); if (c == '\n') serial_putc('\r'); @@ -87,36 +72,30 @@ void serial_putc(const char c) uart->utb = c; } -void serial_puts(const char *s) -{ - while (*s) { - serial_putc(*s++); - } -} - -int serial_getc(void) +static int mcf_serial_getc(void) { - volatile uart_t *uart = (volatile uart_t *)(CFG_UART_BASE); + volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE); /* Wait for a character to arrive. */ while (!(uart->usr & UART_USR_RXRDY)) ; return uart->urb; } -int serial_tstc(void) +static int mcf_serial_tstc(void) { - volatile uart_t *uart = (volatile uart_t *)(CFG_UART_BASE); + volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE); return (uart->usr & UART_USR_RXRDY); } -void serial_setbrg(void) +static void mcf_serial_setbrg(void) { - volatile uart_t *uart = (volatile uart_t *)(CFG_UART_BASE); + volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE); u32 counter; - counter = ((gd->bus_clk / gd->baudrate)) >> 5; - counter++; + /* Setting up BaudRate */ + counter = (u32) ((gd->bus_clk / 32) + (gd->baudrate / 2)); + counter = counter / gd->baudrate; /* write to CTUR: divide counter upper byte */ uart->ubg1 = ((counter & 0xff00) >> 8); @@ -128,4 +107,24 @@ void serial_setbrg(void) uart->ucr = UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED; } -#endif /* CONFIG_MCFUART */ + +static struct serial_device mcf_serial_drv = { + .name = "mcf_serial", + .start = mcf_serial_init, + .stop = NULL, + .setbrg = mcf_serial_setbrg, + .putc = mcf_serial_putc, + .puts = default_serial_puts, + .getc = mcf_serial_getc, + .tstc = mcf_serial_tstc, +}; + +void mcf_serial_initialize(void) +{ + serial_register(&mcf_serial_drv); +} + +__weak struct serial_device *default_serial_console(void) +{ + return &mcf_serial_drv; +}