serial_intel_mid.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2017 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <ns16550.h>
  9. #include <serial.h>
  10. /*
  11. * The UART clock is calculated as
  12. *
  13. * UART clock = XTAL * UART_MUL / UART_DIV
  14. *
  15. * The baudrate is calculated as
  16. *
  17. * baud rate = UART clock / UART_PS / DLAB
  18. */
  19. #define UART_PS 0x30
  20. #define UART_MUL 0x34
  21. #define UART_DIV 0x38
  22. static void mid_writel(struct ns16550_platdata *plat, int offset, int value)
  23. {
  24. unsigned char *addr;
  25. offset *= 1 << plat->reg_shift;
  26. addr = (unsigned char *)plat->base + offset;
  27. writel(value, addr + plat->reg_offset);
  28. }
  29. static int mid_serial_probe(struct udevice *dev)
  30. {
  31. struct ns16550_platdata *plat = dev_get_platdata(dev);
  32. /*
  33. * Initialize fractional divider correctly for Intel Edison
  34. * platform.
  35. *
  36. * For backward compatibility we have to set initial DLAB value
  37. * to 16 and speed to 115200 baud, where initial frequency is
  38. * 29491200Hz, and XTAL frequency is 38.4MHz.
  39. */
  40. mid_writel(plat, UART_MUL, 96);
  41. mid_writel(plat, UART_DIV, 125);
  42. mid_writel(plat, UART_PS, 16);
  43. return ns16550_serial_probe(dev);
  44. }
  45. static const struct udevice_id mid_serial_ids[] = {
  46. { .compatible = "intel,mid-uart" },
  47. {}
  48. };
  49. U_BOOT_DRIVER(serial_intel_mid) = {
  50. .name = "serial_intel_mid",
  51. .id = UCLASS_SERIAL,
  52. .of_match = mid_serial_ids,
  53. .ofdata_to_platdata = ns16550_serial_ofdata_to_platdata,
  54. .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
  55. .priv_auto_alloc_size = sizeof(struct NS16550),
  56. .probe = mid_serial_probe,
  57. .ops = &ns16550_serial_ops,
  58. .flags = DM_FLAG_PRE_RELOC,
  59. };