summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
Diffstat (limited to 'chip')
-rw-r--r--chip/g/rbox.c29
-rw-r--r--chip/g/rbox.h21
2 files changed, 41 insertions, 9 deletions
diff --git a/chip/g/rbox.c b/chip/g/rbox.c
index 9813123a84..dba2438fa9 100644
--- a/chip/g/rbox.c
+++ b/chip/g/rbox.c
@@ -10,21 +10,36 @@
#define POWER_BUTTON 2
-void rbox_press_power_btn(int ms)
-{
- uint8_t val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL);
+static uint8_t val;
- GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, ~(1 << POWER_BUTTON) & val);
- GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 1 << POWER_BUTTON);
- GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 1 << POWER_BUTTON);
+int rbox_powerbtn_is_pressed(void)
+{
+ return !GREAD_FIELD(RBOX, CHECK_OUTPUT, PWRB_OUT);
+}
- msleep(ms);
+int rbox_powerbtn_override_is_enabled(void)
+{
+ return GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, EN) & (1 << POWER_BUTTON);
+}
+void rbox_powerbtn_release(void)
+{
GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 0);
GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 0);
GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, val);
}
+void rbox_powerbtn_press(void)
+{
+ if (rbox_powerbtn_override_is_enabled())
+ return;
+
+ val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL);
+ GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, ~(1 << POWER_BUTTON) & val);
+ GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 1 << POWER_BUTTON);
+ GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 1 << POWER_BUTTON);
+}
+
static void rbox_release_ec_reset(void)
{
/* Let the EC go (the RO bootloader asserts it ASAP after POR) */
diff --git a/chip/g/rbox.h b/chip/g/rbox.h
index 0d90b2ce25..e327faaf8e 100644
--- a/chip/g/rbox.h
+++ b/chip/g/rbox.h
@@ -6,6 +6,23 @@
#ifndef __CROS_RBOX_H
#define __CROS_RBOX_H
-/* Simultate a power button press */
-void rbox_press_power_btn(int ms);
+/**
+ * Return true if the power button output shows it is pressed
+ */
+int rbox_powerbtn_is_pressed(void);
+
+/**
+ * Return true if power button rbox output override is enabled
+ */
+int rbox_powerbtn_override_is_enabled(void);
+
+/**
+ * Disable the output override
+ */
+void rbox_powerbtn_release(void);
+
+/**
+ * Override power button output to force a power button press
+ */
+void rbox_powerbtn_press(void);
#endif /* __CROS_RBOX_H */