mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-11 18:35:28 +00:00
Add EC host command to control fan speed.
Add LPC host command to get and set fan speed. BUG=chrome-os-partner:7313 TEST=Connect a fan and manually test fan actual speed matches target speed. Change-Id: I4b6a711a1b8cca0dbd1c1936fe4f0f15240d3453
This commit is contained in:
@@ -4,4 +4,5 @@
|
||||
|
||||
common-objs=main.o util.o console.o vboot.o
|
||||
common-objs+=flash_commands.o host_command.o port80.o keyboard.o i8042.o
|
||||
common-objs+=memory_commands.o shared_mem.o temp_sensor_commands.o
|
||||
common-objs+=memory_commands.o shared_mem.o temp_sensor_commands.o pwm_commands.o
|
||||
common-objs+=memory_commands.o shared_mem.o pwm_commands.o
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "flash_commands.h"
|
||||
#include "host_command.h"
|
||||
#include "temp_sensor_commands.h"
|
||||
#include "pwm_commands.h"
|
||||
#include "lpc.h"
|
||||
#include "lpc_commands.h"
|
||||
#include "system.h"
|
||||
@@ -176,6 +177,12 @@ static void command_process(int slot)
|
||||
case EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS:
|
||||
lpc_send_host_response(slot, temp_sensor_command_get_readings(data));
|
||||
return;
|
||||
case EC_LPC_COMMAND_PWM_GET_FAN_RPM:
|
||||
lpc_send_host_response(slot, pwm_command_get_fan_rpm(data));
|
||||
return;
|
||||
case EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM:
|
||||
lpc_send_host_response(slot, pwm_command_set_fan_target_rpm(data));
|
||||
return;
|
||||
default:
|
||||
lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND);
|
||||
}
|
||||
@@ -198,11 +205,11 @@ static int command_version(int argc, char **argv)
|
||||
|
||||
|
||||
static const struct console_command console_commands[] = {
|
||||
{"version", command_version},
|
||||
{"version", command_version},
|
||||
};
|
||||
|
||||
static const struct console_group command_group = {
|
||||
"Host commands", console_commands, ARRAY_SIZE(console_commands)
|
||||
"Host commands", console_commands, ARRAY_SIZE(console_commands)
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -212,7 +219,7 @@ static int host_command_init(void)
|
||||
{
|
||||
host_command[0] = host_command[1] = -1;
|
||||
|
||||
console_register_commands(&command_group);
|
||||
console_register_commands(&command_group);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "port80.h"
|
||||
#include "powerdemo.h"
|
||||
#include "pwm.h"
|
||||
#include "pwm_commands.h"
|
||||
#include "system.h"
|
||||
#include "task.h"
|
||||
#include "temp_sensor.h"
|
||||
|
||||
32
common/pwm_commands.c
Normal file
32
common/pwm_commands.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Copyright (c) 2011 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.
|
||||
*/
|
||||
|
||||
/* PWM module for Chrome EC */
|
||||
|
||||
#include "pwm.h"
|
||||
#include "pwm_commands.h"
|
||||
#include "lpc_commands.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Host commands */
|
||||
|
||||
enum lpc_status pwm_command_get_fan_rpm(uint8_t *data)
|
||||
{
|
||||
struct lpc_response_pwm_get_fan_rpm *r =
|
||||
(struct lpc_response_pwm_get_fan_rpm *)data;
|
||||
|
||||
r->rpm = pwm_get_fan_rpm();
|
||||
return EC_LPC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data)
|
||||
{
|
||||
struct lpc_params_pwm_set_fan_target_rpm *p =
|
||||
(struct lpc_params_pwm_set_fan_target_rpm *)data;
|
||||
|
||||
pwm_set_fan_target_rpm(p->rpm);
|
||||
return EC_LPC_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -204,6 +204,21 @@ struct lpc_response_flash_checksum {
|
||||
} while (0)
|
||||
#endif /* SUPPORT_CHECKSUM */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* PWM commands */
|
||||
|
||||
/* Get fan RPM */
|
||||
#define EC_LPC_COMMAND_PWM_GET_FAN_RPM 0x20
|
||||
struct lpc_response_pwm_get_fan_rpm {
|
||||
uint32_t rpm;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* Set target fan RPM */
|
||||
#define EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM 0x21
|
||||
struct lpc_params_pwm_set_fan_target_rpm {
|
||||
uint32_t rpm;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Temperature sensor commands */
|
||||
|
||||
19
include/pwm_commands.h
Normal file
19
include/pwm_commands.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* Copyright (c) 2011 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.
|
||||
*/
|
||||
|
||||
/* PWM commands for Chrome EC */
|
||||
|
||||
#ifndef __CROS_EC_PWM_COMMANDS_H
|
||||
#define __CROS_EC_PWM_COMMANDS_H
|
||||
|
||||
#include "common.h"
|
||||
#include "lpc_commands.h"
|
||||
|
||||
/* Host command handlers. */
|
||||
enum lpc_status pwm_command_get_fan_rpm(uint8_t *data);
|
||||
enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data);
|
||||
|
||||
|
||||
#endif /* __CROS_EC_PWM_COMMANDS_H */
|
||||
@@ -37,6 +37,10 @@ const char help_str[] =
|
||||
" Prints EC version\n"
|
||||
" temps\n"
|
||||
" Print temperature\n"
|
||||
" pwmgetfanrpm\n"
|
||||
" Prints current fan RPM\n"
|
||||
" pwmsetfanrpm <targetrpm>\n"
|
||||
" Set target fan RPM\n"
|
||||
"\n"
|
||||
"Not working for you? Make sure LPC I/O is configured:\n"
|
||||
" pci_write32 0 0x1f 0 0x88 0x007c0801\n"
|
||||
@@ -460,6 +464,46 @@ int cmd_temperature(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_pwm_get_fan_rpm(void)
|
||||
{
|
||||
struct lpc_response_pwm_get_fan_rpm r;
|
||||
int rv;
|
||||
|
||||
rv = ec_command(EC_LPC_COMMAND_PWM_GET_FAN_RPM, NULL, 0, &r, sizeof(r));
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
printf("Current fan RPM: %d\n", r.rpm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_pwm_set_fan_rpm(int argc, char *argv[])
|
||||
{
|
||||
struct lpc_params_pwm_set_fan_target_rpm p;
|
||||
char *e;
|
||||
int rv;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr,
|
||||
"Usage: pwmsetfanrpm <targetrpm>\n");
|
||||
return -1;
|
||||
}
|
||||
p.rpm = strtol(argv[0], &e, 0);
|
||||
if (e && *e) {
|
||||
fprintf(stderr, "Bad RPM.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ec_command(EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM,
|
||||
&p, sizeof(p), NULL, 0);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
printf("Fan target RPM set.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2 || !strcasecmp(argv[1], "-?") ||
|
||||
@@ -493,6 +537,10 @@ int main(int argc, char *argv[])
|
||||
return cmd_version();
|
||||
if (!strcasecmp(argv[1], "temps"))
|
||||
return cmd_temperature();
|
||||
if (!strcasecmp(argv[1], "pwmgetfanrpm"))
|
||||
return cmd_pwm_get_fan_rpm();
|
||||
if (!strcasecmp(argv[1], "pwmsetfanrpm"))
|
||||
return cmd_pwm_set_fan_rpm(argc - 2, argv + 2);
|
||||
|
||||
/* If we're still here, command was unknown */
|
||||
fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);
|
||||
|
||||
Reference in New Issue
Block a user