aboutsummaryrefslogtreecommitdiff
path: root/drivers/serial/serial_intel_mid.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2017-02-28 14:04:10 +0200
committerBin Meng <bmeng.cn@gmail.com>2017-04-10 10:02:03 +0800
commitc5f8dd482b4178cda30be7355085a70521cd4813 (patch)
tree78a3baf00ff94a03e6bf4053a0449eb484fa31dd /drivers/serial/serial_intel_mid.c
parentae5564d1aec8b39f55f283f8d187b7b1603533bf (diff)
downloadu-boot-c5f8dd482b4178cda30be7355085a70521cd4813.zip
u-boot-c5f8dd482b4178cda30be7355085a70521cd4813.tar.gz
u-boot-c5f8dd482b4178cda30be7355085a70521cd4813.tar.bz2
serial: Add serial driver for Intel MID
Add a specific serial driver for Intel MID platforms. It has special fractional divider which can be programmed via UART_PS, UART_MUL, and UART_DIV registers. 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 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. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Diffstat (limited to 'drivers/serial/serial_intel_mid.c')
-rw-r--r--drivers/serial/serial_intel_mid.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/serial/serial_intel_mid.c b/drivers/serial/serial_intel_mid.c
new file mode 100644
index 0000000..777c09d
--- /dev/null
+++ b/drivers/serial/serial_intel_mid.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#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
+
+static void mid_writel(struct ns16550_platdata *plat, int offset, int value)
+{
+ 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)
+{
+ struct ns16550_platdata *plat = dev_get_platdata(dev);
+
+ /*
+ * 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,
+ .ofdata_to_platdata = ns16550_serial_ofdata_to_platdata,
+ .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+ .priv_auto_alloc_size = sizeof(struct NS16550),
+ .probe = mid_serial_probe,
+ .ops = &ns16550_serial_ops,
+ .flags = DM_FLAG_PRE_RELOC,
+};