summaryrefslogtreecommitdiff
path: root/src/ec
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@chromium.org>2017-10-04 14:01:41 -0700
committerFurquan Shaikh <furquan@google.com>2017-10-08 19:38:28 +0000
commit2749c52080bbaba9e6ce54fb327b7157a7e392c2 (patch)
tree91e05dd62841fe1d1f0f63bba017d1fd11550613 /src/ec
parent687b023d970327e2d4994e5fb170edf9a1e7180f (diff)
downloadcoreboot-2749c52080bbaba9e6ce54fb327b7157a7e392c2.tar.xz
ec/google/chromeec: Add library function google_chromeec_events_init
mainboard_ec_init implemented by all x86-based mainboards using chromeec performed similar tasks for initializing and recording ec events. Instead of duplicating this code across multiple boards, provide a library function google_chromeec_events_init that can be called by mainboard with appropriate inputs to perform the required actions. This change also adds a new structure google_chromeec_event_info to allow mainboards to provide information required by the library function to handle different event masks. Also, google_chromeec_log_device_events and google_chromeec_log_events no longer need to be exported. Change-Id: I1cbc24e3e1a31aed35d8527f90ed16ed15ccaa86 Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://review.coreboot.org/21877 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Diffstat (limited to 'src/ec')
-rw-r--r--src/ec/google/chromeec/ec.c70
-rw-r--r--src/ec/google/chromeec/ec.h12
2 files changed, 59 insertions, 23 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index ab879c57a2..639719a85d 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -222,12 +222,12 @@ uint32_t google_chromeec_get_device_current_events(void)
return 0;
}
-void google_chromeec_log_device_events(uint32_t mask)
+static void google_chromeec_log_device_events(uint32_t mask)
{
uint32_t events;
int i;
- if (!IS_ENABLED(CONFIG_ELOG))
+ if (!IS_ENABLED(CONFIG_ELOG) || !mask)
return;
if (google_chromeec_check_feature(EC_FEATURE_DEVICE_EVENT) != 1)
@@ -242,6 +242,53 @@ void google_chromeec_log_device_events(uint32_t mask)
}
}
+static void google_chromeec_log_events(u32 mask)
+{
+ u8 event;
+ u32 wake_mask;
+
+ if (!IS_ENABLED(CONFIG_ELOG))
+ return;
+
+ /* Set wake mask so events will be read from ACPI interface */
+ wake_mask = google_chromeec_get_wake_mask();
+ google_chromeec_set_wake_mask(mask);
+
+ while ((event = google_chromeec_get_event()) != 0) {
+ if (EC_HOST_EVENT_MASK(event) & mask)
+ elog_add_event_byte(ELOG_TYPE_EC_EVENT, event);
+ }
+
+ google_chromeec_set_wake_mask(wake_mask);
+}
+
+void google_chromeec_events_init(const struct google_chromeec_event_info *info,
+ bool is_s3_wakeup)
+{
+ if (is_s3_wakeup) {
+ google_chromeec_log_events(info->log_events |
+ info->s3_wake_events);
+
+ /* Log and clear device events that may wake the system. */
+ google_chromeec_log_device_events(info->s3_device_events);
+
+ /* Disable SMI and wake events. */
+ google_chromeec_set_smi_mask(0);
+
+ /* Clear pending events. */
+ while (google_chromeec_get_event() != 0)
+ ;
+
+ /* Restore SCI event mask. */
+ google_chromeec_set_sci_mask(info->sci_events);
+ } else
+ google_chromeec_log_events(info->log_events |
+ info->s5_wake_events);
+
+ /* Clear wake event mask. */
+ google_chromeec_set_wake_mask(0);
+}
+
int google_chromeec_check_feature(int feature)
{
struct chromeec_command cmd;
@@ -520,25 +567,6 @@ u32 google_chromeec_get_wake_mask(void)
EC_CMD_HOST_EVENT_GET_WAKE_MASK);
}
-void google_chromeec_log_events(u32 mask)
-{
-#if IS_ENABLED(CONFIG_ELOG)
- u8 event;
- u32 wake_mask;
-
- /* Set wake mask so events will be read from ACPI interface */
- wake_mask = google_chromeec_get_wake_mask();
- google_chromeec_set_wake_mask(mask);
-
- while ((event = google_chromeec_get_event()) != 0) {
- if (EC_HOST_EVENT_MASK(event) & mask)
- elog_add_event_byte(ELOG_TYPE_EC_EVENT, event);
- }
-
- google_chromeec_set_wake_mask(wake_mask);
-#endif
-}
-
int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode)
{
struct chromeec_command cmd;
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index 81bc9336e5..95d744358c 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -38,7 +38,6 @@ void google_chromeec_init(void);
uint32_t google_chromeec_get_device_enabled_events(void);
int google_chromeec_set_device_enabled_events(uint32_t mask);
uint32_t google_chromeec_get_device_current_events(void);
-void google_chromeec_log_device_events(uint32_t mask);
int google_chromeec_check_feature(int feature);
uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
@@ -49,7 +48,6 @@ u32 google_chromeec_get_events_b(void);
int google_chromeec_clear_events_b(u32 mask);
int google_chromeec_kbbacklight(int percent);
void google_chromeec_post(u8 postcode);
-void google_chromeec_log_events(u32 mask);
int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
uint8_t google_chromeec_get_switches(void);
@@ -118,4 +116,14 @@ int crosec_command_proto(struct chromeec_command *cec_command,
int google_chromeec_command(struct chromeec_command *cec_command);
+struct google_chromeec_event_info {
+ uint32_t log_events;
+ uint32_t sci_events;
+ uint32_t s3_wake_events;
+ uint32_t s3_device_events;
+ uint32_t s5_wake_events;
+};
+void google_chromeec_events_init(const struct google_chromeec_event_info *info,
+ bool is_s3_wakeup);
+
#endif /* _EC_GOOGLE_CHROMEEC_EC_H */