power_state.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * From coreboot src/soc/intel/broadwell/romstage/power_state.c
  4. *
  5. * Copyright (C) 2016 Google, Inc.
  6. */
  7. #include <common.h>
  8. #include <pci.h>
  9. #include <asm/io.h>
  10. #include <asm/intel_regs.h>
  11. #include <asm/arch/iomap.h>
  12. #include <asm/arch/lpc.h>
  13. #include <asm/arch/pch.h>
  14. #include <asm/arch/pm.h>
  15. /* Return 0, 3, or 5 to indicate the previous sleep state. */
  16. static int prev_sleep_state(struct chipset_power_state *ps)
  17. {
  18. /* Default to S0. */
  19. int prev_sleep_state = SLEEP_STATE_S0;
  20. if (ps->pm1_sts & WAK_STS) {
  21. switch ((ps->pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
  22. #if CONFIG_HAVE_ACPI_RESUME
  23. case SLP_TYP_S3:
  24. prev_sleep_state = SLEEP_STATE_S3;
  25. break;
  26. #endif
  27. case SLP_TYP_S5:
  28. prev_sleep_state = SLEEP_STATE_S5;
  29. break;
  30. }
  31. /* Clear SLP_TYP. */
  32. outl(ps->pm1_cnt & ~(SLP_TYP), ACPI_BASE_ADDRESS + PM1_CNT);
  33. }
  34. if (ps->gen_pmcon3 & (PWR_FLR | SUS_PWR_FLR))
  35. prev_sleep_state = SLEEP_STATE_S5;
  36. return prev_sleep_state;
  37. }
  38. static void dump_power_state(struct chipset_power_state *ps)
  39. {
  40. debug("PM1_STS: %04x\n", ps->pm1_sts);
  41. debug("PM1_EN: %04x\n", ps->pm1_en);
  42. debug("PM1_CNT: %08x\n", ps->pm1_cnt);
  43. debug("TCO_STS: %04x %04x\n", ps->tco1_sts, ps->tco2_sts);
  44. debug("GPE0_STS: %08x %08x %08x %08x\n",
  45. ps->gpe0_sts[0], ps->gpe0_sts[1],
  46. ps->gpe0_sts[2], ps->gpe0_sts[3]);
  47. debug("GPE0_EN: %08x %08x %08x %08x\n",
  48. ps->gpe0_en[0], ps->gpe0_en[1],
  49. ps->gpe0_en[2], ps->gpe0_en[3]);
  50. debug("GEN_PMCON: %04x %04x %04x\n",
  51. ps->gen_pmcon1, ps->gen_pmcon2, ps->gen_pmcon3);
  52. debug("Previous Sleep State: S%d\n",
  53. ps->prev_sleep_state);
  54. }
  55. /* Fill power state structure from ACPI PM registers */
  56. void power_state_get(struct udevice *pch_dev, struct chipset_power_state *ps)
  57. {
  58. ps->pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS);
  59. ps->pm1_en = inw(ACPI_BASE_ADDRESS + PM1_EN);
  60. ps->pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
  61. ps->tco1_sts = inw(ACPI_BASE_ADDRESS + TCO1_STS);
  62. ps->tco2_sts = inw(ACPI_BASE_ADDRESS + TCO2_STS);
  63. ps->gpe0_sts[0] = inl(ACPI_BASE_ADDRESS + GPE0_STS(0));
  64. ps->gpe0_sts[1] = inl(ACPI_BASE_ADDRESS + GPE0_STS(1));
  65. ps->gpe0_sts[2] = inl(ACPI_BASE_ADDRESS + GPE0_STS(2));
  66. ps->gpe0_sts[3] = inl(ACPI_BASE_ADDRESS + GPE0_STS(3));
  67. ps->gpe0_en[0] = inl(ACPI_BASE_ADDRESS + GPE0_EN(0));
  68. ps->gpe0_en[1] = inl(ACPI_BASE_ADDRESS + GPE0_EN(1));
  69. ps->gpe0_en[2] = inl(ACPI_BASE_ADDRESS + GPE0_EN(2));
  70. ps->gpe0_en[3] = inl(ACPI_BASE_ADDRESS + GPE0_EN(3));
  71. dm_pci_read_config16(pch_dev, GEN_PMCON_1, &ps->gen_pmcon1);
  72. dm_pci_read_config16(pch_dev, GEN_PMCON_2, &ps->gen_pmcon2);
  73. dm_pci_read_config16(pch_dev, GEN_PMCON_3, &ps->gen_pmcon3);
  74. ps->prev_sleep_state = prev_sleep_state(ps);
  75. dump_power_state(ps);
  76. }