Skip to content

Commit 5baa1ff

Browse files
committed
Reintroduce cpupower to set PL1, PL2 and PL4 manually, or restore default values
Update maximum fan speed
1 parent 824fc47 commit 5baa1ff

7 files changed

Lines changed: 129 additions & 24 deletions

File tree

baseboard/fwk/fan.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ int fan_rpm_to_percent(int fan, int rpm)
104104
* if we want a performance mode we can tweak this
105105
* to get a few more % of fan speed to unlock additional
106106
* cooling TODO FRAMEWORK */
107-
// FAN_HARDARE_MAX = 7100
108-
// Tested max : 7900 RPM on flat surface, 8800 RPM when intake blocked
109-
pct = (rpm - min) / ((FAN_HARDARE_MAX - min) / 100);
107+
// original FAN_HARDARE_MAX = 7100
108+
// Tested max : 7400 RPM on flat surface, 8500 RPM when intake blocked
109+
pct = (rpm - min) / ((max - min) / 100);
110110
/*CPRINTS(" Fan max min : %d , %d", max, min);*/
111111
}
112112
/*CPRINTS(" Fan PCT = %d ", pct);*/
@@ -185,7 +185,7 @@ void fan_set_rpm_target(int ch, int rpm)
185185
rpm_setting[ch] = rpm;
186186
if (chipset_in_state(CHIPSET_STATE_ON) && rpm == 0 &&
187187
!timestamp_expired(fan_spindown_time, NULL)) {
188-
rpm = 1200;
188+
rpm = fans[0].rpm->rpm_min;
189189
}
190190

191191
pct = fan_rpm_to_percent(ch, rpm);

board/hx20/board.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ const struct fan_conf fan_conf_0 = {
973973

974974
/* Default */
975975
const struct fan_rpm fan_rpm_0 = {
976-
.rpm_min = 1800,
977-
.rpm_start = 1800,
978-
.rpm_max = 6800, /* Todo: Derate by -7% so all units have same performance */
976+
.rpm_min = 1200,
977+
.rpm_start = 1200,
978+
.rpm_max = 7400,
979979
};
980980

981981
const struct fan_t fans[FAN_CH_COUNT] = {

board/hx20/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
#define CONFIG_FANS 1
395395
#undef CONFIG_FAN_INIT_SPEED
396396
#define CONFIG_FAN_INIT_SPEED 15
397-
#define FAN_HARDARE_MAX 7100
397+
#define FAN_HARDARE_MAX 7400
398398
#define CONFIG_TEMP_SENSOR
399399
#define CONFIG_DPTF
400400
#define CONFIG_TEMP_SENSOR_F75303

board/hx20/cpu_power.c

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,23 @@
2121
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
2222
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
2323

24-
#define POWER_LIMIT_1_W 50
25-
26-
static int pl1_watt;
27-
static int pl2_watt;
28-
static int pl4_watt;
24+
// Loaded on EC reset
25+
#define POWER_LIMIT_1_W_DEFAULT 40
26+
#define POWER_LIMIT_2_W_DEFAULT 64
27+
#define POWER_LIMIT_4_W_DEFAULT 121
28+
29+
// Loaded by ectool command "cpupower default"
30+
#define POWER_LIMIT_1_W_USER_DEFAULT 28
31+
#define POWER_LIMIT_2_W_USER_DEFAULT 64
32+
#define POWER_LIMIT_4_W_USER_DEFAULT 121
33+
34+
static int POWER_LIMIT_1_W = POWER_LIMIT_1_W_DEFAULT;
35+
static int POWER_LIMIT_2_W = POWER_LIMIT_2_W_DEFAULT;
36+
static int POWER_LIMIT_4_W = POWER_LIMIT_4_W_DEFAULT;
37+
38+
static int pl1_watt = POWER_LIMIT_1_W_DEFAULT;
39+
static int pl2_watt = POWER_LIMIT_2_W_DEFAULT;
40+
static int pl4_watt = POWER_LIMIT_4_W_DEFAULT;
2941
static int psys_watt;
3042
bool manual_ctl;
3143

@@ -47,6 +59,7 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)
4759
int pps_power_budget;
4860
int battery_percent;
4961

62+
static int old_pl1_watt = -1;
5063
static int old_pl2_watt = -1;
5164
static int old_pl4_watt = -1;
5265
static int old_psys_watt = -1;
@@ -72,23 +85,23 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)
7285
psys_watt = ((active_power * 95) / 100) - pps_power_budget;
7386
} else {
7487
/* ADP > 55W and Battery percentage >= 30% */
75-
pl2_watt = 64;
76-
pl4_watt = 121;
88+
pl1_watt = POWER_LIMIT_1_W;
89+
pl2_watt = POWER_LIMIT_2_W;
90+
pl4_watt = POWER_LIMIT_4_W;
7791
/* psys watt = adp watt * 0.95 + battery watt(55 W) * 0.7 - pps power budget */
7892
psys_watt = ((active_power * 95) / 100) + 39 - pps_power_budget;
7993
}
8094
if (pl2_watt != old_pl2_watt || pl4_watt != old_pl4_watt ||
81-
psys_watt != old_psys_watt || force_update) {
95+
psys_watt != old_psys_watt || force_update ||
96+
pl1_watt != old_pl1_watt) {
97+
old_pl1_watt = pl1_watt;
8298
old_psys_watt = psys_watt;
8399
old_pl4_watt = pl4_watt;
84100
old_pl2_watt = pl2_watt;
85101

86-
pl1_watt = POWER_LIMIT_1_W;
87-
if (manual_ctl == false) {
88-
CPRINTS("Updating SOC Power Limits: PL2 %d, PL4 %d, Psys %d, Adapter %d",
89-
pl2_watt, pl4_watt, psys_watt, active_power);
90-
set_pl_limits(pl1_watt, pl2_watt, pl4_watt, psys_watt);
91-
}
102+
CPRINTS("Updating SOC Power Limits: PL1 %d, PL2 %d, PL4 %d, Psys %d, Adapter %d",
103+
pl1_watt, pl2_watt, pl4_watt, psys_watt, active_power);
104+
set_pl_limits(pl1_watt, pl2_watt, pl4_watt, psys_watt);
92105
}
93106
}
94107

