summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorShelley Chen <shchen@chromium.org>2016-06-10 10:08:01 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-06-21 20:28:09 -0700
commit9ceaa9d8e0706a4a7f416e76d8b0248579b54939 (patch)
tree7abdf70a48174b6f9e22eac8f549804319048252 /chip
parent58c0727901aae21c496056a5eccaa27c693510ef (diff)
downloadchrome-ec-9ceaa9d8e0706a4a7f416e76d8b0248579b54939.tar.gz
rk3399: kevin: Adding get_rtc_alarm functionality.
Adding ability to get # seconds before rtc alarm goes off. BUG=chrome-os-partner:52218 BRANCH=None TEST=ectool rtcgetalarm w/o setting returns Alarm not set. ectool rtcsetalarm 30; ectool rtcgetalarm to make sure counting down to 0. After alarm goes off, rtcgetalarm should return alarm not set again. rtcsetalarm 30; rtcgetalarm to check alarm is set. rtcsetalarm 0; should disable alarm. Use rtcgetalarm to ensure that alarm is disabled. Change-Id: I176b12fe2dda08eedd23ea33dc64785f09f1d9ae Signed-off-by: Shelley Chen <shchen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/353331 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/npcx/system.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/chip/npcx/system.c b/chip/npcx/system.c
index 13695acf73..f014acb455 100644
--- a/chip/npcx/system.c
+++ b/chip/npcx/system.c
@@ -412,13 +412,20 @@ static char system_to_hex(uint8_t x)
/*****************************************************************************/
/* IC specific low-level driver */
-/* Microsecond will be ignore for hardware limitation */
+/*
+ * Microseconds will be ignored. The WTC register only
+ * stores wakeup time in seconds.
+ * Set seconds = 0 to disable the alarm
+ */
+#define EC_RTC_ALARM_CLEAR 0
void system_set_rtc_alarm(uint32_t seconds, uint32_t microseconds)
{
uint32_t cur_secs, alarm_secs;
- if (seconds == 0)
+ if (seconds == EC_RTC_ALARM_CLEAR) {
+ system_reset_rtc_alarm();
return;
+ }
/* Get current clock */
cur_secs = NPCX_TTC;
@@ -458,6 +465,25 @@ void system_reset_rtc_alarm(void)
task_disable_irq(NPCX_IRQ_MTC_WKINTAD_0);
}
+/*
+ * Return the seconds remaining before the RTC alarm goes off.
+ * Returns 0 if alarm is not set.
+ */
+uint32_t system_get_rtc_alarm(void)
+{
+ /*
+ * Return 0:
+ * 1. If alarm is not set to go off, OR
+ * 2. If alarm is set and has already gone off
+ */
+ if (!IS_BIT_SET(NPCX_WTC, NPCX_WTC_WIE) ||
+ IS_BIT_SET(NPCX_WTC, NPCX_WTC_PTO)) {
+ return 0;
+ }
+ /* Get seconds before alarm goes off */
+ return (NPCX_WTC - NPCX_TTC) & MTC_ALARM_MASK;
+}
+
/**
* Enable hibernate interrupt
*/
@@ -780,6 +806,19 @@ DECLARE_HOST_COMMAND(EC_CMD_RTC_SET_ALARM,
system_rtc_set_alarm,
EC_VER_MASK(0));
+static int system_rtc_get_alarm(struct host_cmd_handler_args *args)
+{
+ struct ec_response_rtc *r = args->response;
+
+ r->time = system_get_rtc_alarm();
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_RTC_GET_ALARM,
+ system_rtc_get_alarm,
+ EC_VER_MASK(0));
+
#ifdef CONFIG_EXTERNAL_STORAGE
void system_jump_to_booter(void)
{