summaryrefslogtreecommitdiff
path: root/common/pwm_commands.c
blob: 0493bb9b5e72921f47de8b2ca236fbd4156c60b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Copyright (c) 2012 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 host commands for Chrome EC */

#include "host_command.h"
#include "pwm.h"
#include "thermal.h"


int pwm_command_get_fan_target_rpm(struct host_cmd_handler_args *args)
{
	struct ec_response_pwm_get_fan_rpm *r =
		(struct ec_response_pwm_get_fan_rpm *)args->response;

	r->rpm = pwm_get_fan_target_rpm();
	args->response_size = sizeof(*r);

	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_TARGET_RPM,
		     pwm_command_get_fan_target_rpm,
		     EC_VER_MASK(0));

int pwm_command_set_fan_target_rpm(struct host_cmd_handler_args *args)
{
	const struct ec_params_pwm_set_fan_target_rpm *p =
		(const struct ec_params_pwm_set_fan_target_rpm *)args->params;

#ifdef CONFIG_TASK_THERMAL
	thermal_toggle_auto_fan_ctrl(0);
#endif
	pwm_set_fan_target_rpm(p->rpm);

	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM,
		     pwm_command_set_fan_target_rpm,
		     EC_VER_MASK(0));

int pwm_command_fan_duty(struct host_cmd_handler_args *args)
{
	const struct ec_params_pwm_set_fan_duty *p =
			(const struct ec_params_pwm_set_fan_duty *)args->params;
	pwm_set_fan_duty(p->percent);

	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY,
		     pwm_command_fan_duty,
		     EC_VER_MASK(0));

int pwm_command_get_keyboard_backlight(struct host_cmd_handler_args *args)
{
	struct ec_response_pwm_get_keyboard_backlight *r =
		(struct ec_response_pwm_get_keyboard_backlight *)args->response;

	r->percent = pwm_get_keyboard_backlight();
	r->enabled = pwm_get_keyboard_backlight_enabled();
	args->response_size = sizeof(*r);

	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT,
		     pwm_command_get_keyboard_backlight,
		     EC_VER_MASK(0));

int pwm_command_set_keyboard_backlight(struct host_cmd_handler_args *args)
{
	const struct ec_params_pwm_set_keyboard_backlight *p =
		(const struct ec_params_pwm_set_keyboard_backlight *)
		args->params;

	pwm_set_keyboard_backlight(p->percent);

	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT,
		     pwm_command_set_keyboard_backlight,
		     EC_VER_MASK(0));