lpc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2016 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <fdtdec.h>
  10. #include <pch.h>
  11. #include <pci.h>
  12. #include <asm/intel_regs.h>
  13. #include <asm/io.h>
  14. #include <asm/lpc_common.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /* Enable Prefetching and Caching */
  17. static void enable_spi_prefetch(struct udevice *pch)
  18. {
  19. u8 reg8;
  20. dm_pci_read_config8(pch, 0xdc, &reg8);
  21. reg8 &= ~(3 << 2);
  22. reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
  23. dm_pci_write_config8(pch, 0xdc, reg8);
  24. }
  25. static void enable_port80_on_lpc(struct udevice *pch)
  26. {
  27. /* Enable port 80 POST on LPC */
  28. dm_pci_write_config32(pch, PCH_RCBA_BASE, RCB_BASE_ADDRESS | 1);
  29. clrbits_le32(RCB_REG(GCS), 4);
  30. }
  31. /**
  32. * lpc_early_init() - set up LPC serial ports and other early things
  33. *
  34. * @dev: LPC device
  35. * @return 0 if OK, -ve on error
  36. */
  37. int lpc_common_early_init(struct udevice *dev)
  38. {
  39. struct udevice *pch = dev->parent;
  40. struct reg_info {
  41. u32 base;
  42. u32 size;
  43. } values[4], *ptr;
  44. int count;
  45. int i;
  46. count = fdtdec_get_int_array_count(gd->fdt_blob, dev_of_offset(dev),
  47. "intel,gen-dec", (u32 *)values,
  48. sizeof(values) / sizeof(u32));
  49. if (count < 0)
  50. return -EINVAL;
  51. /* Set COM1/COM2 decode range */
  52. dm_pci_write_config16(pch, LPC_IO_DEC, 0x0010);
  53. /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
  54. dm_pci_write_config16(pch, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
  55. GAMEL_LPC_EN | COMA_LPC_EN);
  56. /* Write all registers but use 0 if we run out of data */
  57. count = count * sizeof(u32) / sizeof(values[0]);
  58. for (i = 0, ptr = values; i < ARRAY_SIZE(values); i++, ptr++) {
  59. u32 reg = 0;
  60. if (i < count)
  61. reg = ptr->base | PCI_COMMAND_IO | (ptr->size << 16);
  62. dm_pci_write_config32(pch, LPC_GENX_DEC(i), reg);
  63. }
  64. enable_spi_prefetch(pch);
  65. /* This is already done in start.S, but let's do it in C */
  66. enable_port80_on_lpc(pch);
  67. return 0;
  68. }
  69. int lpc_set_spi_protect(struct udevice *dev, int bios_ctrl, bool protect)
  70. {
  71. uint8_t bios_cntl;
  72. /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */
  73. dm_pci_read_config8(dev, bios_ctrl, &bios_cntl);
  74. if (protect) {
  75. bios_cntl &= ~BIOS_CTRL_BIOSWE;
  76. bios_cntl |= BIT(5);
  77. } else {
  78. bios_cntl |= BIOS_CTRL_BIOSWE;
  79. bios_cntl &= ~BIT(5);
  80. }
  81. dm_pci_write_config8(dev, bios_ctrl, bios_cntl);
  82. return 0;
  83. }