mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
ectool: Add host command support to set fan RPM for each fan separately
First case is for legacy support ectool pwmsetfanrpm <targetrpm> - set all fans to <targetrpm> ectool pwmsetfanrpm <fan> <targetrpm> - set <fan> to <targetrpm> BUG=chrome-os-partner:23803 TEST=Tested the above EC commands on Auron BRANCH=none CQ-DEPEND=CL:220960 Change-Id: I8f447f53289abaa9c5cc1285f9f0921328fbf32c Signed-off-by: Mohammed Habibulla <moch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221291 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
f93c3e83e4
commit
7b1e58cc43
33
common/fan.c
33
common/fan.c
@@ -308,24 +308,39 @@ DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_TARGET_RPM,
|
|||||||
|
|
||||||
static int hc_pwm_set_fan_target_rpm(struct host_cmd_handler_args *args)
|
static int hc_pwm_set_fan_target_rpm(struct host_cmd_handler_args *args)
|
||||||
{
|
{
|
||||||
const struct ec_params_pwm_set_fan_target_rpm *p = args->params;
|
const struct ec_params_pwm_set_fan_target_rpm_v1 *p_v1 = args->params;
|
||||||
|
const struct ec_params_pwm_set_fan_target_rpm_v0 *p_v0 = args->params;
|
||||||
int fan;
|
int fan;
|
||||||
|
|
||||||
/* TODO(crosbug.com/p/23803) */
|
if (args->version == 0) {
|
||||||
for (fan = 0; fan < CONFIG_FANS; fan++) {
|
for (fan = 0; fan < CONFIG_FANS; fan++) {
|
||||||
/* Always enable the fan */
|
/* Always enable the fan */
|
||||||
set_enabled(fan, 1);
|
set_enabled(fan, 1);
|
||||||
|
|
||||||
set_thermal_control_enabled(fan, 0);
|
set_thermal_control_enabled(fan, 0);
|
||||||
fan_set_rpm_mode(fans[fan].ch, 1);
|
fan_set_rpm_mode(fans[fan].ch, 1);
|
||||||
fan_set_rpm_target(fans[fan].ch, p->rpm);
|
fan_set_rpm_target(fans[fan].ch, p_v0->rpm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EC_RES_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fan = p_v1->fan_idx;
|
||||||
|
if (fan >= CONFIG_FANS)
|
||||||
|
return EC_RES_ERROR;
|
||||||
|
|
||||||
|
/* Always enable the fan */
|
||||||
|
set_enabled(fan, 1);
|
||||||
|
|
||||||
|
set_thermal_control_enabled(fan, 0);
|
||||||
|
fan_set_rpm_mode(fans[fan].ch, 1);
|
||||||
|
fan_set_rpm_target(fans[fan].ch, p_v1->rpm);
|
||||||
|
|
||||||
return EC_RES_SUCCESS;
|
return EC_RES_SUCCESS;
|
||||||
}
|
}
|
||||||
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
|
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
|
||||||
hc_pwm_set_fan_target_rpm,
|
hc_pwm_set_fan_target_rpm,
|
||||||
EC_VER_MASK(0));
|
EC_VER_MASK(0) | EC_VER_MASK(1));
|
||||||
|
|
||||||
static int hc_pwm_set_fan_duty(struct host_cmd_handler_args *args)
|
static int hc_pwm_set_fan_duty(struct host_cmd_handler_args *args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -915,10 +915,17 @@ struct ec_response_pwm_get_fan_rpm {
|
|||||||
/* Set target fan RPM */
|
/* Set target fan RPM */
|
||||||
#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
|
#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
|
||||||
|
|
||||||
struct ec_params_pwm_set_fan_target_rpm {
|
/* Version 0 of input params */
|
||||||
|
struct ec_params_pwm_set_fan_target_rpm_v0 {
|
||||||
uint32_t rpm;
|
uint32_t rpm;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
|
/* Version 1 of input params */
|
||||||
|
struct ec_params_pwm_set_fan_target_rpm_v1 {
|
||||||
|
uint32_t rpm;
|
||||||
|
uint8_t fan_idx;
|
||||||
|
} __packed;
|
||||||
|
|
||||||
/* Get keyboard backlight */
|
/* Get keyboard backlight */
|
||||||
#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
|
#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
|
||||||
|
|
||||||
|
|||||||
@@ -1474,27 +1474,80 @@ int cmd_pwm_get_fan_rpm(int argc, char *argv[])
|
|||||||
|
|
||||||
int cmd_pwm_set_fan_rpm(int argc, char *argv[])
|
int cmd_pwm_set_fan_rpm(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct ec_params_pwm_set_fan_target_rpm p;
|
struct ec_params_pwm_set_fan_target_rpm_v1 p_v1;
|
||||||
char *e;
|
char *e;
|
||||||
int rv;
|
int rv, num_fans;
|
||||||
|
int cmdver = 1;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (!ec_cmd_version_supported(EC_CMD_PWM_SET_FAN_TARGET_RPM, cmdver)) {
|
||||||
fprintf(stderr,
|
struct ec_params_pwm_set_fan_target_rpm_v0 p_v0;
|
||||||
"Usage: %s <targetrpm>\n", argv[0]);
|
|
||||||
|
/* Fall back to command version 0 command */
|
||||||
|
cmdver = 0;
|
||||||
|
|
||||||
|
if (argc != 2) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Usage: %s <targetrpm>\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
p_v0.rpm = strtol(argv[1], &e, 0);
|
||||||
|
if (e && *e) {
|
||||||
|
fprintf(stderr, "Bad RPM.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = ec_command(EC_CMD_PWM_SET_FAN_TARGET_RPM, cmdver,
|
||||||
|
&p_v0, sizeof(p_v0), NULL, 0);
|
||||||
|
if (rv < 0)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
printf("Fan target RPM set for all fans.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 3 || (argc == 2 && !strcmp(argv[1], "help")) || argc == 1) {
|
||||||
|
printf("Usage: %s [idx] <targetrpm>\n", argv[0]);
|
||||||
|
printf("'pwmfansetrpm 0 3000' - Set fan 0 RPM to 3000\n");
|
||||||
|
printf("'pwmfansetrpm 3000' - Set all fans RPM to 3000\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
p.rpm = strtol(argv[1], &e, 0);
|
|
||||||
|
num_fans = get_num_fans();
|
||||||
|
p_v1.rpm = strtol(argv[argc - 1], &e, 0);
|
||||||
if (e && *e) {
|
if (e && *e) {
|
||||||
fprintf(stderr, "Bad RPM.\n");
|
fprintf(stderr, "Bad RPM.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = ec_command(EC_CMD_PWM_SET_FAN_TARGET_RPM, 0,
|
if (argc == 2) {
|
||||||
&p, sizeof(p), NULL, 0);
|
/* Reuse version 0 command if we're setting targetrpm
|
||||||
if (rv < 0)
|
* for all fans */
|
||||||
return rv;
|
struct ec_params_pwm_set_fan_target_rpm_v0 p_v0;
|
||||||
|
|
||||||
|
cmdver = 0;
|
||||||
|
p_v0.rpm = p_v1.rpm;
|
||||||
|
|
||||||
|
rv = ec_command(EC_CMD_PWM_SET_FAN_TARGET_RPM, cmdver,
|
||||||
|
&p_v0, sizeof(p_v0), NULL, 0);
|
||||||
|
if (rv < 0)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
printf("Fan target RPM set for all fans.\n");
|
||||||
|
} else {
|
||||||
|
p_v1.fan_idx = strtol(argv[1], &e, 0);
|
||||||
|
if ((e && *e) || (p_v1.fan_idx >= num_fans)) {
|
||||||
|
fprintf(stderr, "Bad fan index.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = ec_command(EC_CMD_PWM_SET_FAN_TARGET_RPM, cmdver,
|
||||||
|
&p_v1, sizeof(p_v1), NULL, 0);
|
||||||
|
if (rv < 0)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
printf("Fan %d target RPM set.\n", p_v1.fan_idx);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Fan target RPM set.\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user