2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
/*
|
2007-07-06 04:17:36 +00:00
|
|
|
* (C) Copyright 2004-2007 Freescale Semiconductor, Inc.
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
* TsiChung Liew, Tsi-Chung.Liew@freescale.com.
|
|
|
|
*
|
2016-04-27 19:51:13 +00:00
|
|
|
* Modified to add device model (DM) support
|
|
|
|
* (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it>
|
2019-03-13 20:46:49 +00:00
|
|
|
*
|
|
|
|
* Modified to add DM and fdt support, removed non DM code
|
|
|
|
* (C) Copyright 2018 Angelo Dureghello <angelo@sysam.it>
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimal serial functions needed to use one of the uart ports
|
|
|
|
* as serial console interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-04-27 19:51:13 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <dm/platform_data/serial_coldfire.h>
|
2012-10-18 16:54:38 +00:00
|
|
|
#include <serial.h>
|
|
|
|
#include <linux/compiler.h>
|
2007-07-06 04:17:36 +00:00
|
|
|
#include <asm/immap.h>
|
|
|
|
#include <asm/uart.h>
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2010-03-10 01:24:43 +00:00
|
|
|
extern void uart_port_conf(int port);
|
2007-08-05 08:55:21 +00:00
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
static int mcf_serial_init_common(uart_t *uart, int port_idx, int baudrate)
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
{
|
|
|
|
u32 counter;
|
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
uart_port_conf(port_idx);
|
2007-08-05 08:55:21 +00:00
|
|
|
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
/* write to SICR: SIM2 = uart mode,dcd does not affect rx */
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb(UART_UCR_RESET_RX, &uart->ucr);
|
|
|
|
writeb(UART_UCR_RESET_TX, &uart->ucr);
|
|
|
|
writeb(UART_UCR_RESET_ERROR, &uart->ucr);
|
|
|
|
writeb(UART_UCR_RESET_MR, &uart->ucr);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
__asm__("nop");
|
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb(0, &uart->uimr);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
|
|
|
/* write to CSR: RX/TX baud rate from timers */
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb(UART_UCSR_RCS_SYS_CLK | UART_UCSR_TCS_SYS_CLK, &uart->ucsr);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb(UART_UMR_BC_8 | UART_UMR_PM_NONE, &uart->umr);
|
|
|
|
writeb(UART_UMR_SB_STOP_BITS_1, &uart->umr);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
|
|
|
/* Setting up BaudRate */
|
2016-04-27 19:51:13 +00:00
|
|
|
counter = (u32) ((gd->bus_clk / 32) + (baudrate / 2));
|
|
|
|
counter = counter / baudrate;
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
|
|
|
/* write to CTUR: divide counter upper byte */
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb((u8)((counter & 0xff00) >> 8), &uart->ubg1);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
/* write to CTLR: divide counter lower byte */
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb((u8)(counter & 0x00ff), &uart->ubg2);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
|
Added M5329AFEE and M5329BFEE Platforms
Added board/freescale/m5329evb, cpu/mcf532x, drivers/net,
drivers/serial, immap_5329.h, m5329.h, mcfrtc.h,
include/configs/M5329EVB.h, lib_m68k/interrupts.c, and
rtc/mcfrtc.c
Modified CREDITS, MAKEFILE, Makefile, README, common/cmd_bdinfo.c,
common/cmd_mii.c, include/asm-m68k/byteorder.h, include/asm-m68k/fec.h,
include/asm-m68k/io.h, include/asm-m68k/mcftimer.h,
include/asm-m68k/mcfuart.h, include/asm-m68k/ptrace.h,
include/asm-m68k/u-boot.h, lib_m68k/Makefile, lib_m68k/board.c,
lib_m68k/time.c, net/eth.c and rtc/Makefile
Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
2007-06-18 18:50:13 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
static void mcf_serial_setbrg_common(uart_t *uart, int baudrate)
|
|
|
|
{
|
|
|
|
u32 counter;
|
|
|
|
|
|
|
|
/* Setting up BaudRate */
|
|
|
|
counter = (u32) ((gd->bus_clk / 32) + (baudrate / 2));
|
|
|
|
counter = counter / baudrate;
|
|
|
|
|
|
|
|
/* write to CTUR: divide counter upper byte */
|
|
|
|
writeb(((counter & 0xff00) >> 8), &uart->ubg1);
|
|
|
|
/* write to CTLR: divide counter lower byte */
|
|
|
|
writeb((counter & 0x00ff), &uart->ubg2);
|
|
|
|
|
|
|
|
writeb(UART_UCR_RESET_RX, &uart->ucr);
|
|
|
|
writeb(UART_UCR_RESET_TX, &uart->ucr);
|
|
|
|
|
|
|
|
writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coldfire_serial_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev->platdata;
|
|
|
|
|
|
|
|
return mcf_serial_init_common((uart_t *)plat->base,
|
|
|
|
plat->port, plat->baudrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coldfire_serial_putc(struct udevice *dev, const char ch)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev->platdata;
|
|
|
|
uart_t *uart = (uart_t *)plat->base;
|
|
|
|
|
|
|
|
/* Wait for last character to go. */
|
|
|
|
if (!(readb(&uart->usr) & UART_USR_TXRDY))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
writeb(ch, &uart->utb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coldfire_serial_getc(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev->platdata;
|
|
|
|
uart_t *uart = (uart_t *)(plat->base);
|
|
|
|
|
|
|
|
/* Wait for a character to arrive. */
|
|
|
|
if (!(readb(&uart->usr) & UART_USR_RXRDY))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
return readb(&uart->urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
int coldfire_serial_setbrg(struct udevice *dev, int baudrate)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev->platdata;
|
|
|
|
uart_t *uart = (uart_t *)(plat->base);
|
|
|
|
|
|
|
|
mcf_serial_setbrg_common(uart, baudrate);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coldfire_serial_pending(struct udevice *dev, bool input)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev->platdata;
|
|
|
|
uart_t *uart = (uart_t *)(plat->base);
|
|
|
|
|
|
|
|
if (input)
|
|
|
|
return readb(&uart->usr) & UART_USR_RXRDY ? 1 : 0;
|
|
|
|
else
|
|
|
|
return readb(&uart->usr) & UART_USR_TXRDY ? 0 : 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-13 20:46:49 +00:00
|
|
|
static int coldfire_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct coldfire_serial_platdata *plat = dev_get_platdata(dev);
|
|
|
|
fdt_addr_t addr_base;
|
|
|
|
|
|
|
|
addr_base = devfdt_get_addr(dev);
|
|
|
|
if (addr_base == FDT_ADDR_T_NONE)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
plat->base = (uint32_t)addr_base;
|
|
|
|
|
|
|
|
plat->port = dev->seq;
|
|
|
|
plat->baudrate = gd->baudrate;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
static const struct dm_serial_ops coldfire_serial_ops = {
|
|
|
|
.putc = coldfire_serial_putc,
|
|
|
|
.pending = coldfire_serial_pending,
|
|
|
|
.getc = coldfire_serial_getc,
|
|
|
|
.setbrg = coldfire_serial_setbrg,
|
|
|
|
};
|
|
|
|
|
2019-03-13 20:46:49 +00:00
|
|
|
static const struct udevice_id coldfire_serial_ids[] = {
|
|
|
|
{ .compatible = "fsl,mcf-uart" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2016-04-27 19:51:13 +00:00
|
|
|
U_BOOT_DRIVER(serial_coldfire) = {
|
|
|
|
.name = "serial_coldfire",
|
|
|
|
.id = UCLASS_SERIAL,
|
2019-03-13 20:46:49 +00:00
|
|
|
.of_match = coldfire_serial_ids,
|
|
|
|
.ofdata_to_platdata = coldfire_ofdata_to_platdata,
|
|
|
|
.platdata_auto_alloc_size = sizeof(struct coldfire_serial_platdata),
|
2016-04-27 19:51:13 +00:00
|
|
|
.probe = coldfire_serial_probe,
|
|
|
|
.ops = &coldfire_serial_ops,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|