summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-03-19 10:27:05 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-03-20 23:51:00 +0000
commita025f18673583e1c030aa006e0f0cebeea18c062 (patch)
treef534c379664bcfee544555e8e305e96a91e36b57
parent0a35a979d470f64263d153521b4641b9d7dbdbef (diff)
downloadchrome-ec-a025f18673583e1c030aa006e0f0cebeea18c062.tar.gz
Rename charge_state.[ch] to charge_state_v1.[ch]
Making room for a new charge_state implementation. BRANCH=ToT BUG=chrome-os-partner:23776 TEST=make buildall -j No new functionality, just renaming some files. Change-Id: I80ce861f09129a518e180cac20d32e867a93cd46 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/190852 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/big/board.h1
-rw-r--r--board/falco/board.h1
-rw-r--r--board/link/board.h1
-rw-r--r--board/nyan/board.h1
-rw-r--r--board/peppy/board.h1
-rw-r--r--board/rambi/board.h1
-rw-r--r--board/samus/board.h1
-rw-r--r--board/squawks/board.h1
-rw-r--r--common/build.mk3
-rw-r--r--common/charge_state_v1.c (renamed from common/charge_state.c)0
-rw-r--r--include/charge_state.h165
-rw-r--r--include/charge_state_v1.h159
-rw-r--r--include/config.h4
-rw-r--r--include/extpower_falco.h8
-rw-r--r--test/test_config.h2
15 files changed, 198 insertions, 151 deletions
diff --git a/board/big/board.h b/board/big/board.h
index 8ff78d957c..ea6daef76a 100644
--- a/board/big/board.h
+++ b/board/big/board.h
@@ -12,6 +12,7 @@
#define CONFIG_AP_HANG_DETECT
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24725
#define CONFIG_CHIPSET_TEGRA
#define CONFIG_POWER_COMMON
diff --git a/board/falco/board.h b/board/falco/board.h
index d86a9793f2..9cd5ec0c13 100644
--- a/board/falco/board.h
+++ b/board/falco/board.h
@@ -13,6 +13,7 @@
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24738
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHIPSET_CAN_THROTTLE
diff --git a/board/link/board.h b/board/link/board.h
index 3816279b91..c52b6561a2 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -17,6 +17,7 @@
#define CONFIG_BATTERY_VENDOR_PARAMS
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24725
#define CONFIG_CHIPSET_CAN_THROTTLE
#define CONFIG_CHIPSET_IVYBRIDGE
diff --git a/board/nyan/board.h b/board/nyan/board.h
index c49d7f3e3a..0e9c4ea4eb 100644
--- a/board/nyan/board.h
+++ b/board/nyan/board.h
@@ -12,6 +12,7 @@
#define CONFIG_AP_HANG_DETECT
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24725
#define CONFIG_CHIPSET_TEGRA
#define CONFIG_POWER_COMMON
diff --git a/board/peppy/board.h b/board/peppy/board.h
index e5b60c3d17..b586816fc9 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -15,6 +15,7 @@
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24707A
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHIPSET_CAN_THROTTLE
diff --git a/board/rambi/board.h b/board/rambi/board.h
index 331fcc17af..f6afb1ecc9 100644
--- a/board/rambi/board.h
+++ b/board/rambi/board.h
@@ -14,6 +14,7 @@
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24715
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 1700 /* 33 W adapter, 19 V, 1.75 A */
diff --git a/board/samus/board.h b/board/samus/board.h
index 6646f24152..c4c04df347 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -33,6 +33,7 @@
#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24715
/* 10mOhm sense resitors. */
#define CONFIG_CHARGER_SENSE_RESISTOR 10
diff --git a/board/squawks/board.h b/board/squawks/board.h
index e637f5917d..6637184921 100644
--- a/board/squawks/board.h
+++ b/board/squawks/board.h
@@ -14,6 +14,7 @@
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24715
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 1700 /* 33 W adapter, 19 V, 1.75 A */
diff --git a/common/build.mk b/common/build.mk
index 8e92e6f328..74d851f5b5 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -23,7 +23,8 @@ common-$(CONFIG_BATTERY_BQ27541)+=battery.o
common-$(CONFIG_BATTERY_SMART)+=battery.o
common-$(CONFIG_BUTTON_COUNT)+=button.o
common-$(CONFIG_CAPSENSE)+=capsense.o
-common-$(CONFIG_CHARGER)+=charge_state.o charger.o
+common-$(CONFIG_CHARGER)+=charger.o
+common-$(CONFIG_CHARGER_V1)+=charge_state_v1.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.c b/common/charge_state_v1.c
index 53c1dda5d2..53c1dda5d2 100644
--- a/common/charge_state.c
+++ b/common/charge_state_v1.c
diff --git a/include/charge_state.h b/include/charge_state.h
index b9795391b1..8c0f73952c 100644
--- a/include/charge_state.h
+++ b/include/charge_state.h
@@ -1,159 +1,26 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* 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_H
#define __CROS_EC_CHARGE_STATE_H
-/* Update period to prevent charger watchdog timeout */
-#define CHARGER_UPDATE_PERIOD (SECOND * 10)
-
-/* Power state task polling periods in usec */
-#define POLL_PERIOD_VERY_LONG MINUTE
-#define POLL_PERIOD_LONG (MSEC * 500)
-#define POLL_PERIOD_CHARGE (MSEC * 250)
-#define POLL_PERIOD_SHORT (MSEC * 100)
-#define MIN_SLEEP_USEC (MSEC * 50)
-#define MAX_SLEEP_USEC SECOND
-
-/* Power state error flags */
-#define F_CHARGER_INIT (1 << 0) /* Charger initialization */
-#define F_CHARGER_VOLTAGE (1 << 1) /* Charger maximum output voltage */
-#define F_CHARGER_CURRENT (1 << 2) /* Charger maximum output current */
-#define F_BATTERY_VOLTAGE (1 << 3) /* Battery voltage */
-#define F_BATTERY_MODE (1 << 8) /* Battery mode */
-#define F_BATTERY_CAPACITY (1 << 9) /* Battery capacity */
-#define F_BATTERY_STATE_OF_CHARGE (1 << 10) /* State of charge, percentage */
-#define F_BATTERY_UNRESPONSIVE (1 << 11) /* Battery not responding */
-#define F_BATTERY_NOT_CONNECTED (1 << 12) /* Battery not connected */
-#define F_BATTERY_GET_PARAMS (1 << 13) /* Any battery parameter bad */
-
-#define F_BATTERY_MASK (F_BATTERY_VOLTAGE | \
- F_BATTERY_MODE | \
- F_BATTERY_CAPACITY | F_BATTERY_STATE_OF_CHARGE | \
- F_BATTERY_UNRESPONSIVE | F_BATTERY_NOT_CONNECTED | \
- F_BATTERY_GET_PARAMS)
-#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
-};
+#include "common.h"
-/* 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.
- */
-struct charge_state_data {
- int ac;
- int charging_voltage;
- int charging_current;
- struct batt_params batt;
- enum charge_state state;
- uint32_t error;
- timestamp_t ts;
-};
-
-/* State context
- * The shared context for state handler. The context contains current and
- * previous state.
- */
-struct charge_state_context {
- struct charge_state_data curr;
- struct charge_state_data prev;
- timestamp_t charge_state_updated_time;
- uint32_t *memmap_batt_volt;
- uint32_t *memmap_batt_rate;
- uint32_t *memmap_batt_cap;
- uint8_t *memmap_batt_flags;
- /* Charger and battery pack info */
- const struct charger_info *charger;
- const struct battery_info *battery;
- /* Charging timestamps */
- timestamp_t charger_update_time;
- timestamp_t trickle_charging_time;
- timestamp_t voltage_debounce_time;
- timestamp_t shutdown_warning_time;
- int battery_responsive;
-};
+/* Stuff that's common to all charger implementations can go here. */
-/**
- * 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_H */
+/* Pick the right implementation */
+#ifdef CONFIG_CHARGER_V1
+#ifdef CONFIG_CHARGER_V2
+#error "Choose either CONFIG_CHARGER_V1 or CONFIG_CHARGER_V2, not both"
+#else
+#include "charge_state_v1.h"
+#endif
+#else /* not V1 */
+#ifdef CONFIG_CHARGER_V2
+#include "charge_state_v2.h"
+#endif
+#endif /* CONFIG_CHARGER_V1 */
+#endif /* __CROS_EC_CHARGE_STATE_H */
diff --git a/include/charge_state_v1.h b/include/charge_state_v1.h
new file mode 100644
index 0000000000..29afd96a6e
--- /dev/null
+++ b/include/charge_state_v1.h
@@ -0,0 +1,159 @@
+/* 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.
+ */
+
+#include "battery.h"
+#include "timer.h"
+
+#ifndef __CROS_EC_CHARGE_STATE_V1_H
+#define __CROS_EC_CHARGE_STATE_V1_H
+
+/* Update period to prevent charger watchdog timeout */
+#define CHARGER_UPDATE_PERIOD (SECOND * 10)
+
+/* Power state task polling periods in usec */
+#define POLL_PERIOD_VERY_LONG MINUTE
+#define POLL_PERIOD_LONG (MSEC * 500)
+#define POLL_PERIOD_CHARGE (MSEC * 250)
+#define POLL_PERIOD_SHORT (MSEC * 100)
+#define MIN_SLEEP_USEC (MSEC * 50)
+#define MAX_SLEEP_USEC SECOND
+
+/* Power state error flags */
+#define F_CHARGER_INIT (1 << 0) /* Charger initialization */
+#define F_CHARGER_VOLTAGE (1 << 1) /* Charger maximum output voltage */
+#define F_CHARGER_CURRENT (1 << 2) /* Charger maximum output current */
+#define F_BATTERY_VOLTAGE (1 << 3) /* Battery voltage */
+#define F_BATTERY_MODE (1 << 8) /* Battery mode */
+#define F_BATTERY_CAPACITY (1 << 9) /* Battery capacity */
+#define F_BATTERY_STATE_OF_CHARGE (1 << 10) /* State of charge, percentage */
+#define F_BATTERY_UNRESPONSIVE (1 << 11) /* Battery not responding */
+#define F_BATTERY_NOT_CONNECTED (1 << 12) /* Battery not connected */
+#define F_BATTERY_GET_PARAMS (1 << 13) /* Any battery parameter bad */
+
+#define F_BATTERY_MASK (F_BATTERY_VOLTAGE | \
+ F_BATTERY_MODE | \
+ F_BATTERY_CAPACITY | F_BATTERY_STATE_OF_CHARGE | \
+ F_BATTERY_UNRESPONSIVE | F_BATTERY_NOT_CONNECTED | \
+ F_BATTERY_GET_PARAMS)
+#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.
+ */
+struct charge_state_data {
+ int ac;
+ int charging_voltage;
+ int charging_current;
+ struct batt_params batt;
+ enum charge_state state;
+ uint32_t error;
+ timestamp_t ts;
+};
+
+/* State context
+ * The shared context for state handler. The context contains current and
+ * previous state.
+ */
+struct charge_state_context {
+ struct charge_state_data curr;
+ struct charge_state_data prev;
+ timestamp_t charge_state_updated_time;
+ uint32_t *memmap_batt_volt;
+ uint32_t *memmap_batt_rate;
+ uint32_t *memmap_batt_cap;
+ uint8_t *memmap_batt_flags;
+ /* Charger and battery pack info */
+ const struct charger_info *charger;
+ const struct battery_info *battery;
+ /* Charging timestamps */
+ timestamp_t charger_update_time;
+ timestamp_t trickle_charging_time;
+ timestamp_t voltage_debounce_time;
+ timestamp_t shutdown_warning_time;
+ 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/config.h b/include/config.h
index 76deccc7e4..a80d256db6 100644
--- a/include/config.h
+++ b/include/config.h
@@ -159,8 +159,10 @@
/*****************************************************************************/
/* Charger config */
-/* Compile common charge state code */
+/* Compile common charge state code. You must pick an implementation. */
#undef CONFIG_CHARGER
+#undef CONFIG_CHARGER_V1
+#undef CONFIG_CHARGER_V2
/* Compile charger-specific code for these chargers (pick at most one) */
#undef CONFIG_CHARGER_BQ24707A
diff --git a/include/extpower_falco.h b/include/extpower_falco.h
index b5cbbcdc8d..8d7cb57b8b 100644
--- a/include/extpower_falco.h
+++ b/include/extpower_falco.h
@@ -8,7 +8,15 @@
#ifndef __CROS_EC_EXTPOWER_FALCO_H
#define __CROS_EC_EXTPOWER_FALCO_H
+#ifdef CONFIG_CHARGER_V2
+#error "This is not compatible with CONFIG_CHARGER_V2"
+/*
+ * ... but we can't define CONFIG_CHARGER_V1 because the tests don't need or
+ * want charge_state_v1.c. Sigh.
+ */
+#endif
#include "charge_state.h"
+#include "charge_state_v1.h"
/* Supported adapters */
enum adapter_type {
diff --git a/test/test_config.h b/test/test_config.h
index 3fc11034bc..9a005645f8 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -54,6 +54,7 @@
#define CONFIG_BATTERY_MOCK
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_INPUT_CURRENT 4032
#define CONFIG_CHARGER_DISCHARGE_ON_AC
int board_discharge_on_ac(int enabled);
@@ -72,6 +73,7 @@ int board_discharge_on_ac(int enabled);
#define CONFIG_BATTERY_MOCK
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V1
#define CONFIG_CHARGER_INPUT_CURRENT 4032
#define CONFIG_CHIPSET_CAN_THROTTLE
#define CONFIG_EXTPOWER_FALCO