From defaf5cdb5a44067ea0f2d7f18fd57e240d992a6 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Wed, 19 Mar 2014 11:15:57 -0700 Subject: Create stub files for charge_state_v2.c Remove copied code from V1 implementation, reduce to bare minimum needed to satisfy external dependencies. Don't actually enable it for any platforms, though. BRANCH=ToT BUG=chrome-os-partner:23776 TEST=make buildall -j It's used by anything and doesn't do anything if it was, but test compilation of the changed sources by defining CONFIG_CHARGER_V2. Change-Id: Iea37d0b4fc48c8ebf7f7088cd1674d6e275d03d4 Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/190853 Reviewed-by: Randall Spangler --- common/build.mk | 1 + common/charge_state_v2.c | 66 +++++++++++++++++++++++++++++++++++++++ include/charge_state.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++ include/charge_state_v1.h | 79 ----------------------------------------------- include/charge_state_v2.h | 14 +++++++++ 5 files changed, 160 insertions(+), 79 deletions(-) create mode 100644 common/charge_state_v2.c create mode 100644 include/charge_state_v2.h diff --git a/common/build.mk b/common/build.mk index 74d851f5b5..e2697c8c1c 100644 --- a/common/build.mk +++ b/common/build.mk @@ -25,6 +25,7 @@ common-$(CONFIG_BUTTON_COUNT)+=button.o common-$(CONFIG_CAPSENSE)+=capsense.o common-$(CONFIG_CHARGER)+=charger.o common-$(CONFIG_CHARGER_V1)+=charge_state_v1.o +common-$(CONFIG_CHARGER_V2)+=charge_state_v2.o # TODO(crosbug.com/p/23815): This is really the charge state machine # for ARM, not the charger driver for the tps65090. Rename. common-$(CONFIG_CHARGER_TPS65090)+=pmu_tps65090_charger.o diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c new file mode 100644 index 0000000000..1f0d4d6350 --- /dev/null +++ b/common/charge_state_v2.c @@ -0,0 +1,66 @@ +/* Copyright (c) 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. + * + * Battery charging task and state machine. + */ + +#include "battery.h" +#include "charge_state.h" +#include "charger.h" +#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 "system.h" +#include "task.h" +#include "timer.h" +#include "util.h" + +/* Console output macros */ +#define CPUTS(outstr) cputs(CC_CHARGER, outstr) +#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) + + + +void charger_task(void) +{ + while (1) + task_wait_event(-1); +} + + +int charge_keep_power_off(void) +{ + return 0; +} + + +enum charge_state charge_get_state(void) +{ + return PWR_STATE_INIT; +} + +uint32_t charge_get_flags(void) +{ + return 0; +} + +int charge_get_percent(void) +{ + return 0; +} + +int charge_temp_sensor_get_val(int idx, int *temp_ptr) +{ + return EC_ERROR_UNKNOWN; +} + +int charge_want_shutdown(void) +{ + return 0; +} diff --git a/include/charge_state.h b/include/charge_state.h index 8c0f73952c..581acfd285 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -8,6 +8,85 @@ #include "common.h" /* Stuff that's common to all charger implementations can go here. */ +/* Power states */ +enum charge_state { + /* Meta-state; unchanged from previous time through task loop */ + PWR_STATE_UNCHANGE = 0, + /* Initializing charge state machine at boot */ + PWR_STATE_INIT, + /* Re-initializing charge state machine */ + PWR_STATE_REINIT, + /* Just transitioned from init to idle */ + PWR_STATE_IDLE0, + /* Idle; AC present */ + PWR_STATE_IDLE, + /* Discharging */ + PWR_STATE_DISCHARGE, + /* Charging */ + PWR_STATE_CHARGE, + /* Charging, almost fully charged */ + PWR_STATE_CHARGE_NEAR_FULL, + /* Charging state machine error */ + PWR_STATE_ERROR +}; + +/* Charge state flags */ +/* Forcing idle state */ +#define CHARGE_FLAG_FORCE_IDLE (1 << 0) +/* External (AC) power is present */ +#define CHARGE_FLAG_EXTERNAL_POWER (1 << 1) + +/* Debugging constants, in the same order as enum charge_state. This string + * table was moved here to sync with enum above. + */ +#define CHARGE_STATE_NAME_TABLE { \ + "unchange", \ + "init", \ + "reinit", \ + "idle0", \ + "idle", \ + "discharge", \ + "charge", \ + "charge_near_full", \ + "error" \ + } + /* End of CHARGE_STATE_NAME_TABLE macro */ + + +/** + * Return current charge state. + */ +enum charge_state charge_get_state(void); + +/** + * Return non-zero if battery is so low we want to keep AP off. + */ +int charge_keep_power_off(void); + +/** + * Return current charge state flags (CHARGE_FLAG_*) + */ +uint32_t charge_get_flags(void); + +/** + * Return current battery charge percentage. + */ +int charge_get_percent(void); + +/** + * Return non-zero if discharging and battery so low we should shut down. + */ +int charge_want_shutdown(void); + +/** + * Get the last polled battery/charger temperature. + * + * @param idx Sensor index to read. + * @param temp_ptr Destination for temperature in K. + * + * @return EC_SUCCESS if successful, non-zero if error. + */ +int charge_temp_sensor_get_val(int idx, int *temp_ptr); /* Pick the right implementation */ diff --git a/include/charge_state_v1.h b/include/charge_state_v1.h index 29afd96a6e..d0637a2d21 100644 --- a/include/charge_state_v1.h +++ b/include/charge_state_v1.h @@ -40,50 +40,6 @@ #define F_CHARGER_MASK (F_CHARGER_VOLTAGE | F_CHARGER_CURRENT | \ F_CHARGER_INIT) -/* Power states */ -enum charge_state { - /* Meta-state; unchanged from previous time through task loop */ - PWR_STATE_UNCHANGE = 0, - /* Initializing charge state machine at boot */ - PWR_STATE_INIT, - /* Re-initializing charge state machine */ - PWR_STATE_REINIT, - /* Just transitioned from init to idle */ - PWR_STATE_IDLE0, - /* Idle; AC present */ - PWR_STATE_IDLE, - /* Discharging */ - PWR_STATE_DISCHARGE, - /* Charging */ - PWR_STATE_CHARGE, - /* Charging, almost fully charged */ - PWR_STATE_CHARGE_NEAR_FULL, - /* Charging state machine error */ - PWR_STATE_ERROR -}; - -/* Charge state flags */ -/* Forcing idle state */ -#define CHARGE_FLAG_FORCE_IDLE (1 << 0) -/* External (AC) power is present */ -#define CHARGE_FLAG_EXTERNAL_POWER (1 << 1) - -/* Debugging constants, in the same order as enum charge_state. This string - * table was moved here to sync with enum above. - */ -#define CHARGE_STATE_NAME_TABLE { \ - "unchange", \ - "init", \ - "reinit", \ - "idle0", \ - "idle", \ - "discharge", \ - "charge", \ - "charge_near_full", \ - "error" \ - } - /* End of CHARGE_STATE_NAME_TABLE macro */ - /* Power state data * Status collection of charging state machine. */ @@ -120,40 +76,5 @@ struct charge_state_context { int battery_responsive; }; -/** - * Return current charge state. - */ -enum charge_state charge_get_state(void); - -/** - * Return non-zero if battery is so low we want to keep AP off. - */ -int charge_keep_power_off(void); - -/** - * Return current charge state flags (CHARGE_FLAG_*) - */ -uint32_t charge_get_flags(void); - -/** - * Return current battery charge percentage. - */ -int charge_get_percent(void); - -/** - * Return non-zero if discharging and battery so low we should shut down. - */ -int charge_want_shutdown(void); - -/** - * Get the last polled battery/charger temperature. - * - * @param idx Sensor index to read. - * @param temp_ptr Destination for temperature in K. - * - * @return EC_SUCCESS if successful, non-zero if error. - */ -int charge_temp_sensor_get_val(int idx, int *temp_ptr); - #endif /* __CROS_EC_CHARGE_STATE_V1_H */ diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h new file mode 100644 index 0000000000..085f2a2047 --- /dev/null +++ b/include/charge_state_v2.h @@ -0,0 +1,14 @@ +/* Copyright (c) 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. + */ + +#include "battery.h" +#include "timer.h" + +#ifndef __CROS_EC_CHARGE_STATE_V2_H +#define __CROS_EC_CHARGE_STATE_V2_H + + +#endif /* __CROS_EC_CHARGE_STATE_V2_H */ + -- cgit v1.2.1