diff options
-rw-r--r-- | baseboard/kukui/baseboard.h | 38 | ||||
-rw-r--r-- | baseboard/kukui/battery_max17055.c (renamed from baseboard/kukui/battery.c) | 113 | ||||
-rw-r--r-- | baseboard/kukui/battery_mm8013.c | 75 | ||||
-rw-r--r-- | baseboard/kukui/build.mk | 6 | ||||
-rw-r--r-- | baseboard/kukui/charger_mt6370.c | 85 | ||||
-rw-r--r-- | baseboard/kukui/charger_mt6370.h | 13 | ||||
-rw-r--r-- | baseboard/kukui/usb_pd_policy.c | 3 | ||||
-rw-r--r-- | board/kukui/board.h | 14 |
8 files changed, 223 insertions, 124 deletions
diff --git a/baseboard/kukui/baseboard.h b/baseboard/kukui/baseboard.h index 08bd9e181f..b1da5368bf 100644 --- a/baseboard/kukui/baseboard.h +++ b/baseboard/kukui/baseboard.h @@ -8,6 +8,38 @@ #ifndef __CROS_EC_BASEBOARD_H #define __CROS_EC_BASEBOARD_H +/* + * Variant battery defines, pick one: + * VARIANT_KUKUI_BATTERY_MAX17055 + * VARIANT_KUKUI_BATTERY_MM8013 + */ +#if defined(VARIANT_KUKUI_BATTERY_MAX17055) +#define CONFIG_BATTERY_MAX17055 +#define CONFIG_BATTERY_MAX17055_ALERT +#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */ +#elif defined(VARIANT_KUKUI_BATTERY_MM8013) +#define CONFIG_BATTERY_MM8013 +#else +#error Must define a VARIANT_KUKUI_BATTERY +#endif /* VARIANT_KUKUI_BATTERY */ + +/* + * Variant charger defines, pick one: + * VARIANT_KUKUI_CHARGER_MT6370 + */ +#if defined(VARIANT_KUKUI_CHARGER_MT6370) +#define CONFIG_CHARGER_MT6370 +#define CONFIG_CHARGE_RAMP_SW +#define CONFIG_CHARGER_OTG +#define CONFIG_CHARGER_PROFILE_OVERRIDE +#define CONFIG_USB_PD_TCPM_MT6370 +#define CONFIG_USB_PD_TCPC_LOW_POWER +#define CONFIG_USB_PD_DISCHARGE_TCPC +#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE +#else +#error Must define a VARIANT_KUKUI_CHARGER +#endif /* VARIANT_KUKUI_CHARGER */ + /* Optional modules */ #define CONFIG_ADC #undef CONFIG_ADC_WATCHDOG @@ -64,14 +96,12 @@ #define CONFIG_SOFTWARE_PANIC #define CONFIG_VBOOT_HASH -#define CONFIG_CHARGE_RAMP_SW #define CONFIG_CHARGER #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_V2 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 #define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 2 #define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000 -#define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_DISCHARGE_ON_AC #define CONFIG_CHARGER_DISCHARGE_ON_AC_CUSTOM #define CONFIG_USB_CHARGER @@ -95,13 +125,9 @@ #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USB_PD_DISCHARGE_TCPC #define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE #define CONFIG_USB_PD_LOGGING #define CONFIG_USB_PD_PORT_COUNT 1 -#define CONFIG_USB_PD_TCPC_LOW_POWER -#define CONFIG_USB_PD_TCPM_MT6370 #define CONFIG_USB_PD_TCPM_TCPCI #define CONFIG_USB_PD_VBUS_DETECT_TCPC #define CONFIG_USB_PD_5V_EN_CUSTOM diff --git a/baseboard/kukui/battery.c b/baseboard/kukui/battery_max17055.c index 62f73bfa34..f1bdfdcbe1 100644 --- a/baseboard/kukui/battery.c +++ b/baseboard/kukui/battery_max17055.c @@ -6,35 +6,16 @@ */ #include "battery.h" -#include "battery_smart.h" #include "charge_state.h" +#include "charger_mt6370.h" #include "console.h" -#include "driver/charger/rt946x.h" -#include "driver/tcpm/mt6370.h" +#include "driver/battery/max17055.h" #include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "power.h" -#include "usb_pd.h" #include "util.h" -#if defined(CONFIG_BATTERY_MAX17055) -#include "driver/battery/max17055.h" -#elif defined(CONFIG_BATTERY_MM8013) -#include "driver/battery/mm8013.h" -#endif - #define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT -#if defined(BOARD_KRANE) -#define BATT_ID 1 -#else #define BATT_ID 0 -#endif - -#define BAT_LEVEL_PD_LIMIT 85 -#define IBAT_PD_LIMIT 1000 #define BATTERY_SIMPLO_CHARGE_MIN_TEMP 0 #define BATTERY_SIMPLO_CHARGE_MAX_TEMP 60 @@ -43,7 +24,6 @@ enum battery_type { BATTERY_SIMPLO = 0, - BATTERY_SCUD, BATTERY_COUNT }; @@ -60,26 +40,8 @@ static const struct battery_info info[] = { .discharging_min_c = -20, .discharging_max_c = 60, }, - [BATTERY_SCUD] = { - .voltage_max = 4400, - .voltage_normal = 3850, - .voltage_min = 3400, - .precharge_current = 256, - .start_charging_min_c = 0, - .start_charging_max_c = 45, - .charging_min_c = 0, - .charging_max_c = 50, - .discharging_min_c = -20, - .discharging_max_c = 60, - }, }; -#ifdef CONFIG_BATTERY_MAX17055 - -#if BATT_ID == 1 -#error "Battery profile for Mitsumi battery not available" -#endif - static const struct max17055_batt_profile batt_profile[] = { [BATTERY_SIMPLO] = { .is_ez_config = 1, @@ -109,23 +71,12 @@ const struct max17055_alert_profile *max17055_get_alert_profile(void) { return &alert_profile[BATT_ID]; } -#endif /* CONFIG_BATTERY_MAX17055 */ const struct battery_info *battery_get_info(void) { return &info[BATT_ID]; } -int board_cut_off_battery(void) -{ - /* The cut-off procedure is recommended by Richtek. b/116682788 */ - rt946x_por_reset(); - mt6370_vconn_discharge(0); - rt946x_cutoff_battery(); - - return EC_SUCCESS; -} - enum battery_disconnect_state battery_get_disconnect_state(void) { if (battery_is_present() == BP_YES) @@ -135,9 +86,6 @@ enum battery_disconnect_state battery_get_disconnect_state(void) int charger_profile_override(struct charge_state_data *curr) { - static int previous_chg_limit_mv; - int chg_limit_mv; -#ifdef CONFIG_BATTERY_MAX17055 /* battery temp in 0.1 deg C */ int bat_temp_c = curr->batt.temperature - 2731; @@ -169,9 +117,6 @@ int charger_profile_override(struct charge_state_data *curr) /* TEMP_ZONE_2 */ {450, BATTERY_SIMPLO_CHARGE_MAX_TEMP * 10, 3350, 4300}, }, - [BATTERY_SCUD] = { - /* unused */ - }, }; BUILD_ASSERT(ARRAY_SIZE(temp_zones[0]) == TEMP_ZONE_COUNT); BUILD_ASSERT(ARRAY_SIZE(temp_zones) == BATTERY_COUNT); @@ -206,62 +151,14 @@ int charger_profile_override(struct charge_state_data *curr) curr->state = ST_IDLE; break; } -#endif /* CONFIG_BATTERY_MAX17055 */ - /* TODO(b:131284131): Add battery configs for krane. */ - /* Limit input (=VBUS) to 5V when soc > 85% and charge current < 1A. */ - if (!(curr->batt.flags & BATT_FLAG_BAD_CURRENT) && - charge_get_percent() > BAT_LEVEL_PD_LIMIT && - curr->batt.current < 1000) { - chg_limit_mv = 5500; - } else if (IS_ENABLED(BOARD_KRANE) && - board_get_version() == 3 && - power_get_state() == POWER_S0) { - /* - * TODO(b:134227872): limit power to 5V/2A in S0 to prevent - * overheat - */ - chg_limit_mv = 5500; - curr->requested_current = 2000; - } else { - chg_limit_mv = PD_MAX_VOLTAGE_MV; - } - - if (chg_limit_mv != previous_chg_limit_mv) - CPRINTS("VBUS limited to %dmV", chg_limit_mv); - previous_chg_limit_mv = chg_limit_mv; - - /* Pull down VBUS */ - if (pd_get_max_voltage() != chg_limit_mv) - pd_set_external_voltage_limit(0, chg_limit_mv); - - /* - * When the charger says it's done charging, even if fuel gauge says - * SOC < BATTERY_LEVEL_NEAR_FULL, we'll overwrite SOC with - * BATTERY_LEVEL_NEAR_FULL. So we can ensure both Chrome OS UI - * and battery LED indicate full charge. - */ - if (rt946x_is_charge_done()) { - curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL, - curr->batt.state_of_charge); - } +#ifdef VARIANT_KUKUI_CHARGER_MT6370 + mt6370_charger_profile_override(curr); +#endif /* CONFIG_CHARGER_MT6370 */ return 0; } -static void board_charge_termination(void) -{ - static uint8_t te; - /* Enable charge termination when we are sure battery is present. */ - if (!te && battery_is_present() == BP_YES) { - if (!rt946x_enable_charge_termination(1)) - te = 1; - } -} -DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, - board_charge_termination, - HOOK_PRIO_DEFAULT); - enum ec_status charger_profile_override_get_param(uint32_t param, uint32_t *value) { diff --git a/baseboard/kukui/battery_mm8013.c b/baseboard/kukui/battery_mm8013.c new file mode 100644 index 0000000000..ad65116ebf --- /dev/null +++ b/baseboard/kukui/battery_mm8013.c @@ -0,0 +1,75 @@ +/* Copyright 2018 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 pack vendor provided charging profile + */ + +#include "battery.h" +#include "charge_state.h" +#include "charger_mt6370.h" +#include "console.h" +#include "driver/tcpm/mt6370.h" +#include "ec_commands.h" +#include "util.h" + +#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT + +#define BATT_ID 0 + +#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) + +enum battery_type { + BATTERY_SCUD = 0, + BATTERY_COUNT +}; + +static const struct battery_info info[] = { + [BATTERY_SCUD] = { + .voltage_max = 4400, + .voltage_normal = 3850, + .voltage_min = 3400, + .precharge_current = 256, + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 50, + .discharging_min_c = -20, + .discharging_max_c = 60, + }, +}; + +const struct battery_info *battery_get_info(void) +{ + return &info[BATT_ID]; +} + +enum battery_disconnect_state battery_get_disconnect_state(void) +{ + if (battery_is_present() == BP_YES) + return BATTERY_NOT_DISCONNECTED; + return BATTERY_DISCONNECTED; +} + +int charger_profile_override(struct charge_state_data *curr) +{ + /* TODO(b:138269954): Add battery configs for krane. */ + +#ifdef VARIANT_KUKUI_CHARGER_MT6370 + mt6370_charger_profile_override(curr); +#endif /* CONFIG_CHARGER_MT6370 */ + + return 0; +} + +enum ec_status charger_profile_override_get_param(uint32_t param, + uint32_t *value) +{ + return EC_RES_INVALID_PARAM; +} + +enum ec_status charger_profile_override_set_param(uint32_t param, + uint32_t value) +{ + return EC_RES_INVALID_PARAM; +} diff --git a/baseboard/kukui/build.mk b/baseboard/kukui/build.mk index 4de8dfb684..af328fc2ab 100644 --- a/baseboard/kukui/build.mk +++ b/baseboard/kukui/build.mk @@ -10,7 +10,9 @@ baseboard-y=baseboard.o baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o baseboard-$(CONFIG_BOOTBLOCK)+=emmc.o -# TODO(b:137172860) split battery.c into variant_battery_xxx.c */ -baseboard-y+=battery.o +baseboard-$(VARIANT_KUKUI_BATTERY_MAX17055)+=battery_max17055.o +baseboard-$(VARIANT_KUKUI_BATTERY_MM8013)+=battery_mm8013.o + +baseboard-$(VARIANT_KUKUI_CHARGER_MT6370)+=charger_mt6370.o $(out)/RO/baseboard/$(BASEBOARD)/emmc.o: $(out)/bootblock_data.h diff --git a/baseboard/kukui/charger_mt6370.c b/baseboard/kukui/charger_mt6370.c new file mode 100644 index 0000000000..362ce8c86b --- /dev/null +++ b/baseboard/kukui/charger_mt6370.c @@ -0,0 +1,85 @@ +/* Copyright 2019 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 "charger_mt6370.h" +#include "console.h" +#include "driver/tcpm/mt6370.h" +#include "driver/charger/rt946x.h" +#include "hooks.h" +#include "power.h" +#include "usb_pd.h" +#include "util.h" + +#define BAT_LEVEL_PD_LIMIT 85 + +#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) + +int board_cut_off_battery(void) +{ + /* The cut-off procedure is recommended by Richtek. b/116682788 */ + rt946x_por_reset(); + mt6370_vconn_discharge(0); + rt946x_cutoff_battery(); + + return EC_SUCCESS; +} + +void mt6370_charger_profile_override(struct charge_state_data *curr) +{ + static int previous_chg_limit_mv; + int chg_limit_mv; + + /* Limit input (=VBUS) to 5V when soc > 85% and charge current < 1A. */ + if (!(curr->batt.flags & BATT_FLAG_BAD_CURRENT) && + charge_get_percent() > BAT_LEVEL_PD_LIMIT && + curr->batt.current < 1000) { + chg_limit_mv = 5500; + } else if (IS_ENABLED(BOARD_KRANE) && + board_get_version() == 3 && + power_get_state() == POWER_S0) { + /* + * TODO(b:134227872): limit power to 5V/2A in S0 to prevent + * overheat + */ + chg_limit_mv = 5500; + curr->requested_current = 2000; + } else { + chg_limit_mv = PD_MAX_VOLTAGE_MV; + } + + if (chg_limit_mv != previous_chg_limit_mv) + CPRINTS("VBUS limited to %dmV", chg_limit_mv); + previous_chg_limit_mv = chg_limit_mv; + + /* Pull down VBUS */ + if (pd_get_max_voltage() != chg_limit_mv) + pd_set_external_voltage_limit(0, chg_limit_mv); + + /* + * When the charger says it's done charging, even if fuel gauge says + * SOC < BATTERY_LEVEL_NEAR_FULL, we'll overwrite SOC with + * BATTERY_LEVEL_NEAR_FULL. So we can ensure both Chrome OS UI + * and battery LED indicate full charge. + */ + if (rt946x_is_charge_done()) { + curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL, + curr->batt.state_of_charge); + } + +} + +static void board_charge_termination(void) +{ + static uint8_t te; + /* Enable charge termination when we are sure battery is present. */ + if (!te && battery_is_present() == BP_YES) { + if (!rt946x_enable_charge_termination(1)) + te = 1; + } +} +DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, + board_charge_termination, + HOOK_PRIO_DEFAULT); + diff --git a/baseboard/kukui/charger_mt6370.h b/baseboard/kukui/charger_mt6370.h new file mode 100644 index 0000000000..9cf1b44d95 --- /dev/null +++ b/baseboard/kukui/charger_mt6370.h @@ -0,0 +1,13 @@ +/* Copyright 2019 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. + */ + +#ifndef __CROS_EC_BASEBOARD_CHARGER_MT6370_H +#define __CROS_EC_BASEBOARD_CHARGER_MT6370_H + +#include "charge_state.h" + +void mt6370_charger_profile_override(struct charge_state_data *curr); + +#endif diff --git a/baseboard/kukui/usb_pd_policy.c b/baseboard/kukui/usb_pd_policy.c index 40c22b8c66..238ec4b1bf 100644 --- a/baseboard/kukui/usb_pd_policy.c +++ b/baseboard/kukui/usb_pd_policy.c @@ -5,7 +5,6 @@ #include "charger.h" #include "console.h" -#include "driver/charger/rt946x.h" #include "gpio.h" #include "system.h" #include "timer.h" @@ -63,7 +62,7 @@ int board_vbus_source_enabled(int port) int board_is_sourcing_vbus(int port) { - if (board_get_version() <= 1) + if (IS_ENABLED(BOARD_KUKUI) && board_get_version() <= 1) return charger_is_sourcing_otg_power(port); else return board_vbus_source_enabled(port); diff --git a/board/kukui/board.h b/board/kukui/board.h index aa05ebc712..6808efb49e 100644 --- a/board/kukui/board.h +++ b/board/kukui/board.h @@ -8,20 +8,22 @@ #ifndef __CROS_EC_BOARD_H #define __CROS_EC_BOARD_H +#ifdef BOARD_KRANE +#define VARIANT_KUKUI_BATTERY_MM8013 +#else +#define VARIANT_KUKUI_BATTERY_MAX17055 +#endif + +#define VARIANT_KUKUI_CHARGER_MT6370 + #include "baseboard.h" -#define CONFIG_CHARGER_MT6370 -#define CONFIG_CHARGER_OTG #define CONFIG_VOLUME_BUTTONS /* Battery */ #ifdef BOARD_KRANE -#define CONFIG_BATTERY_MM8013 #define BATTERY_DESIRED_CHARGING_CURRENT 3500 /* mA */ #else -#define CONFIG_BATTERY_MAX17055 -#define CONFIG_BATTERY_MAX17055_ALERT -#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */ #define BATTERY_DESIRED_CHARGING_CURRENT 2000 /* mA */ #endif /* BOARD_KRANE */ |