early_uart.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <errno.h>
  7. #include <asm/io.h>
  8. #define PCI_DEV_CONFIG(segbus, dev, fn) ( \
  9. (((segbus) & 0xfff) << 20) | \
  10. (((dev) & 0x1f) << 15) | \
  11. (((fn) & 0x07) << 12))
  12. /* Platform Controller Unit */
  13. #define LPC_DEV 0x1f
  14. #define LPC_FUNC 0
  15. /* Enable UART */
  16. #define UART_CONT 0x80
  17. /* SCORE Pad definitions */
  18. #define UART_RXD_PAD 82
  19. #define UART_TXD_PAD 83
  20. /* Pad base: PAD_CONF0[n]= PAD_BASE + 16 * n */
  21. #define GPSCORE_PAD_BASE (IO_BASE_ADDRESS + IO_BASE_OFFSET_GPSCORE)
  22. /* IO Memory */
  23. #define IO_BASE_ADDRESS 0xfed0c000
  24. #define IO_BASE_OFFSET_GPSCORE 0x0000
  25. #define IO_BASE_OFFSET_GPNCORE 0x1000
  26. #define IO_BASE_OFFSET_GPSSUS 0x2000
  27. #define IO_BASE_SIZE 0x4000
  28. static inline unsigned int score_pconf0(int pad_num)
  29. {
  30. return GPSCORE_PAD_BASE + pad_num * 16;
  31. }
  32. static void score_select_func(int pad, int func)
  33. {
  34. uint32_t reg;
  35. uint32_t pconf0_addr = score_pconf0(pad);
  36. reg = readl(pconf0_addr);
  37. reg &= ~0x7;
  38. reg |= func & 0x7;
  39. writel(reg, pconf0_addr);
  40. }
  41. static void x86_pci_write_config32(int dev, unsigned int where, u32 value)
  42. {
  43. unsigned long addr;
  44. addr = CONFIG_PCIE_ECAM_BASE | dev | (where & ~3);
  45. writel(value, addr);
  46. }
  47. /* This can be called after memory-mapped PCI is working */
  48. int setup_internal_uart(int enable)
  49. {
  50. /* Enable or disable the legacy UART hardware */
  51. x86_pci_write_config32(PCI_DEV_CONFIG(0, LPC_DEV, LPC_FUNC), UART_CONT,
  52. enable);
  53. /* All done for the disable part, so just return */
  54. if (!enable)
  55. return 0;
  56. /*
  57. * Set up the pads to the UART function. This allows the signals to
  58. * leave the chip
  59. */
  60. score_select_func(UART_RXD_PAD, 1);
  61. score_select_func(UART_TXD_PAD, 1);
  62. /* TODO(sjg@chromium.org): Call debug_uart_init() */
  63. return 0;
  64. }
  65. void board_debug_uart_init(void)
  66. {
  67. setup_internal_uart(1);
  68. }