summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2019-03-26 06:06:01 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-30 20:59:37 -0700
commit89bfde44d99ad345a686998b344aac35051ebdff (patch)
tree6a8a7135d30e9d06fcb824cab459fb25fc60dbc3 /board
parent592919bd01f8a20c16a6e2907c273b94bc9962c4 (diff)
downloadchrome-ec-89bfde44d99ad345a686998b344aac35051ebdff.tar.gz
flapjack: base on the adc to determine battery type
Use the ADC reading to match the battery in the table. BUG=b:126770302 BRANCH=None TEST=Check the console with matching "Battery Type:" value. Change-Id: Ibdc9a96b7f15506deda6e87fec49270a7afe3441 Signed-off-by: YH Lin <yueherngl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1507320 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/flapjack/battery.c56
-rw-r--r--board/flapjack/board.c2
2 files changed, 46 insertions, 12 deletions
diff --git a/board/flapjack/battery.c b/board/flapjack/battery.c
index 1e088f32d9..6ba167b3fe 100644
--- a/board/flapjack/battery.c
+++ b/board/flapjack/battery.c
@@ -19,9 +19,12 @@
#include "usb_pd.h"
#include "util.h"
#include "board.h"
+#include "adc.h"
+#include "adc_chip.h"
+#include "math_util.h"
-/* We have only one battery now. */
-#define BATT_ID BATTERY_C18_ATL
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
#define BAT_LEVEL_PD_LIMIT 85
@@ -147,19 +150,52 @@ static const struct {
},
};
+static struct {
+ enum battery_type type;
+ int expect_mv;
+} const batteries[] = {
+ { BATTERY_C18_ATL, 900 }, /* 100K */
+ { BATTERY_C19_ATL, 576 }, /* 47K */
+};
+BUILD_ASSERT(ARRAY_SIZE(batteries) < BATTERY_COUNT);
+
+#define MARGIN_MV 56 /* Simply assume 1800/16/2 */
+
+static enum battery_type batt_type = BATTERY_UNKNOWN;
+
+static void board_get_battery_type(void)
+{
+ int mv;
+ int i;
+
+ mv = adc_read_channel(ADC_BATT_ID);
+ if (mv == ADC_READ_ERROR)
+ mv = adc_read_channel(ADC_BATT_ID);
+
+ for (i = 0; i < ARRAY_SIZE(batteries); i++) {
+ if (ABS(mv - batteries[i].expect_mv) < MARGIN_MV) {
+ batt_type = batteries[i].type;
+ break;
+ }
+ }
+
+ CPRINTS("Battery Type: %d", batt_type);
+}
+DECLARE_HOOK(HOOK_INIT, board_get_battery_type, HOOK_PRIO_FIRST);
+
const struct battery_info *battery_get_info(void)
{
- return &info[BATT_ID];
+ return &info[batt_type];
}
const struct max17055_batt_profile *max17055_get_batt_profile(void)
{
- return &batt_profile[BATT_ID];
+ return &batt_profile[batt_type];
}
const struct max17055_alert_profile *max17055_get_alert_profile(void)
{
- return &alert_profile[BATT_ID];
+ return &alert_profile[batt_type];
}
int board_cut_off_battery(void)
@@ -188,14 +224,14 @@ int charger_profile_override(struct charge_state_data *curr)
return 0;
if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
- (bat_temp_c < temp_zones[BATT_ID][0].temp_min) ||
- (bat_temp_c >= temp_zones[BATT_ID][TEMP_ZONE_COUNT - 1].temp_max))
+ (bat_temp_c < temp_zones[batt_type][0].temp_min) ||
+ (bat_temp_c >= temp_zones[batt_type][TEMP_ZONE_COUNT - 1].temp_max))
temp_zone = TEMP_OUT_OF_RANGE;
else {
for (temp_zone = TEMP_ZONE_0; temp_zone < TEMP_ZONE_COUNT;
temp_zone++) {
if (bat_temp_c <
- temp_zones[BATT_ID][temp_zone].temp_max)
+ temp_zones[batt_type][temp_zone].temp_max)
break;
}
}
@@ -206,9 +242,9 @@ int charger_profile_override(struct charge_state_data *curr)
curr->state = ST_IDLE;
} else {
curr->requested_current =
- temp_zones[BATT_ID][temp_zone].desired_current;
+ temp_zones[batt_type][temp_zone].desired_current;
curr->requested_voltage =
- temp_zones[BATT_ID][temp_zone].desired_voltage;
+ temp_zones[batt_type][temp_zone].desired_voltage;
}
/*
diff --git a/board/flapjack/board.c b/board/flapjack/board.c
index bcf1dbe98e..9c32886ffb 100644
--- a/board/flapjack/board.c
+++ b/board/flapjack/board.c
@@ -285,8 +285,6 @@ void board_config_pre_init(void)
(3 << 20) | (3 << 24);
}
-#define THRESHOLD_MV 56 /* Simply assume 1800/16/2 */
-
/* Motion sensors */
/* Mutexes */
#ifdef SECTION_IS_RW