@@ -179,3 +192,41 @@ static int cmd_fan_mode(int argc, char **argv)
179192
DECLARE_CONSOLE_COMMAND(fanmode, cmd_fan_mode,
180193
"[silent|normal|extreme]",
181194
"Set/Get fan mode");
195+
196+
/* Host command handler for CPU power limits */
197+
static enum ec_status host_command_cpu_power(struct host_cmd_handler_args *args)
198+
{
199+
const struct ec_params_cpu_power *p = args->params;
200+
struct ec_response_cpu_power *r = args->response;
201+
202+
/* If parameters provided, set the values */
203+
if (args->params_size > 0 && p) {
204+
/*
205+
* "default" from ectool is encoded as an all-zero payload.
206+
*/
207+
if (p->pl1_mW == 0 && p->pl2_mW == 0 && p->pl4_mW == 0) {
208+
POWER_LIMIT_1_W = POWER_LIMIT_1_W_USER_DEFAULT;
209+
POWER_LIMIT_2_W = POWER_LIMIT_2_W_USER_DEFAULT;
210+
POWER_LIMIT_4_W = POWER_LIMIT_4_W_USER_DEFAULT;
211+
} else {
212+
if (p->pl1_mW != 0)
213+
POWER_LIMIT_1_W = p->pl1_mW / 1000;
214+
if (p->pl2_mW != 0)
215+
POWER_LIMIT_2_W = p->pl2_mW / 1000;
216+
if (p->pl4_mW != 0)
217+
POWER_LIMIT_4_W = p->pl4_mW / 1000;
218+
}
219+
update_soc_power_limit(true, false);
220+
}
221+
222+
/* Return current power limits in mW */
223+
r->pl1_mW = pl1_watt * 1000;
224+
r->pl2_mW = pl2_watt * 1000;
225+
r->pl4_mW = pl4_watt * 1000;
226+
r->psys_mW = psys_watt * 1000;
227+
228+
args->response_size = sizeof(*r);
229+
return EC_RES_SUCCESS;
230+
}
231+
232+
DECLARE_HOST_COMMAND(EC_CMD_CPU_POWER, host_command_cpu_power, EC_VER_MASK(0));

board/hx30/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
/*#define CONFIG_FAN_RPM_CUSTOM*/
412412
#undef CONFIG_FAN_INIT_SPEED
413413
#define CONFIG_FAN_INIT_SPEED 15
414-
#define FAN_HARDARE_MAX 7900
414+
#define FAN_HARDARE_MAX 7100
415415
#define CONFIG_TEMP_SENSOR
416416
#define CONFIG_DPTF
417417
#define CONFIG_TEMP_SENSOR_F75303

