summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-06-22 14:15:26 -0700
committerGerrit <chrome-bot@google.com>2012-06-22 15:56:57 -0700
commit80c635ecabdd398c20441cfd4dadb00c7eb76720 (patch)
tree604ec5789631b4f4514449c858d017f23e72fe73
parente61af38f55525177393a1e915fca45ef1c983411 (diff)
downloadchrome-ec-80c635ecabdd398c20441cfd4dadb00c7eb76720.tar.gz
Add 'fanduty' command both EC console and ectool.
This forces the fan PWM duty cycle to a fixed percentage (0-100). It's only used for airflow testing. BUG=chrome-os-partner:10747 TEST=manual Using this ectool, try ectool fanduty 0 ectool pwmgetfanrpm ectool fanduty 50 ectool pwmgetfanrpm ectool fanduty 100 ectool pwmgetfanrpm You should see (and hear) the fan speed up. If you have an EC console, you can run faninfo and it should show that the 'Target:' is unrelated to the 'Actual:' value. Change-Id: Iac332fb3ba63f96726cf7f64061b3ce22d2e76fd Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/25965 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/link/board.h3
-rw-r--r--chip/lm4/pwm.c41
-rw-r--r--common/pwm_commands.c10
-rw-r--r--include/ec_commands.h6
-rw-r--r--include/pwm.h3
-rw-r--r--util/ectool.c29
6 files changed, 71 insertions, 21 deletions
diff --git a/board/link/board.h b/board/link/board.h
index af771bdd81..793920cfe8 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -29,9 +29,6 @@
/* Enable the fake developer switch. See crosbug.com/p/8884 */
#define CONFIG_FAKE_DEV_SWITCH
-/* Enable direct fan PWM control. See crosbug.com/p/10747 */
-#define CONFIG_CONSOLE_CMD_FANDUTY
-
/* Fan PWM channels */
#define FAN_CH_CPU 0 /* CPU fan */
#define FAN_CH_KBLIGHT 1 /* Keyboard backlight */
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index 78c7bccdbc..fff33f03b3 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -9,6 +9,7 @@
#include "console.h"
#include "gpio.h"
#include "hooks.h"
+#include "host_command.h"
#include "lpc.h"
#include "ec_commands.h"
#include "pwm.h"
@@ -212,23 +213,11 @@ DECLARE_CONSOLE_COMMAND(fanset, command_fan_set,
"Set fan speed",
NULL);
-
-#ifdef CONFIG_CONSOLE_CMD_FANDUTY
-/* TODO: this is a temporary command for debugging tach issues */
-static int command_fan_duty(int argc, char **argv)
+int pwm_set_fan_duty(int percent)
{
- int d = 0, pwm;
- char *e;
-
- if (argc < 2)
- return EC_ERROR_PARAM_COUNT;
-
- d = strtoi(argv[1], &e, 0);
- if (*e)
- return EC_ERROR_PARAM1;
+ int pwm;
- pwm = (MAX_PWM * d) / 100;
- ccprintf("Setting fan duty cycle to %d%% = 0x%x...\n", d, pwm);
+ pwm = (MAX_PWM * percent) / 100;
/* Move the fan to manual control */
if (!(LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001)) {
@@ -248,12 +237,28 @@ static int command_fan_duty(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(fanduty, command_fan_duty,
+
+static int ec_command_fan_duty(int argc, char **argv)
+{
+ int percent = 0;
+ char *e;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ percent = strtoi(argv[1], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM1;
+
+ ccprintf("Setting fan duty cycle to %d%%\n", percent);
+ pwm_set_fan_duty(percent);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fanduty, ec_command_fan_duty,
"percent",
"Set fan duty cycle",
NULL);
-#endif
-
static int command_kblight(int argc, char **argv)
{
diff --git a/common/pwm_commands.c b/common/pwm_commands.c
index 523a803ce0..12de09b3d0 100644
--- a/common/pwm_commands.c
+++ b/common/pwm_commands.c
@@ -37,6 +37,16 @@ DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
pwm_command_set_fan_target_rpm);
+int pwm_command_fan_duty(uint8_t *data, int *resp_size)
+{
+ struct ec_params_pwm_set_fan_duty *p =
+ (struct ec_params_pwm_set_fan_duty *)data;
+ pwm_set_fan_duty(p->percent);
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY, pwm_command_fan_duty);
+
+
int pwm_command_get_keyboard_backlight(uint8_t *data, int *resp_size)
{
struct ec_response_pwm_get_keyboard_backlight *r =
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 02ad07eb20..3c8b8cb11c 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -381,6 +381,12 @@ struct ec_params_pwm_set_keyboard_backlight {
uint8_t percent;
} __attribute__ ((packed));
+/* Set target fan PWM duty cycle */
+#define EC_CMD_PWM_SET_FAN_DUTY 0x24
+struct ec_params_pwm_set_fan_duty {
+ uint32_t percent;
+} __attribute__ ((packed));
+
/*****************************************************************************/
/* Lightbar commands. This looks worse than it is. Since we only use one LPC
* command to say "talk to the lightbar", we put the "and tell it to do X"
diff --git a/include/pwm.h b/include/pwm.h
index 356b080532..0d21769233 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -23,6 +23,9 @@ int pwm_get_fan_target_rpm(void);
/* Set the target fan RPM. Pass -1 to set fan to maximum. */
int pwm_set_fan_target_rpm(int rpm);
+/* Set the fan PWM duty cycle (0-100), disabling the automatic control. */
+int pwm_set_fan_duty(int percent);
+
/* Enable/disable the keyboard backlight. */
int pwm_enable_keyboard_backlight(int enable);
diff --git a/util/ectool.c b/util/ectool.c
index cd1b3a293f..f608d952cb 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#include "battery.h"
+#include "board.h"
#include "comm-host.h"
#include "ec_commands.h"
#include "lightbar.h"
@@ -51,6 +52,8 @@ const char help_str[] =
" Sets the SMI mask for EC host events\n"
" eventsetwakemask <mask>\n"
" Sets the wake mask for EC host events\n"
+ " fanduty <percent>\n"
+ " Forces the fan PWM to a constant duty cycle\n"
" flasherase <offset> <size>\n"
" Erases EC flash\n"
" flashinfo\n"
@@ -797,6 +800,31 @@ int cmd_pwm_set_keyboard_backlight(int argc, char *argv[])
return 0;
}
+int cmd_fanduty(int argc, char *argv[])
+{
+ struct ec_params_pwm_set_fan_duty p;
+ char *e;
+ int rv;
+
+ if (argc != 2) {
+ fprintf(stderr,
+ "Usage: %s <targetrpm>\n", argv[0]);
+ return -1;
+ }
+ p.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,
+ &p, sizeof(p), NULL, 0);
+ if (rv)
+ return rv;
+
+ printf("Fan duty cycle set.\n");
+ return 0;
+}
#define LBMSG(state) #state
#include "lightbar_msg_list.h"
@@ -1556,6 +1584,7 @@ const struct command commands[] = {
{"eventsetscimask", cmd_host_event_set_sci_mask},
{"eventsetsmimask", cmd_host_event_set_smi_mask},
{"eventsetwakemask", cmd_host_event_set_wake_mask},
+ {"fanduty", cmd_fanduty},
{"flasherase", cmd_flash_erase},
{"flashread", cmd_flash_read},
{"flashwrite", cmd_flash_write},