serial.c 1.7 KB

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