summaryrefslogtreecommitdiff
path: root/common/inductive_charging.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/inductive_charging.c')
-rw-r--r--common/inductive_charging.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/inductive_charging.c b/common/inductive_charging.c
new file mode 100644
index 0000000000..3a2448933f
--- /dev/null
+++ b/common/inductive_charging.c
@@ -0,0 +1,37 @@
+/* Copyright 2014 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.
+ */
+
+/* Inductive charging control */
+
+#include "common.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "lid_switch.h"
+
+void inductive_charging_interrupt(enum gpio_signal signal)
+{
+ int charger_enabled = gpio_get_level(GPIO_BASE_CHG_VDD_EN);
+ int charge_done = gpio_get_level(GPIO_CHARGE_DONE);
+
+ if (!charger_enabled || charge_done)
+ gpio_set_level(GPIO_CHARGE_EN, 0);
+ else
+ gpio_set_level(GPIO_CHARGE_EN, 1);
+}
+
+static void inductive_charging_lid_update(void)
+{
+ int lid_open = lid_is_open();
+ gpio_set_level(GPIO_BASE_CHG_VDD_EN, !lid_open);
+ inductive_charging_interrupt(GPIO_LID_OPEN);
+}
+DECLARE_HOOK(HOOK_LID_CHANGE, inductive_charging_lid_update, HOOK_PRIO_DEFAULT);
+
+static void inductive_charging_init(void)
+{
+ gpio_enable_interrupt(GPIO_CHARGE_DONE);
+ inductive_charging_lid_update();
+}
+DECLARE_HOOK(HOOK_INIT, inductive_charging_init, HOOK_PRIO_DEFAULT);