diff options
author | ChromeOS Developer <rspangler@chromium.org> | 2013-03-15 14:55:53 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-19 10:31:12 -0700 |
commit | 6c285c09941dfb1924b037476e823ecff20c897d (patch) | |
tree | 02fa6d9f4a20f380ed6bc99e6994d6ab2c65c2ca /common/extpower_gpio.c | |
parent | c196c66432ea9d74a84602f4a49c4fd43de1ddd5 (diff) | |
download | chrome-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
Diffstat (limited to 'common/extpower_gpio.c')
-rw-r--r-- | common/extpower_gpio.c | 35 |
1 files changed, 35 insertions, 0 deletions
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); +} |