From e1fcb2db780c7ae97ad7dbfa8dcccf9de4098a5a Mon Sep 17 00:00:00 2001 From: Sean Rhodes Date: Thu, 27 Jun 2024 12:20:18 +0100 Subject: [PATCH] ec/starlabs/merlin: Add support for setting the charging speed Allow boards that use the merlin EC to configure the charging speed, as all versions of the merlin EC support this. All coreboot does it write a value to the EC RAM and the EC will handle the rest. Change-Id: I46faa540530c5bd7f5473021561380213158152e Signed-off-by: Sean Rhodes Reviewed-on: https://review.coreboot.org/c/coreboot/+/84633 Tested-by: build bot (Jenkins) Reviewed-by: Matt DeVillier --- src/ec/starlabs/merlin/Kconfig | 6 +++++ src/ec/starlabs/merlin/ec.h | 5 ++++ src/ec/starlabs/merlin/ite.c | 23 +++++++++++++++++++ src/ec/starlabs/merlin/variants/apl/ecdefs.h | 1 + .../starlabs/merlin/variants/cezanne/ecdefs.h | 1 + src/ec/starlabs/merlin/variants/glk/ecdefs.h | 1 + src/ec/starlabs/merlin/variants/glkr/ecdefs.h | 1 + src/ec/starlabs/merlin/variants/kbl/ecdefs.h | 1 + .../starlabs/merlin/variants/merlin/ecdefs.h | 1 + src/mainboard/starlabs/starbook/Kconfig | 3 +++ src/mainboard/starlabs/starbook/cmos.default | 1 + src/mainboard/starlabs/starbook/cmos.layout | 5 ++++ src/mainboard/starlabs/starfighter/Kconfig | 1 + .../starlabs/starfighter/cmos.default | 1 + .../starlabs/starfighter/cmos.layout | 5 ++++ src/mainboard/starlabs/starlite_adl/Kconfig | 1 + .../starlabs/starlite_adl/cmos.default | 2 ++ .../starlabs/starlite_adl/cmos.layout | 5 ++++ 18 files changed, 64 insertions(+) diff --git a/src/ec/starlabs/merlin/Kconfig b/src/ec/starlabs/merlin/Kconfig index 9f05991061..fd8000e39e 100644 --- a/src/ec/starlabs/merlin/Kconfig +++ b/src/ec/starlabs/merlin/Kconfig @@ -64,6 +64,12 @@ config EC_STARLABS_MAX_CHARGE help Select if the mainboard supports limiting the maximum charge of the battery. +config EC_STARLABS_CHARGING_SPEED + bool "Enable setting the charging speed" + depends on EC_STARLABS_MERLIN + help + Select if the mainboard supports configuring the charging speed. + config EC_STARLABS_MERLIN bool "Use open-source Merlin EC Firmware" default n diff --git a/src/ec/starlabs/merlin/ec.h b/src/ec/starlabs/merlin/ec.h index ca1d081f0c..728f255a09 100644 --- a/src/ec/starlabs/merlin/ec.h +++ b/src/ec/starlabs/merlin/ec.h @@ -98,6 +98,11 @@ #define KBL_DISABLED 0x00 #define KBL_ENABLED 0xdd +/* Charging Speed */ +#define SPEED_1_0C 0x00 +#define SPEED_0_5C 0x01 +#define SPEED_0_2C 0x02 + uint16_t ec_get_version(void); #endif diff --git a/src/ec/starlabs/merlin/ite.c b/src/ec/starlabs/merlin/ite.c index 2f8bced324..03b3a96999 100644 --- a/src/ec/starlabs/merlin/ite.c +++ b/src/ec/starlabs/merlin/ite.c @@ -69,6 +69,7 @@ static void merlin_init(struct device *dev) * trackpad_state * kbl_brightness * kbl_state + * charging_speed */ /* @@ -240,6 +241,28 @@ static void merlin_init(struct device *dev) */ ec_write(ECRAM_KBL_STATE, KBL_ENABLED); + + /* + * Charging Speed + * + * Setting: charging_speed + * + * Values: 1.0C, 0.5C, 0.2C + * Default: 0.5C + * + */ + const uint8_t charging_speed[] = { + SPEED_1_0C, + SPEED_0_5C, + SPEED_0_2C + }; + + if (CONFIG(EC_STARLABS_CHARGING_SPEED)) + ec_write(ECRAM_CHARGING_SPEED, + get_ec_value_from_option("charging_speed", + SPEED_0_5C, + charging_speed, + ARRAY_SIZE(charging_speed))); } static struct device_operations ops = { diff --git a/src/ec/starlabs/merlin/variants/apl/ecdefs.h b/src/ec/starlabs/merlin/variants/apl/ecdefs.h index cca0bdc1bd..a7a0c753b6 100644 --- a/src/ec/starlabs/merlin/variants/apl/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/apl/ecdefs.h @@ -20,5 +20,6 @@ #define ECRAM_MAX_CHARGE dead_code_t(uint8_t) #define ECRAM_FAN_MODE dead_code_t(uint8_t) #define ECRAM_FAST_CHARGE dead_code_t(uint8_t) +#define ECRAM_CHARGING_SPEED dead_code_t(uint8_t) #endif diff --git a/src/ec/starlabs/merlin/variants/cezanne/ecdefs.h b/src/ec/starlabs/merlin/variants/cezanne/ecdefs.h index 6942c391a3..aa75e28e04 100644 --- a/src/ec/starlabs/merlin/variants/cezanne/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/cezanne/ecdefs.h @@ -23,5 +23,6 @@ #define ECRAM_KBL_BRIGHTNESS 0x36 #define ECRAM_FN_LOCK_STATE 0x70 #define ECRAM_FAST_CHARGE dead_code_t(uint8_t) +#define ECRAM_CHARGING_SPEED dead_code_t(uint8_t) #endif diff --git a/src/ec/starlabs/merlin/variants/glk/ecdefs.h b/src/ec/starlabs/merlin/variants/glk/ecdefs.h index 8130bd17d4..9037904034 100644 --- a/src/ec/starlabs/merlin/variants/glk/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/glk/ecdefs.h @@ -20,5 +20,6 @@ #define ECRAM_MAX_CHARGE dead_code_t(uint8_t) #define ECRAM_FAN_MODE dead_code_t(uint8_t) #define ECRAM_FAST_CHARGE dead_code_t(uint8_t) +#define ECRAM_CHARGING_SPEED dead_code_t(uint8_t) #endif diff --git a/src/ec/starlabs/merlin/variants/glkr/ecdefs.h b/src/ec/starlabs/merlin/variants/glkr/ecdefs.h index 038c378fb2..9c3daa094c 100644 --- a/src/ec/starlabs/merlin/variants/glkr/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/glkr/ecdefs.h @@ -23,5 +23,6 @@ #define ECRAM_MAX_CHARGE dead_code_t(uint8_t) #define ECRAM_FAN_MODE dead_code_t(uint8_t) #define ECRAM_FAST_CHARGE 0x18 +#define ECRAM_CHARGING_SPEED dead_code_t(uint8_t) #endif diff --git a/src/ec/starlabs/merlin/variants/kbl/ecdefs.h b/src/ec/starlabs/merlin/variants/kbl/ecdefs.h index 5ba8ad64b1..d15a6ad820 100644 --- a/src/ec/starlabs/merlin/variants/kbl/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/kbl/ecdefs.h @@ -20,5 +20,6 @@ #define ECRAM_FN_CTRL_REVERSE 0x43 #define ECRAM_MAX_CHARGE dead_code_t(uint8_t) #define ECRAM_FAST_CHARGE dead_code_t(uint8_t) +#define ECRAM_CHARGING_SPEED dead_code_t(uint8_t) #endif diff --git a/src/ec/starlabs/merlin/variants/merlin/ecdefs.h b/src/ec/starlabs/merlin/variants/merlin/ecdefs.h index 8127027fcb..37b0562014 100644 --- a/src/ec/starlabs/merlin/variants/merlin/ecdefs.h +++ b/src/ec/starlabs/merlin/variants/merlin/ecdefs.h @@ -20,5 +20,6 @@ #define ECRAM_MAX_CHARGE 0x1a #define ECRAM_FAN_MODE 0x1b #define ECRAM_FAST_CHARGE dead_code_t(uint8_t) +#define ECRAM_CHARGING_SPEED 0x1d #endif diff --git a/src/mainboard/starlabs/starbook/Kconfig b/src/mainboard/starlabs/starbook/Kconfig index 6ba3d6ea01..f3dd24a8a7 100644 --- a/src/mainboard/starlabs/starbook/Kconfig +++ b/src/mainboard/starlabs/starbook/Kconfig @@ -29,6 +29,7 @@ config BOARD_STARLABS_LABTOP_KBL config BOARD_STARLABS_LABTOP_CML select BOARD_ROMSIZE_KB_16384 select BOARD_STARLABS_STARBOOK_SERIES + select EC_STARLABS_CHARGING_SPEED select EC_STARLABS_KBL_LEVELS select EC_STARLABS_MAX_CHARGE select EC_STARLABS_MERLIN @@ -45,6 +46,7 @@ config BOARD_STARLABS_STARBOOK_TGL select BOARD_STARLABS_STARBOOK_SERIES select DRIVERS_INTEL_PMC select DRIVERS_INTEL_USB4_RETIMER + select EC_STARLABS_CHARGING_SPEED select EC_STARLABS_KBL_LEVELS select EC_STARLABS_MAX_CHARGE select EC_STARLABS_MERLIN @@ -62,6 +64,7 @@ config BOARD_STARLABS_STARBOOK_ADL_COMMON select BOARD_ROMSIZE_KB_32768 select BOARD_STARLABS_STARBOOK_SERIES select DRIVERS_INTEL_PMC + select EC_STARLABS_CHARGING_SPEED select EC_STARLABS_KBL_LEVELS select EC_STARLABS_MAX_CHARGE select EC_STARLABS_MERLIN diff --git a/src/mainboard/starlabs/starbook/cmos.default b/src/mainboard/starlabs/starbook/cmos.default index b4ae84cc7d..d5f195ec92 100644 --- a/src/mainboard/starlabs/starbook/cmos.default +++ b/src/mainboard/starlabs/starbook/cmos.default @@ -20,6 +20,7 @@ card_reader=Enable # EC kbl_timeout=30 seconds fn_ctrl_swap=Disable +charging_speed=0.5C # Functions fn_lock_state=0x1 trackpad_state=0x1 diff --git a/src/mainboard/starlabs/starbook/cmos.layout b/src/mainboard/starlabs/starbook/cmos.layout index e4032110a3..fad4032bf3 100644 --- a/src/mainboard/starlabs/starbook/cmos.layout +++ b/src/mainboard/starlabs/starbook/cmos.layout @@ -40,6 +40,7 @@ entries 608 1 e 1 fn_ctrl_swap 616 2 e 8 max_charge 624 2 e 9 fan_mode +632 2 e 11 charging_speed # coreboot config options: check sums 984 16 h 0 check_sum @@ -102,6 +103,10 @@ enumerations 10 2 High 10 3 On +11 0 1.0C +11 1 0.5C +11 2 0.2C + # ----------------------------------------------------------------- checksums diff --git a/src/mainboard/starlabs/starfighter/Kconfig b/src/mainboard/starlabs/starfighter/Kconfig index b3ee347036..7fd6c29f75 100644 --- a/src/mainboard/starlabs/starfighter/Kconfig +++ b/src/mainboard/starlabs/starfighter/Kconfig @@ -8,6 +8,7 @@ config BOARD_STARLABS_STARFIGHTER_SERIES select DRIVERS_I2C_HID select EC_STARLABS_FAN select EC_STARLABS_ITE + select EC_STARLABS_CHARGING_SPEED select EC_STARLABS_KBL_LEVELS select EC_STARLABS_MAX_CHARGE select EC_STARLABS_MERLIN diff --git a/src/mainboard/starlabs/starfighter/cmos.default b/src/mainboard/starlabs/starfighter/cmos.default index 88cd1789fb..7d0d447b0f 100644 --- a/src/mainboard/starlabs/starfighter/cmos.default +++ b/src/mainboard/starlabs/starfighter/cmos.default @@ -16,6 +16,7 @@ pci_hot_plug=Disable # EC kbl_timeout=30 seconds fn_ctrl_swap=Disable +charging_speed=0.5C # southbridge power_on_after_fail=Disable # Functions diff --git a/src/mainboard/starlabs/starfighter/cmos.layout b/src/mainboard/starlabs/starfighter/cmos.layout index cdda7da26c..affe40fc4d 100644 --- a/src/mainboard/starlabs/starfighter/cmos.layout +++ b/src/mainboard/starlabs/starfighter/cmos.layout @@ -36,6 +36,7 @@ entries 608 1 e 1 fn_ctrl_swap 616 2 e 8 max_charge 624 2 e 9 fan_mode +632 2 e 11 charging_speed # coreboot config options: southbridge 800 2 e 6 power_on_after_fail @@ -101,6 +102,10 @@ enumerations 10 2 High 10 3 On +11 0 1.0C +11 1 0.5C +11 2 0.2C + # ----------------------------------------------------------------- checksums diff --git a/src/mainboard/starlabs/starlite_adl/Kconfig b/src/mainboard/starlabs/starlite_adl/Kconfig index fe07f16aae..5c3ff34e7b 100644 --- a/src/mainboard/starlabs/starlite_adl/Kconfig +++ b/src/mainboard/starlabs/starlite_adl/Kconfig @@ -1,6 +1,7 @@ config BOARD_STARLABS_STARLITE_SERIES def_bool n select DRIVERS_I2C_HID + select EC_STARLABS_CHARGING_SPEED select EC_STARLABS_ITE select EC_STARLABS_MAX_CHARGE select EC_STARLABS_MERLIN diff --git a/src/mainboard/starlabs/starlite_adl/cmos.default b/src/mainboard/starlabs/starlite_adl/cmos.default index c2c7adfe6a..a850e859c7 100644 --- a/src/mainboard/starlabs/starlite_adl/cmos.default +++ b/src/mainboard/starlabs/starlite_adl/cmos.default @@ -13,3 +13,5 @@ wireless=Enable webcam=Enable camera=Enable microphone=Enable +# EC +charging_speed=0.5C diff --git a/src/mainboard/starlabs/starlite_adl/cmos.layout b/src/mainboard/starlabs/starlite_adl/cmos.layout index 2f2ef41492..6ca539d612 100644 --- a/src/mainboard/starlabs/starlite_adl/cmos.layout +++ b/src/mainboard/starlabs/starlite_adl/cmos.layout @@ -33,6 +33,7 @@ entries # coreboot config options: EC 600 2 e 6 max_charge +608 2 e 11 charging_speed # coreboot config options: check sums 984 16 h 0 check_sum @@ -72,6 +73,10 @@ enumerations 6 1 80% 6 2 60% +7 0 1.0C +7 1 0.5C +7 2 0.2C + # ----------------------------------------------------------------- checksums