0006-ec-dell-mec5035-Add-S3-suspend-SMI-handler.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From f20c476a9358865d347c83d15f1943e4e238fe88 Mon Sep 17 00:00:00 2001
  2. From: Nicholas Chin <nic.c3.14@gmail.com>
  3. Date: Fri, 3 May 2024 11:03:32 -0600
  4. Subject: [PATCH 06/18] ec/dell/mec5035: Add S3 suspend SMI handler
  5. This is necessary for S3 resume to work on SNB and newer Dell Latitude
  6. laptops. If a command isn't sent, the EC cuts power to the DIMMs,
  7. preventing the system from resuming. These commands were found using an
  8. FPGA to log all LPC bus transactions between the host and the EC and
  9. then narrowing down which ones were actually necessary.
  10. Interestingly, the command IDs appear to be identical to those in
  11. ec/google/wilco, the EC used on Dell Latitude Chromebooks, and that EC
  12. implements a similar S3 SMI handler as the one implemented in this
  13. commit. The Wilco EC Kconfig does suggest that its firmware is a
  14. modified version of Dell's usual Latitude EC firmware, so the
  15. similarities seem to be intentional.
  16. These similarities also identified a command to enable or disable wake
  17. sources like the power button and lid switch, and this was added to the
  18. SMI handler to disable lid wake as the system does not yet resume
  19. properly from a like wake with coreboot.
  20. Tested on the Latitude E6430 (Ivy Bridge) and the Precision M6800
  21. (Haswell, not yet pushed).
  22. Change-Id: I655868aba46911d128f6c24f410dc6fdf83f3070
  23. Signed-off-by: Nicholas Chin <nic.c3.14@gmail.com>
  24. ---
  25. src/ec/dell/mec5035/Makefile.mk | 1 +
  26. src/ec/dell/mec5035/mec5035.c | 14 ++++++++++++++
  27. src/ec/dell/mec5035/mec5035.h | 22 ++++++++++++++++++++++
  28. src/ec/dell/mec5035/smihandler.c | 17 +++++++++++++++++
  29. 4 files changed, 54 insertions(+)
  30. create mode 100644 src/ec/dell/mec5035/smihandler.c
  31. diff --git a/src/ec/dell/mec5035/Makefile.mk b/src/ec/dell/mec5035/Makefile.mk
  32. index 4ebdd811f9..be557e4599 100644
  33. --- a/src/ec/dell/mec5035/Makefile.mk
  34. +++ b/src/ec/dell/mec5035/Makefile.mk
  35. @@ -5,5 +5,6 @@ ifeq ($(CONFIG_EC_DELL_MEC5035),y)
  36. bootblock-y += mec5035.c
  37. romstage-y += mec5035.c
  38. ramstage-y += mec5035.c
  39. +smm-y += mec5035.c smihandler.c
  40. endif
  41. diff --git a/src/ec/dell/mec5035/mec5035.c b/src/ec/dell/mec5035/mec5035.c
  42. index dffbb7960c..85c2ab0140 100644
  43. --- a/src/ec/dell/mec5035/mec5035.c
  44. +++ b/src/ec/dell/mec5035/mec5035.c
  45. @@ -94,6 +94,20 @@ void mec5035_control_radio(enum ec_radio_dev dev, enum ec_radio_state state)
  46. ec_command(CMD_RADIO_CTRL);
  47. }
  48. +void mec5035_change_wake(u8 source, enum ec_wake_change change)
  49. +{
  50. + u8 buf[ACPI_WAKEUP_NUM_ARGS] = {change, source, 0, 0x40};
  51. + write_mailbox_regs(buf, 2, ACPI_WAKEUP_NUM_ARGS);
  52. + ec_command(CMD_ACPI_WAKEUP_CHANGE);
  53. +}
  54. +
  55. +void mec5035_sleep_enable(void)
  56. +{
  57. + u8 buf[SLEEP_EN_NUM_ARGS] = {3, 0};
  58. + write_mailbox_regs(buf, 2, SLEEP_EN_NUM_ARGS);
  59. + ec_command(CMD_SLEEP_ENABLE);
  60. +}
  61. +
  62. void mec5035_early_init(void)
  63. {
  64. /* If this isn't sent the EC shuts down the system after about 15
  65. diff --git a/src/ec/dell/mec5035/mec5035.h b/src/ec/dell/mec5035/mec5035.h
  66. index 32f791cb01..8d4fded28b 100644
  67. --- a/src/ec/dell/mec5035/mec5035.h
  68. +++ b/src/ec/dell/mec5035/mec5035.h
  69. @@ -4,12 +4,15 @@
  70. #define _EC_DELL_MEC5035_H_
  71. #include <stdint.h>
  72. +#include <types.h>
  73. #define NUM_REGISTERS 32
  74. enum mec5035_cmd {
  75. CMD_MOUSE_TP = 0x1a,
  76. CMD_RADIO_CTRL = 0x2b,
  77. + CMD_ACPI_WAKEUP_CHANGE = 0x4a,
  78. + CMD_SLEEP_ENABLE = 0x64,
  79. CMD_CPU_OK = 0xc2,
  80. };
  81. @@ -33,9 +36,28 @@ enum ec_radio_state {
  82. RADIO_ON
  83. };
  84. +#define ACPI_WAKEUP_NUM_ARGS 4
  85. +enum ec_wake_change {
  86. + WAKE_OFF = 0,
  87. + WAKE_ON
  88. +};
  89. +
  90. +/* Copied from ec/google/wilco/commands.h. Not sure if these all apply */
  91. +enum ec_acpi_wake_events {
  92. + EC_ACPI_WAKE_PWRB = BIT(0), /* Wake up by power button */
  93. + EC_ACPI_WAKE_LID = BIT(1), /* Wake up by lid switch */
  94. + EC_ACPI_WAKE_RTC = BIT(5), /* Wake up by RTC */
  95. +};
  96. +
  97. +#define SLEEP_EN_NUM_ARGS 2
  98. +
  99. u8 mec5035_mouse_touchpad(enum ec_mouse_setting setting);
  100. void mec5035_cpu_ok(void);
  101. void mec5035_early_init(void);
  102. void mec5035_control_radio(enum ec_radio_dev device, enum ec_radio_state state);
  103. +void mec5035_change_wake(u8 source, enum ec_wake_change change);
  104. +void mec5035_sleep_enable(void);
  105. +
  106. +void mec5035_smi_sleep(int slp_type);
  107. #endif /* _EC_DELL_MEC5035_H_ */
  108. diff --git a/src/ec/dell/mec5035/smihandler.c b/src/ec/dell/mec5035/smihandler.c
  109. new file mode 100644
  110. index 0000000000..958733bf97
  111. --- /dev/null
  112. +++ b/src/ec/dell/mec5035/smihandler.c
  113. @@ -0,0 +1,17 @@
  114. +/* SPDX-License-Identifier: GPL-2.0-only */
  115. +
  116. +#include <acpi/acpi.h>
  117. +#include <console/console.h>
  118. +#include <ec/acpi/ec.h>
  119. +#include "mec5035.h"
  120. +
  121. +void mec5035_smi_sleep(int slp_type)
  122. +{
  123. + switch (slp_type) {
  124. + case ACPI_S3:
  125. + /* System does not yet resume properly if woken by lid */
  126. + mec5035_change_wake(EC_ACPI_WAKE_LID, WAKE_OFF);
  127. + mec5035_sleep_enable();
  128. + break;
  129. + }
  130. +}
  131. --
  132. 2.39.5