0045-ec-dell-mec5035-Add-S3-suspend-SMI-handler.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From a8c4f7004ea1c9b8268a87dd0b700c250ec4747d 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] ec/dell/mec5035: Add S3 suspend SMI handler
  5. Change-Id: I655868aba46911d128f6c24f410dc6fdf83f3070
  6. Signed-off-by: Nicholas Chin <nic.c3.14@gmail.com>
  7. ---
  8. src/ec/dell/mec5035/Makefile.mk | 1 +
  9. src/ec/dell/mec5035/mec5035.c | 14 ++++++++++++++
  10. src/ec/dell/mec5035/mec5035.h | 19 +++++++++++++++++++
  11. src/ec/dell/mec5035/smihandler.c | 17 +++++++++++++++++
  12. 4 files changed, 51 insertions(+)
  13. create mode 100644 src/ec/dell/mec5035/smihandler.c
  14. diff --git a/src/ec/dell/mec5035/Makefile.mk b/src/ec/dell/mec5035/Makefile.mk
  15. index 4ebdd811f9..be557e4599 100644
  16. --- a/src/ec/dell/mec5035/Makefile.mk
  17. +++ b/src/ec/dell/mec5035/Makefile.mk
  18. @@ -5,5 +5,6 @@ ifeq ($(CONFIG_EC_DELL_MEC5035),y)
  19. bootblock-y += mec5035.c
  20. romstage-y += mec5035.c
  21. ramstage-y += mec5035.c
  22. +smm-y += mec5035.c smihandler.c
  23. endif
  24. diff --git a/src/ec/dell/mec5035/mec5035.c b/src/ec/dell/mec5035/mec5035.c
  25. index 68b6b2f7fb..33bf046634 100644
  26. --- a/src/ec/dell/mec5035/mec5035.c
  27. +++ b/src/ec/dell/mec5035/mec5035.c
  28. @@ -94,6 +94,20 @@ void mec5035_control_radio(enum ec_radio_dev dev, enum ec_radio_state state)
  29. ec_command(CMD_RADIO_CTRL);
  30. }
  31. +void mec5035_sleep_enable(void)
  32. +{
  33. + u8 buf[SLEEP_EN_NUM_ARGS] = {3, 0};
  34. + write_mailbox_regs(buf, 2, SLEEP_EN_NUM_ARGS);
  35. + ec_command(CMD_SLEEP_ENABLE);
  36. +}
  37. +
  38. +void mec5035_change_wake(u8 source, enum ec_wake_change change)
  39. +{
  40. + u8 buf[ACPI_WAKEUP_NUM_ARGS] = {change, source, 0, 0x40};
  41. + write_mailbox_regs(buf, 2, ACPI_WAKEUP_NUM_ARGS);
  42. + ec_command(CMD_ACPI_WAKEUP_CHANGE);
  43. +}
  44. +
  45. void mec5035_early_init(void)
  46. {
  47. /* If this isn't sent the EC shuts down the system after about 15
  48. diff --git a/src/ec/dell/mec5035/mec5035.h b/src/ec/dell/mec5035/mec5035.h
  49. index fa15a9d621..069616fbc5 100644
  50. --- a/src/ec/dell/mec5035/mec5035.h
  51. +++ b/src/ec/dell/mec5035/mec5035.h
  52. @@ -4,6 +4,7 @@
  53. #define _EC_DELL_MEC5035_H_
  54. #include <stdint.h>
  55. +#include <types.h>
  56. #define NUM_REGISTERS 32
  57. @@ -29,9 +30,27 @@ enum ec_radio_state {
  58. RADIO_ON
  59. };
  60. +#define CMD_ACPI_WAKEUP_CHANGE 0x4a
  61. +#define ACPI_WAKEUP_NUM_ARGS 4
  62. +enum ec_wake_change {
  63. + WAKE_OFF = 0,
  64. + WAKE_ON
  65. +};
  66. +enum ec_acpi_wake_events {
  67. + EC_ACPI_WAKE_PWRB = BIT(0), /* Wake up by power button */
  68. + EC_ACPI_WAKE_LID = BIT(1), /* Wake up by lid switch */
  69. + EC_ACPI_WAKE_RTC = BIT(5), /* Wake up by RTC */
  70. +};
  71. +
  72. +#define CMD_SLEEP_ENABLE 0x64
  73. +#define SLEEP_EN_NUM_ARGS 2
  74. +
  75. u8 mec5035_mouse_touchpad(u8 setting);
  76. void mec5035_cpu_ok(void);
  77. void mec5035_early_init(void);
  78. void mec5035_control_radio(enum ec_radio_dev device, enum ec_radio_state state);
  79. +void mec5035_sleep(int slp_type);
  80. +void mec5035_change_wake(u8 source, enum ec_wake_change change);
  81. +void mec5035_sleep_enable(void);
  82. #endif /* _EC_DELL_MEC5035_H_ */
  83. diff --git a/src/ec/dell/mec5035/smihandler.c b/src/ec/dell/mec5035/smihandler.c
  84. new file mode 100644
  85. index 0000000000..1db834773d
  86. --- /dev/null
  87. +++ b/src/ec/dell/mec5035/smihandler.c
  88. @@ -0,0 +1,17 @@
  89. +/* SPDX-License-Identifier: GPL-2.0-only */
  90. +
  91. +#include <acpi/acpi.h>
  92. +#include <console/console.h>
  93. +#include <ec/acpi/ec.h>
  94. +#include "mec5035.h"
  95. +
  96. +void mec5035_sleep(int slp_type)
  97. +{
  98. + switch (slp_type) {
  99. + case ACPI_S3:
  100. + /* System does not yet resume properly if woken by lid */
  101. + mec5035_change_wake(EC_ACPI_WAKE_LID, WAKE_OFF);
  102. + mec5035_sleep_enable();
  103. + break;
  104. + }
  105. +}
  106. --
  107. 2.44.0