summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChromeOS Developer <rspangler@chromium.org>2013-03-15 14:55:53 -0700
committerChromeBot <chrome-bot@google.com>2013-03-19 10:31:12 -0700
commit6c285c09941dfb1924b037476e823ecff20c897d (patch)
tree02fa6d9f4a20f380ed6bc99e6994d6ab2c65c2ca
parentc196c66432ea9d74a84602f4a49c4fd43de1ddd5 (diff)
downloadchrome-ec-6c285c09941dfb1924b037476e823ecff20c897d.tar.gz
Move external power detect for link to its own file
Now that it doesn't need to leverage SWITCH_TASK to send the AC_CHANGE notification, pure GPIO-based external power detection can move from switch.c to its own file. BUG=chrome-os-partner:18256 BRANCH=none TEST=add AC power, UI shows charging indicator; remove AC, indicator goes away Change-Id: Id495f34185b7d971c241ac6d0a8311a6bf544507 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/45789
-rw-r--r--board/link/board.c5
-rw-r--r--board/link/board.h1
-rw-r--r--chip/lm4/switch.c17
-rw-r--r--common/build.mk1
-rw-r--r--common/charge_state.c8
-rw-r--r--common/extpower_gpio.c35
-rw-r--r--common/x86_power.c7
-rw-r--r--include/extpower.h25
-rw-r--r--include/switch.h5
9 files changed, 72 insertions, 32 deletions
diff --git a/board/link/board.c b/board/link/board.c
index bb72fdccc1..fd3c573d26 100644
--- a/board/link/board.c
+++ b/board/link/board.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,6 +6,7 @@
#include "adc.h"
#include "common.h"
+#include "extpower.h"
#include "gpio.h"
#include "i2c.h"
#include "lm4_adc.h"
@@ -31,7 +32,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
/* Other inputs */
{"THERMAL_DATA_READYn", LM4_GPIO_B, (1<<4), 0, NULL},
{"AC_PRESENT", LM4_GPIO_H, (1<<3), GPIO_INT_BOTH,
- switch_interrupt},
+ extpower_interrupt},
{"BOARD_VERSION1", LM4_GPIO_H, (1<<6), 0, NULL},
{"BOARD_VERSION2", LM4_GPIO_L, (1<<6), 0, NULL},
{"BOARD_VERSION3", LM4_GPIO_L, (1<<7), 0, NULL},
diff --git a/board/link/board.h b/board/link/board.h
index d02715abad..cc7463c961 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -18,6 +18,7 @@
#define CONFIG_CHARGER
#define CONFIG_CHARGER_BQ24725
#define CONFIG_CONSOLE_CMDHELP
+#define CONFIG_EXTPOWER_GPIO
#define CONFIG_LPC
#define CONFIG_ONEWIRE
#define CONFIG_ONEWIRE_LED
diff --git a/chip/lm4/switch.c b/chip/lm4/switch.c
index 4283916f76..94d41bed77 100644
--- a/chip/lm4/switch.c
+++ b/chip/lm4/switch.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -113,7 +113,6 @@ static uint64_t tdebounce_pwr;
static uint8_t *memmap_switches;
static int debounced_lid_open;
static int debounced_power_pressed;
-static int ac_changed;
static int simulate_power_pressed;
/**
@@ -368,11 +367,6 @@ static void set_initial_pwrbtn_state(void)
}
}
-int switch_get_ac_present(void)
-{
- return gpio_get_level(GPIO_AC_PRESENT);
-}
-
int switch_get_lid_open(void)
{
return debounced_lid_open;
@@ -511,12 +505,6 @@ void switch_task(void)
while (1) {
t = get_time().val;
- /* Handle AC state changes */
- if (ac_changed) {
- ac_changed = 0;
- hook_notify(HOOK_AC_CHANGE);
- }
-
/* Handle debounce timeouts for power button and lid switch */
if (tdebounce_pwr && t >= tdebounce_pwr) {
tdebounce_pwr = 0;
@@ -625,9 +613,6 @@ void switch_interrupt(enum gpio_signal signal)
case GPIO_PCH_BKLTEN:
update_backlight();
break;
- case GPIO_AC_PRESENT:
- ac_changed = 1;
- break;
default:
/*
* Change in non-debounced switches; we'll update their state
diff --git a/common/build.mk b/common/build.mk
index 6c91b25d8a..9ea9322a23 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -14,6 +14,7 @@ common-$(CONFIG_BATTERY_LINK)+=battery_link.o
common-$(CONFIG_CHARGER_BQ24725)+=charger_bq24725.o
common-$(CONFIG_PMU_TPS65090)+=pmu_tps65090.o pmu_tps65090_charger.o
common-$(CONFIG_EOPTION)+=eoption.o
+common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o
common-$(CONFIG_FLASH)+=flash_common.o fmap.o
common-$(CONFIG_I2C)+=i2c_commands.o
common-$(CONFIG_IR357x)+=ir357x.o
diff --git a/common/charge_state.c b/common/charge_state.c
index 808a93e477..f6ef5ce655 100644
--- a/common/charge_state.c
+++ b/common/charge_state.c
@@ -12,12 +12,12 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "printf.h"
#include "smart_battery.h"
-#include "switch.h"
#include "system.h"
#include "task.h"
#include "timer.h"
@@ -153,10 +153,6 @@ static int state_common(struct power_state_context *ctx)
rv = charger_post_init();
if (rv)
curr->error |= F_CHARGER_INIT;
- host_set_single_event(EC_HOST_EVENT_AC_CONNECTED);
- } else {
- /* AC off */
- host_set_single_event(EC_HOST_EVENT_AC_DISCONNECTED);
}
}
@@ -579,7 +575,7 @@ uint32_t charge_get_flags(void)
if (state_machine_force_idle)
flags |= CHARGE_FLAG_FORCE_IDLE;
- if (switch_get_ac_present())
+ if (extpower_is_present())
flags |= CHARGE_FLAG_EXTERNAL_POWER;
return flags;
diff --git a/common/extpower_gpio.c b/common/extpower_gpio.c
new file mode 100644
index 0000000000..218905f91d
--- /dev/null
+++ b/common/extpower_gpio.c
@@ -0,0 +1,35 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Pure GPIO-based external power detection */
+
+#include "common.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+
+int extpower_is_present(void)
+{
+ return gpio_get_level(GPIO_AC_PRESENT);
+}
+
+/**
+ * Handle notification of external power change; forward it to host.
+ */
+static void extpower_changed(void)
+{
+ if (extpower_is_present())
+ host_set_single_event(EC_HOST_EVENT_AC_CONNECTED);
+ else
+ host_set_single_event(EC_HOST_EVENT_AC_DISCONNECTED);
+}
+DECLARE_HOOK(HOOK_AC_CHANGE, extpower_changed, HOOK_PRIO_DEFAULT);
+
+void extpower_interrupt(enum gpio_signal signal)
+{
+ /* Trigger deferred notification of external power change */
+ hook_notify(HOOK_AC_CHANGE);
+}
diff --git a/common/x86_power.c b/common/x86_power.c
index 74eb70fa76..8b8968a2e3 100644
--- a/common/x86_power.c
+++ b/common/x86_power.c
@@ -8,6 +8,7 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
@@ -340,7 +341,7 @@ DECLARE_HOOK(HOOK_LID_CHANGE, x86_lid_change, HOOK_PRIO_DEFAULT);
static void x86_power_ac_change(void)
{
- if (switch_get_ac_present()) {
+ if (extpower_is_present()) {
CPRINTF("[%T x86 AC on]\n");
} else {
CPRINTF("[%T x86 AC off]\n");
@@ -437,7 +438,7 @@ void x86_power_task(void)
}
in_want = 0;
- if (switch_get_ac_present())
+ if (extpower_is_present())
task_wait_event(-1);
else {
uint64_t target_time = last_shutdown_time +
@@ -785,7 +786,7 @@ static int command_hibernation_delay(int argc, char **argv)
/* Print the current setting */
ccprintf("Hibernation delay: %d s\n", hibernate_delay);
- if (state == X86_G3 && !switch_get_ac_present()) {
+ if (state == X86_G3 && !extpower_is_present()) {
ccprintf("Time G3: %d s\n", time_g3);
ccprintf("Time left: %d s\n", hibernate_delay - time_g3);
}
diff --git a/include/extpower.h b/include/extpower.h
new file mode 100644
index 0000000000..d3f9a4f6ef
--- /dev/null
+++ b/include/extpower.h
@@ -0,0 +1,25 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* External power detection API for Chrome EC */
+
+#ifndef __CROS_EC_EXTPOWER_H
+#define __CROS_EC_EXTPOWER_H
+
+#include "common.h"
+
+/**
+ * Return non-zero if external power is present.
+ */
+int extpower_is_present(void);
+
+/**
+ * Interrupt handler for external power GPIOs.
+ *
+ * @param signal Signal which triggered the interrupt.
+ */
+void extpower_interrupt(enum gpio_signal signal);
+
+#endif /* __CROS_EC_EXTPOWER_H */
diff --git a/include/switch.h b/include/switch.h
index 9c4dfef498..ffb8eaee7b 100644
--- a/include/switch.h
+++ b/include/switch.h
@@ -24,11 +24,6 @@ void switch_interrupt(enum gpio_signal signal);
void switch_task(void);
/**
- * Return non-zero if AC power is present.
- */
-int switch_get_ac_present(void);
-
-/**
* Return non-zero if lid is open.
*
* Uses the debounced lid state, not the raw signal from the GPIO.