ectool: Add hostcmd support to set fan duty cycle for each fan separately

ectool fanduty <percent>	- set all fans to <percent> duty cycle
ectool fanduty <fan> <percent>	- set <fan> to <percent> duty cycle

BUG=chrome-os-partner:23803
TEST=Tested the above EC commands on Auron
BRANCH=none

Change-Id: I06ca1552bd8f3412f6e90245da302c9f86ab6103
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221505
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Mohammed Habibulla
2014-10-03 16:45:33 -07:00
committed by chrome-internal-fetch
parent e541eeb294
commit 876b0f0bdc
3 changed files with 86 additions and 16 deletions

View File

@@ -344,18 +344,28 @@ DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
static int hc_pwm_set_fan_duty(struct host_cmd_handler_args *args)
{
const struct ec_params_pwm_set_fan_duty *p = args->params;
const struct ec_params_pwm_set_fan_duty_v1 *p_v1 = args->params;
const struct ec_params_pwm_set_fan_duty_v0 *p_v0 = args->params;
int fan;
/* TODO(crosbug.com/p/23803) */
for (fan = 0; fan < CONFIG_FANS; fan++)
set_duty_cycle(fan, p->percent);
if (args->version == 0) {
for (fan = 0; fan < CONFIG_FANS; fan++)
set_duty_cycle(fan, p_v0->percent);
return EC_RES_SUCCESS;
}
fan = p_v1->fan_idx;
if (fan >= CONFIG_FANS)
return EC_RES_ERROR;
set_duty_cycle(fan, p_v1->percent);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY,
hc_pwm_set_fan_duty,
EC_VER_MASK(0));
EC_VER_MASK(0) | EC_VER_MASK(1));
static int hc_thermal_auto_fan_ctrl(struct host_cmd_handler_args *args)
{

View File

@@ -944,10 +944,17 @@ struct ec_params_pwm_set_keyboard_backlight {
/* Set target fan PWM duty cycle */
#define EC_CMD_PWM_SET_FAN_DUTY 0x24
struct ec_params_pwm_set_fan_duty {
/* Version 0 of input params */
struct ec_params_pwm_set_fan_duty_v0 {
uint32_t percent;
} __packed;
/* Version 1 of input params */
struct ec_params_pwm_set_fan_duty_v1 {
uint32_t percent;
uint8_t fan_idx;
} __packed;
/*****************************************************************************/
/*
* Lightbar commands. This looks worse than it is. Since we only use one HOST

View File

@@ -1598,26 +1598,79 @@ int cmd_pwm_set_keyboard_backlight(int argc, char *argv[])
int cmd_fanduty(int argc, char *argv[])
{
struct ec_params_pwm_set_fan_duty p;
struct ec_params_pwm_set_fan_duty_v1 p_v1;
char *e;
int rv;
int rv, num_fans;
int cmdver = 1;
if (argc != 2) {
fprintf(stderr,
"Usage: %s <percent>\n", argv[0]);
if (!ec_cmd_version_supported(EC_CMD_PWM_SET_FAN_DUTY, cmdver)) {
struct ec_params_pwm_set_fan_duty_v0 p_v0;
if (argc != 2) {
fprintf(stderr,
"Usage: %s <percent>\n", argv[0]);
return -1;
}
p_v0.percent = strtol(argv[1], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad percent arg.\n");
return -1;
}
rv = ec_command(EC_CMD_PWM_SET_FAN_DUTY, 0,
&p_v0, sizeof(p_v0), NULL, 0);
if (rv < 0)
return rv;
printf("Fan duty cycle set.\n");
return 0;
}
if (argc > 3 || (argc == 2 && !strcmp(argv[1], "help")) || argc == 1) {
printf("Usage: %s [idx] <percent>\n", argv[0]);
printf("'%s 0 50' - Set fan 0 duty cycle to 50 percent\n",
argv[0]);
printf("'%s 30' - Set all fans duty cycle to 30 percent\n",
argv[0]);
return -1;
}
p.percent = strtol(argv[1], &e, 0);
num_fans = get_num_fans();
p_v1.percent = strtol(argv[argc - 1], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad percent arg.\n");
return -1;
}
rv = ec_command(EC_CMD_PWM_SET_FAN_DUTY, 0, &p, sizeof(p), NULL, 0);
if (rv < 0)
return rv;
if (argc == 2) {
/* Reuse version 0 command if we're setting duty cycle
* for all fans */
struct ec_params_pwm_set_fan_duty_v0 p_v0;
cmdver = 0;
p_v0.percent = p_v1.percent;
rv = ec_command(EC_CMD_PWM_SET_FAN_DUTY, cmdver,
&p_v0, sizeof(p_v0), NULL, 0);
if (rv < 0)
return rv;
printf("Fan duty cycle 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_DUTY, cmdver,
&p_v1, sizeof(p_v1), NULL, 0);
if (rv < 0)
return rv;
printf("Fan %d duty cycle set.\n", p_v1.fan_idx);
}
printf("Fan duty cycle set.\n");
return 0;
}