early_uart.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #define PCI_DEV_CONFIG(segbus, dev, fn) ( \
  8. (((segbus) & 0xfff) << 20) | \
  9. (((dev) & 0x1f) << 15) | \
  10. (((fn) & 0x07) << 12))
  11. /* Platform Controller Unit */
  12. #define LPC_DEV 0x1f
  13. #define LPC_FUNC 0
  14. /* Enable UART */
  15. #define UART_CONT 0x80
  16. /* UART PAD definitions */
  17. #define UART_RXD_COMMUITY 1
  18. #define UART_TXD_COMMUITY 1
  19. #define UART_RXD_FAMILY 4
  20. #define UART_TXD_FAMILY 4
  21. #define UART_RXD_PAD 2
  22. #define UART_TXD_PAD 7
  23. #define UART_RXD_FUNC 3
  24. #define UART_TXD_FUNC 3
  25. /* IO Memory */
  26. #define IO_BASE_ADDRESS 0xfed80000
  27. static inline uint32_t gpio_pconf0(int community, int family, int pad)
  28. {
  29. return IO_BASE_ADDRESS + community * 0x8000 + 0x4400 +
  30. family * 0x400 + pad * 8;
  31. }
  32. static void gpio_select_func(int community, int family, int pad, int func)
  33. {
  34. uint32_t pconf0_addr = gpio_pconf0(community, family, pad);
  35. clrsetbits_le32(pconf0_addr, 0xf << 16, func << 16);
  36. }
  37. static void x86_pci_write_config32(int dev, unsigned int where, u32 value)
  38. {
  39. unsigned long addr;
  40. addr = CONFIG_PCIE_ECAM_BASE | dev | (where & ~3);
  41. writel(value, addr);
  42. }
  43. /* This can be called after memory-mapped PCI is working */
  44. int setup_internal_uart(int enable)
  45. {
  46. /* Enable or disable the legacy UART hardware */
  47. x86_pci_write_config32(PCI_DEV_CONFIG(0, LPC_DEV, LPC_FUNC), UART_CONT,
  48. enable);
  49. /* All done for the disable part, so just return */
  50. if (!enable)
  51. return 0;
  52. /*
  53. * Set up the pads to the UART function. This allows the signals to
  54. * leave the chip
  55. */
  56. gpio_select_func(UART_RXD_COMMUITY, UART_RXD_FAMILY,
  57. UART_RXD_PAD, UART_RXD_FUNC);
  58. gpio_select_func(UART_TXD_COMMUITY, UART_TXD_FAMILY,
  59. UART_TXD_PAD, UART_TXD_FUNC);
  60. return 0;
  61. }
  62. void board_debug_uart_init(void)
  63. {
  64. setup_internal_uart(1);
  65. }