serial.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019 Intel Corporation <www.intel.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <log.h>
  8. #include <ns16550.h>
  9. #include <serial.h>
  10. #include <asm/arch/slimbootloader.h>
  11. /**
  12. * The serial port info hob is generated by Slim Bootloader, so eligible for
  13. * Slim Bootloader based boards only.
  14. */
  15. static int slimbootloader_serial_ofdata_to_platdata(struct udevice *dev)
  16. {
  17. const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID;
  18. struct sbl_serial_port_info *data;
  19. struct ns16550_platdata *plat = dev->plat;
  20. if (!gd->arch.hob_list)
  21. panic("hob list not found!");
  22. data = hob_get_guid_hob_data(gd->arch.hob_list, NULL, &guid);
  23. if (!data) {
  24. debug("failed to get serial port information\n");
  25. return -ENOENT;
  26. }
  27. debug("type:%d base=0x%08x baudrate=%d stride=%d clk=%d\n",
  28. data->type,
  29. data->base,
  30. data->baud,
  31. data->stride,
  32. data->clk);
  33. plat->base = data->base;
  34. /* ns16550 uses reg_shift, then covert stride to shift */
  35. plat->reg_shift = data->stride >> 1;
  36. plat->reg_width = data->stride;
  37. plat->clock = data->clk;
  38. plat->fcr = UART_FCR_DEFVAL;
  39. plat->flags = 0;
  40. if (data->type == 1)
  41. plat->flags |= NS16550_FLAG_IO;
  42. return 0;
  43. }
  44. static const struct udevice_id slimbootloader_serial_ids[] = {
  45. { .compatible = "intel,slimbootloader-uart" },
  46. {}
  47. };
  48. U_BOOT_DRIVER(serial_slimbootloader) = {
  49. .name = "serial_slimbootloader",
  50. .id = UCLASS_SERIAL,
  51. .of_match = slimbootloader_serial_ids,
  52. .ofdata_to_platdata = slimbootloader_serial_ofdata_to_platdata,
  53. .plat_auto = sizeof(struct ns16550_platdata),
  54. .priv_auto = sizeof(struct NS16550),
  55. .probe = ns16550_serial_probe,
  56. .ops = &ns16550_serial_ops,
  57. };