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: @@ -436,6 +437,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; @@ -462,6 +469,12 @@ static void handle_acpi_write(int is_cmd) CPRINTF("\r[%T ACPI kblight %d]", data); 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", diff --git a/common/fan.c b/common/fan.c index 9d9c0f68fc..520d6fe03b 100644 --- a/common/fan.c +++ b/common/fan.c @@ -258,6 +258,36 @@ DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty, "Set fan duty cycle", 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 */ 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