summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Habibulla <moch@chromium.org>2014-10-02 14:36:16 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-10 18:26:11 +0000
commita1016ea5b23c2898f452b732d1086efcf3bc9f89 (patch)
treeee65799b3a80aa1d51d3a635a5c2cb15baeb85f3
parenta881f01694223e62ec572a98a233bf29d2628695 (diff)
downloadchrome-ec-a1016ea5b23c2898f452b732d1086efcf3bc9f89.tar.gz
CHERRY-PICK: 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: I5d63fd9cb6d24882ce2f197dc47111b9092c6853 Original-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> Reviewed-on: https://chromium-review.googlesource.com/222862
-rw-r--r--common/fan.c33
-rw-r--r--include/ec_commands.h9
-rw-r--r--util/ectool.c75
3 files changed, 96 insertions, 21 deletions
diff --git a/common/fan.c b/common/fan.c
index 7543d1e4d5..550a4cf305 100644
--- a/common/fan.c
+++ b/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)
{
- 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;
- /* TODO(crosbug.com/p/23803) */
- for (fan = 0; fan < CONFIG_FANS; fan++) {
- /* Always enable the fan */
- set_enabled(fan, 1);
+ if (args->version == 0) {
+ for (fan = 0; fan < CONFIG_FANS; fan++) {
+ /* 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->rpm);
+ set_thermal_control_enabled(fan, 0);
+ fan_set_rpm_mode(fans[fan].ch, 1);
+ 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;
}
DECLARE_HOST_COMMAND(EC_CMD_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)
{
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 1339d328eb..dcc097cc83 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -915,10 +915,17 @@ struct ec_response_pwm_get_fan_rpm {
/* Set target fan RPM */
#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;
} __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 */
#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
diff --git a/util/ectool.c b/util/ectool.c
index 657bac4a71..851f0f4d6b 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1450,27 +1450,80 @@ int cmd_pwm_get_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;
- int rv;
+ int rv, num_fans;
+ int cmdver = 1;
- if (argc != 2) {
- fprintf(stderr,
- "Usage: %s <targetrpm>\n", argv[0]);
+ if (!ec_cmd_version_supported(EC_CMD_PWM_SET_FAN_TARGET_RPM, cmdver)) {
+ struct ec_params_pwm_set_fan_target_rpm_v0 p_v0;
+
+ /* 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;
}
- p.rpm = strtol(argv[1], &e, 0);
+
+ num_fans = get_num_fans();
+ p_v1.rpm = strtol(argv[argc - 1], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad RPM.\n");
return -1;
}
- rv = ec_command(EC_CMD_PWM_SET_FAN_TARGET_RPM, 0,
- &p, sizeof(p), NULL, 0);
- if (rv < 0)
- return rv;
+ if (argc == 2) {
+ /* Reuse version 0 command if we're setting targetrpm
+ * for all fans */
+ 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;
}