mb/starlabs/labtop: Add enum for `power_profile`

Introduce and use an enum for the `power_profile` CMOS option. Add a
helper function that converts CMOS values into enum values. Using an
enum allows GCC to warn about switch statements using enum types for
their control expressions not handling all possible enum values, and
also improves readability.

Change-Id: I47a453ea12d164d26908a9944a89a481757e753c
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/60212
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Sean Rhodes <admin@starlabs.systems>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
This commit is contained in:
Angel Pons 2021-12-18 13:26:09 +01:00
parent a2c10a2539
commit 4b9ac2c993
3 changed files with 29 additions and 14 deletions

View File

@ -5,6 +5,15 @@
#include <soc/gpio.h>
enum cmos_power_profile {
PP_POWER_SAVER = 0,
PP_BALANCED = 1,
PP_PERFORMANCE = 2,
};
#define NUM_POWER_PROFILES 3
enum cmos_power_profile get_power_profile(enum cmos_power_profile fallback);
/*
* The next set of functions return the gpio table and fill in the number of
* entries for each table.

View File

@ -5,6 +5,12 @@
#include <option.h>
#include <variants.h>
enum cmos_power_profile get_power_profile(enum cmos_power_profile fallback)
{
const unsigned int power_profile = get_uint_option("power_profile", fallback);
return power_profile < NUM_POWER_PROFILES ? power_profile : fallback;
}
static void init_mainboard(void *chip_info)
{
const struct pad_config *pads;

View File

@ -24,26 +24,26 @@ void devtree_update(void)
/* Update PL1 & PL2 based on CMOS settings */
switch (get_uint_option("power_profile", 0)) {
case 1:
soc_conf_2core->tdp_pl1_override = 15;
soc_conf_4core->tdp_pl1_override = 15;
soc_conf_2core->tdp_pl2_override = 25;
soc_conf_4core->tdp_pl2_override = 25;
break;
case 2:
soc_conf_2core->tdp_pl1_override = 28;
soc_conf_4core->tdp_pl1_override = 28;
soc_conf_2core->tdp_pl2_override = 40;
soc_conf_4core->tdp_pl2_override = 40;
break;
default:
switch (get_power_profile(PP_POWER_SAVER)) {
case PP_POWER_SAVER:
disable_turbo();
soc_conf_2core->tdp_pl1_override = 15;
soc_conf_4core->tdp_pl1_override = 15;
soc_conf_2core->tdp_pl2_override = 15;
soc_conf_4core->tdp_pl2_override = 15;
break;
case PP_BALANCED:
soc_conf_2core->tdp_pl1_override = 15;
soc_conf_4core->tdp_pl1_override = 15;
soc_conf_2core->tdp_pl2_override = 25;
soc_conf_4core->tdp_pl2_override = 25;
break;
case PP_PERFORMANCE:
soc_conf_2core->tdp_pl1_override = 28;
soc_conf_4core->tdp_pl1_override = 28;
soc_conf_2core->tdp_pl2_override = 40;
soc_conf_4core->tdp_pl2_override = 40;
break;
}
/* Enable/Disable Wireless based on CMOS settings */