include/ec_commands.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6982,6 +6982,27 @@ struct ec_response_fan_mode {
69826982
uint8_t mode; /* Current fan mode */
69836983
} __ec_align1;
69846984

6985+
/*****************************************************************************/
6986+
/*
6987+
* CPU Power command
6988+
* Get/set CPU power limits
6989+
*/
6990+
#define EC_CMD_CPU_POWER 0x03D6
6991+
6992+
struct ec_params_cpu_power {
6993+
uint32_t pl1_mW; /* PL1 power in milliwatts (0 = query only) */
6994+
uint32_t pl2_mW; /* PL2 power in milliwatts (0 = query only) */
6995+
uint32_t pl4_mW; /* PL4 power in milliwatts (0 = query only) */
6996+
} __ec_align4;
6997+
6998+
struct ec_response_cpu_power {
6999+
uint32_t pl1_mW; /* Current PL1 in mW */
7000+
uint32_t pl2_mW; /* Current PL2 in mW */
7001+
uint32_t pl4_mW; /* Current PL4 in mW */
7002+
uint32_t psys_mW; /* Current Psys in mW */
7003+
} __ec_align4;
7004+
7005+
69857006
/****************************************************************************/
69867007
/*
69877008
* Reserve a range of host commands for board-specific, experimental, or

util/ectool.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const char help_str[] =
9494
" chargestate\n"
9595
" Handle commands related to charge state v2 (and later)\n"
9696
" cpupower\n"
97-
" Get CPU power limits (PL1, PL2, PL4, Psys)\n"
97+
" Get or set CPU power limits (PL1, PL2, PL4, default)\n"
9898
" chipinfo\n"
9999
" Prints chip info\n"
100100
" cmdversions <cmd>\n"
@@ -129,6 +129,8 @@ const char help_str[] =
129129
" Set the maximum external power limit\n"
130130
" fanduty <percent>\n"
131131
" Forces the fan PWM to a constant duty cycle\n"
132+
" fanmode [mode]\n"
133+
" Prints or sets fan curve profile\n"
132134
" flasherase <offset> <size>\n"
133135
" Erases EC flash\n"
134136
" flasheraseasync <offset> <size>\n"
@@ -600,6 +602,36 @@ static int cmd_fan_mode(int argc, char *argv[])
600602
return 0;
601603
}
602604

605+
static int cmd_cpu_power(int argc, char *argv[])
606+
{
607+
struct ec_params_cpu_power p = {};
608+
struct ec_response_cpu_power r;
609+
int rv;
610+
611+
/* A default reset is encoded as an all-zero payload. */
612+
if (argc == 2 && !strcasecmp(argv[1], "default")) {
613+
rv = ec_command(EC_CMD_CPU_POWER, 0, &p, sizeof(p), &r, sizeof(r));
614+
} else if (argc >= 4) {
615+
p.pl1_mW = strtol(argv[1], NULL, 0) * 1000;
616+
p.pl2_mW = strtol(argv[2], NULL, 0) * 1000;
617+
p.pl4_mW = strtol(argv[3], NULL, 0) * 1000;
618+
rv = ec_command(EC_CMD_CPU_POWER, 0, &p, sizeof(p), &r, sizeof(r));
619+
} else {
620+
/* Query only */
621+
rv = ec_command(EC_CMD_CPU_POWER, 0, NULL, 0, &r, sizeof(r));
622+
}
623+
624+
if (rv < 0)
625+
return rv;
626+
627+
printf("CPU Power Limits:\n");
628+
printf(" PL1: %u W\n", r.pl1_mW / 1000);
629+
printf(" PL2: %u W\n", r.pl2_mW / 1000);
630+
printf(" PL4: %u W\n", r.pl4_mW / 1000);
631+
printf(" Psys: %u W\n", r.psys_mW / 1000);
632+
return 0;
633+
}
634+
603635
static void cmd_hostevent_help(char *cmd)
604636
{
605637
fprintf(stderr,
@@ -10163,6 +10195,7 @@ const struct command commands[] = {
1016310195
{"chipinfo", cmd_chipinfo},
1016410196
{"cmdversions", cmd_cmdversions},
1016510197
{"console", cmd_console},
10198+
{"cpupower", cmd_cpu_power},
1016610199
{"cec", cmd_cec},
1016710200
{"echash", cmd_ec_hash},
1016810201
{"eventclear", cmd_host_event_clear},

0 commit comments

Comments
 (0)