diff options
author | Mohammed Habibulla <moch@chromium.org> | 2014-10-03 16:45:33 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-10-10 18:48:21 +0000 |
commit | 430eea334a2ad2050ebfd3348f91d760b171a6b3 (patch) | |
tree | 2975a597f30016b7beb421a3f5b410d1eaa54e6e | |
parent | 76b57daa9c3eaef6b30a789fc7ce319eb8b59f73 (diff) | |
download | chrome-ec-430eea334a2ad2050ebfd3348f91d760b171a6b3.tar.gz |
CHERRY-PICK: 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: I4864b7bd65076ec480e5657daefaf165110f3976
Original-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>
Reviewed-on: https://chromium-review.googlesource.com/222863
-rw-r--r-- | common/fan.c | 20 | ||||
-rw-r--r-- | include/ec_commands.h | 9 | ||||
-rw-r--r-- | util/ectool.c | 73 |
3 files changed, 86 insertions, 16 deletions
diff --git a/common/fan.c b/common/fan.c index 2e25f200b4..db0b9a0d86 100644 --- a/common/fan.c +++ b/common/fan.c @@ -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) { diff --git a/include/ec_commands.h b/include/ec_commands.h index f6e009f17d..5d54a6e576 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -944,8 +944,15 @@ 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; /*****************************************************************************/ diff --git a/util/ectool.c b/util/ectool.c index 57e0cc4463..c62cf26105 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1583,26 +1583,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; } |