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 <dtrain_hsu@compal.corp-partner.google.com>
Change-Id: I1fcb593090f95bf23808e577dd11b8a836f47494
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65242
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Subrata Banik <subratabanik@google.com>
diff --git a/src/mainboard/google/brya/variants/kinox/ramstage.c b/src/mainboard/google/brya/variants/kinox/ramstage.c
index 36f250e..6df88c2 100644
--- a/src/mainboard/google/brya/variants/kinox/ramstage.c
+++ b/src/mainboard/google/brya/variants/kinox/ramstage.c
@@ -79,48 +79,48 @@
.bj_volts_mv = 20000
};
-static void change_power_limits(const struct cpu_power_limits *limits, size_t num_entries)
+static const struct cpu_power_limits *get_power_limit(size_t *total_entries)
{
- variant_update_psys_power_limits(limits, sys_limits, num_entries, &psys_config);
- variant_update_power_limits(limits, num_entries);
+ enum usb_chg_type type;
+ uint16_t volts_mv, current_ma, watts;
+ int rv = google_chromeec_get_usb_pd_power_info(&type, ¤t_ma, &volts_mv);
+ 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 {
+ printk(BIOS_INFO, "PL124: Baseline.\n");
+ *total_entries = ARRAY_SIZE(baseline_limits);
+ return baseline_limits;
+ }
+ } else {
+ 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)
{
- 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);
- }
- } 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);
- }
- }
- } else {
- printk(BIOS_INFO, "EC cmd failure: PL124: Baseline.\n");
- total_entries = ARRAY_SIZE(baseline_limits);
- change_power_limits(baseline_limits, total_entries);
- }
+ 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)