summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-11-20 10:15:58 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-11-21 22:21:34 +0000
commitf7dba327a2b352babbd9d6bc2f6dbd2b3c02efdd (patch)
tree41b89af58a71db10bbbe42ee1fcffe32ce0697b7
parent24fdf4e554f542488ba268fece6e62b2014357fd (diff)
downloadchrome-ec-f7dba327a2b352babbd9d6bc2f6dbd2b3c02efdd.tar.gz
Add DPTF interface for fan duty
This adds include/dptf.h to define the DPTF interface functions. As the first DPTF feature, it also adds a register to the EC's ACPI interface block. Register 0x04 is used to get and set the fan's target duty cycle, as a percentage value. Writing a 0 to this register will set the target duty cycle to 0, writing a 100 (0x64) will set it to 100%. Writing any other value will return the fan control to the EC, rather than driving it manually from the host. Likewise, reading from this register returns the current fan target duty cycle, as a percentage. If the EC is controlling the fan automatically, the returned value will be 0xFF. BUG=chrome-os-partner:23972 BRANCH=none TEST=manual You can monitor the fan state from the EC console with the "faninfo" command. From the host side, test this interface from a root shell. Read fan duty: iotools io_write8 0x66 0x80 iotools io_write8 0x62 4 iotools io_read8 0x62 Set fan duty to 100%: iotools io_write8 0x66 0x81 iotools io_write8 0x62 4 iotools io_write8 0x62 100 Set fan duty to 50%: iotools io_write8 0x66 0x81 iotools io_write8 0x62 4 iotools io_write8 0x62 50 Set fan duty to 0%: iotools io_write8 0x66 0x81 iotools io_write8 0x62 4 iotools io_write8 0x62 0 Set fan control back to automatic: iotools io_write8 0x66 0x81 iotools io_write8 0x62 4 iotools io_write8 0x62 -1 Change-Id: I91ec463095cfd17adf452f0967da3944b254d558 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/177423 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/lm4/lpc.c15
-rw-r--r--common/fan.c30
-rw-r--r--include/dptf.h17
-rw-r--r--include/ec_commands.h2
4 files changed, 63 insertions, 1 deletions
diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c
index afbe31f717..0b9ec2771a 100644
--- a/chip/lm4/lpc.c
+++ b/chip/lm4/lpc.c
@@ -8,6 +8,7 @@
#include "clock.h"
#include "common.h"
#include "console.h"
+#include "dptf.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
@@ -412,7 +413,7 @@ static void handle_acpi_write(int is_cmd)
/* Process complete commands */
if (acpi_cmd == EC_CMD_ACPI_READ && acpi_data_count == 1) {
/* ACPI read cmd + addr */
- int result = 0;
+ int result = 0xff; /* value for bogus read */
switch (acpi_addr) {
case EC_ACPI_MEM_VERSION:
@@ -437,6 +438,12 @@ static void handle_acpi_write(int is_cmd)
result = pwm_get_duty(PWM_CH_KBLIGHT);
break;
#endif
+#ifdef CONFIG_FANS
+ case EC_ACPI_MEM_FAN_DUTY:
+ /** TODO(crosbug.com/p/23774): Fix this too */
+ result = dptf_get_fan_duty_target();
+ break;
+#endif
default:
break;
}
@@ -463,6 +470,12 @@ static void handle_acpi_write(int is_cmd)
pwm_set_duty(PWM_CH_KBLIGHT, data);
break;
#endif
+#ifdef CONFIG_FANS
+ case EC_ACPI_MEM_FAN_DUTY:
+ /** TODO(crosbug.com/p/23774): Fix this too */
+ dptf_set_fan_duty_target(data);
+ break;
+#endif
default:
CPRINTF("[%T ACPI write 0x%02x = 0x%02x]\n",
acpi_addr, data);
diff --git a/common/fan.c b/common/fan.c
index 9d9c0f68fc..520d6fe03b 100644
--- a/common/fan.c
+++ b/common/fan.c
@@ -259,6 +259,36 @@ DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty,
NULL);
/*****************************************************************************/
+/* DPTF interface functions */
+
+/* 0-100% if in duty mode. -1 if not */
+int dptf_get_fan_duty_target(void)
+{
+ int fan = 0; /* TODO(crosbug.com/p/23803) */
+
+ if (thermal_control_enabled[fan] || fan_get_rpm_mode(fan))
+ return -1;
+
+ return fan_get_duty(fan);
+}
+
+/* 0-100% sets duty, out of range means let the EC drive */
+void dptf_set_fan_duty_target(int pct)
+{
+ int fan;
+
+ if (pct < 0 || pct > 100) {
+ /* TODO(crosbug.com/p/23803) */
+ for (fan = 0; fan < CONFIG_FANS; fan++)
+ set_thermal_control_enabled(fan, 1);
+ } else {
+ /* TODO(crosbug.com/p/23803) */
+ for (fan = 0; fan < CONFIG_FANS; fan++)
+ set_duty_cycle(fan, pct);
+ }
+}
+
+/*****************************************************************************/
/* Host commands */
static int hc_pwm_get_fan_target_rpm(struct host_cmd_handler_args *args)
diff --git a/include/dptf.h b/include/dptf.h
new file mode 100644
index 0000000000..48be860f2d
--- /dev/null
+++ b/include/dptf.h
@@ -0,0 +1,17 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Functions used to provide the Intel DPTF interface over ACPI */
+
+#ifndef __CROS_EC_DPTF_H
+#define __CROS_EC_DPTF_H
+
+/* 0-100% sets fixed duty cycle, out of range means let the EC drive */
+void dptf_set_fan_duty_target(int pct);
+
+/* 0-100% if in duty mode. -1 if not */
+int dptf_get_fan_duty_target(void);
+
+#endif /* __CROS_EC_DPTF_H */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index b1e3ed887b..b97ef7dc48 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1866,6 +1866,8 @@ struct ec_params_reboot_ec {
#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
/* Keyboard backlight brightness percent (0 - 100) */
#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
+/* Target Fan Duty (0-100, 0xff for auto/none) */
+#define EC_ACPI_MEM_FAN_DUTY 0x04
/* Current version of ACPI memory address space */
#define EC_ACPI_MEM_VERSION_CURRENT 1