From 121ff627689834c4d0517ae151eb355ad548d285 Mon Sep 17 00:00:00 2001 From: Dtrain Hsu Date: Mon, 20 Jun 2022 14:38:43 +0800 Subject: mb/google/brya/var/kinox: Refactoring update_power_limits function Based on 'commit 0b917bde36a7 ("mb/google/brya/var/kinox: Set power limit based on charger type")' to refactoring update_power_limits function for kinox. BUG=b:231911918 TEST=Build and boot to Chrome OS Signed-off-by: Dtrain Hsu Change-Id: I1fcb593090f95bf23808e577dd11b8a836f47494 Reviewed-on: https://review.coreboot.org/c/coreboot/+/65242 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak Reviewed-by: Subrata Banik --- .../google/brya/variants/kinox/ramstage.c | 68 +++++++++++----------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/mainboard/google/brya/variants/kinox/ramstage.c b/src/mainboard/google/brya/variants/kinox/ramstage.c index 36f250e7b4..6df88c28df 100644 --- a/src/mainboard/google/brya/variants/kinox/ramstage.c +++ b/src/mainboard/google/brya/variants/kinox/ramstage.c @@ -79,50 +79,50 @@ const struct psys_config psys_config = { .bj_volts_mv = 20000 }; -static void change_power_limits(const struct cpu_power_limits *limits, size_t num_entries) -{ - variant_update_psys_power_limits(limits, sys_limits, num_entries, &psys_config); - variant_update_power_limits(limits, num_entries); -} - -static void update_power_limits(void) +static const struct cpu_power_limits *get_power_limit(size_t *total_entries) { enum usb_chg_type type; uint16_t volts_mv, current_ma, watts; - size_t total_entries; int rv = google_chromeec_get_usb_pd_power_info(&type, ¤t_ma, &volts_mv); - if (rv == 0) { - watts = ((uint32_t)current_ma * volts_mv) / 1000000; - printk(BIOS_INFO, "PL124: type: (%u) Current_ma: (%u) Volts_mv: (%u) Watts: (%u)\n", - type, current_ma, volts_mv, watts); - if (type == USB_CHG_TYPE_PROPRIETARY) { - if (watts == CHARGER_170W) { - printk(BIOS_INFO, "PL124: Performance.\n"); - total_entries = ARRAY_SIZE(perf_limits); - change_power_limits(perf_limits, total_entries); - } else { - printk(BIOS_INFO, "PL124: Baseline.\n"); - total_entries = ARRAY_SIZE(baseline_limits); - change_power_limits(baseline_limits, total_entries); - } + if (rv) { + printk(BIOS_INFO, "EC cmd failure: PL124: Baseline.\n"); + *total_entries = ARRAY_SIZE(baseline_limits); + return baseline_limits; + } + + watts = ((uint32_t)current_ma * volts_mv) / 1000000; + if (type == USB_CHG_TYPE_PROPRIETARY) { + if (watts == CHARGER_170W) { + printk(BIOS_INFO, "PL124: Performance.\n"); + *total_entries = ARRAY_SIZE(perf_limits); + return perf_limits; } else { - if (watts >= CHARGER_90W) { - printk(BIOS_INFO, "PL124: Performance.\n"); - total_entries = ARRAY_SIZE(perf_limits); - change_power_limits(perf_limits, total_entries); - } else { - printk(BIOS_INFO, "PL124: Baseline.\n"); - total_entries = ARRAY_SIZE(baseline_limits); - change_power_limits(baseline_limits, total_entries); - } + printk(BIOS_INFO, "PL124: Baseline.\n"); + *total_entries = ARRAY_SIZE(baseline_limits); + return baseline_limits; } } else { - printk(BIOS_INFO, "EC cmd failure: PL124: Baseline.\n"); - total_entries = ARRAY_SIZE(baseline_limits); - change_power_limits(baseline_limits, total_entries); + if (watts >= CHARGER_90W) { + printk(BIOS_INFO, "PL124: Performance.\n"); + *total_entries = ARRAY_SIZE(perf_limits); + return perf_limits; + } else { + printk(BIOS_INFO, "PL124: Baseline.\n"); + *total_entries = ARRAY_SIZE(baseline_limits); + return baseline_limits; + } } } +static void update_power_limits(void) +{ + size_t entries; + const struct cpu_power_limits *power_limit; + power_limit = get_power_limit(&entries); + variant_update_psys_power_limits(power_limit, sys_limits, entries, &psys_config); + variant_update_power_limits(power_limit, entries); +} + void variant_devtree_update(void) { update_power_limits(); -- cgit v1.2.3