2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-28 12:04:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <ns16550.h>
|
|
|
|
#include <serial.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The UART clock is calculated as
|
|
|
|
*
|
|
|
|
* UART clock = XTAL * UART_MUL / UART_DIV
|
|
|
|
*
|
|
|
|
* The baudrate is calculated as
|
|
|
|
*
|
|
|
|
* baud rate = UART clock / UART_PS / DLAB
|
|
|
|
*/
|
|
|
|
#define UART_PS 0x30
|
|
|
|
#define UART_MUL 0x34
|
|
|
|
#define UART_DIV 0x38
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
static void mid_writel(struct ns16550_plat *plat, int offset, int value)
|
2017-02-28 12:04:10 +00:00
|
|
|
{
|
|
|
|
unsigned char *addr;
|
|
|
|
|
|
|
|
offset *= 1 << plat->reg_shift;
|
|
|
|
addr = (unsigned char *)plat->base + offset;
|
|
|
|
|
|
|
|
writel(value, addr + plat->reg_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mid_serial_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct ns16550_plat *plat = dev_get_plat(dev);
|
2017-02-28 12:04:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize fractional divider correctly for Intel Edison
|
|
|
|
* platform.
|
|
|
|
*
|
|
|
|
* For backward compatibility we have to set initial DLAB value
|
|
|
|
* to 16 and speed to 115200 baud, where initial frequency is
|
|
|
|
* 29491200Hz, and XTAL frequency is 38.4MHz.
|
|
|
|
*/
|
|
|
|
mid_writel(plat, UART_MUL, 96);
|
|
|
|
mid_writel(plat, UART_DIV, 125);
|
|
|
|
mid_writel(plat, UART_PS, 16);
|
|
|
|
|
|
|
|
return ns16550_serial_probe(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id mid_serial_ids[] = {
|
|
|
|
{ .compatible = "intel,mid-uart" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(serial_intel_mid) = {
|
|
|
|
.name = "serial_intel_mid",
|
|
|
|
.id = UCLASS_SERIAL,
|
|
|
|
.of_match = mid_serial_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = ns16550_serial_of_to_plat,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct ns16550_plat),
|
2020-12-23 02:30:18 +00:00
|
|
|
.priv_auto = sizeof(struct ns16550),
|
2017-02-28 12:04:10 +00:00
|
|
|
.probe = mid_serial_probe,
|
|
|
|
.ops = &ns16550_serial_ops,
|
|
|
|
};
|