serial_coreboot.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * UART support for U-Boot when launched from Coreboot
  4. *
  5. * Copyright 2019 Google LLC
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <ns16550.h>
  10. #include <serial.h>
  11. #include <asm/arch/sysinfo.h>
  12. static int coreboot_ofdata_to_platdata(struct udevice *dev)
  13. {
  14. struct ns16550_platdata *plat = dev_get_platdata(dev);
  15. struct cb_serial *cb_info = lib_sysinfo.serial;
  16. plat->base = cb_info->baseaddr;
  17. plat->reg_shift = cb_info->regwidth == 4 ? 2 : 0;
  18. plat->reg_width = cb_info->regwidth;
  19. plat->clock = cb_info->input_hertz;
  20. plat->fcr = UART_FCR_DEFVAL;
  21. plat->flags = 0;
  22. if (cb_info->type == CB_SERIAL_TYPE_IO_MAPPED)
  23. plat->flags |= NS16550_FLAG_IO;
  24. return 0;
  25. }
  26. static const struct udevice_id coreboot_serial_ids[] = {
  27. { .compatible = "coreboot-serial" },
  28. { },
  29. };
  30. U_BOOT_DRIVER(coreboot_uart) = {
  31. .name = "coreboot_uart",
  32. .id = UCLASS_SERIAL,
  33. .of_match = coreboot_serial_ids,
  34. .priv_auto_alloc_size = sizeof(struct NS16550),
  35. .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
  36. .ofdata_to_platdata = coreboot_ofdata_to_platdata,
  37. .probe = ns16550_serial_probe,
  38. .ops = &ns16550_serial_ops,
  39. .flags = DM_FLAG_PRE_RELOC,
  40. };