Merge branch 'master' of https://gitlab.denx.de/u-boot/custodians/u-boot-spi
[oweals/u-boot.git] / drivers / serial / serial_coreboot.c
index 5c6a76c59c0af23bd482434464d2428f827c2c48..ccab347514cfb6a483431b16512dc2d6ec3d367e 100644 (file)
@@ -1,38 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (c) 2014 Google, Inc
+ * UART support for U-Boot when launched from Coreboot
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright 2019 Google LLC
  */
 
 #include <common.h>
 #include <dm.h>
 #include <ns16550.h>
 #include <serial.h>
+#include <asm/arch/sysinfo.h>
 
-static const struct udevice_id coreboot_serial_ids[] = {
-       { .compatible = "coreboot-uart" },
-       { }
-};
-
-static int coreboot_serial_ofdata_to_platdata(struct udevice *dev)
+static int coreboot_ofdata_to_platdata(struct udevice *dev)
 {
        struct ns16550_platdata *plat = dev_get_platdata(dev);
-       int ret;
+       struct cb_serial *cb_info = lib_sysinfo.serial;
 
-       ret = ns16550_serial_ofdata_to_platdata(dev);
-       if (ret)
-               return ret;
-       plat->clock = 1843200;
+       plat->base = cb_info->baseaddr;
+       plat->reg_shift = cb_info->regwidth == 4 ? 2 : 0;
+       plat->reg_width = cb_info->regwidth;
+       plat->clock = cb_info->input_hertz;
+       plat->fcr = UART_FCR_DEFVAL;
+       plat->flags = 0;
+       if (cb_info->type == CB_SERIAL_TYPE_IO_MAPPED)
+               plat->flags |= NS16550_FLAG_IO;
 
        return 0;
 }
-U_BOOT_DRIVER(serial_ns16550) = {
-       .name   = "serial_coreboot",
+
+static const struct udevice_id coreboot_serial_ids[] = {
+       { .compatible = "coreboot-serial" },
+       { },
+};
+
+U_BOOT_DRIVER(coreboot_uart) = {
+       .name   = "coreboot_uart",
        .id     = UCLASS_SERIAL,
-       .of_match = coreboot_serial_ids,
-       .ofdata_to_platdata = coreboot_serial_ofdata_to_platdata,
-       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .of_match       = coreboot_serial_ids,
        .priv_auto_alloc_size = sizeof(struct NS16550),
-       .probe = ns16550_serial_probe,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .ofdata_to_platdata  = coreboot_ofdata_to_platdata,
+       .probe  = ns16550_serial_probe,
        .ops    = &ns16550_serial_ops,
+       .flags  = DM_FLAG_PRE_RELOC,
 };