mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-07 16:11:43 +00:00
Add EC host commands for keyboard backlight
Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=chrome-os-partner:8128 TEST='ectool setkblight X && ectool getkblight' for X=1, 20, 99, 100, 0 Change-Id: I540fd2d05f4caa110cd1dc45e9b5184fc8777a06
This commit is contained in:
@@ -64,9 +64,16 @@ int pwm_set_fan_target_rpm(int rpm)
|
||||
}
|
||||
|
||||
|
||||
int pwm_get_keyboard_backlight(void)
|
||||
{
|
||||
return ((LM4_FAN_FANCMD(FAN_CH_KBLIGHT) >> 16) * 100 +
|
||||
MAX_PWM / 2) / MAX_PWM;
|
||||
}
|
||||
|
||||
|
||||
int pwm_set_keyboard_backlight(int percent)
|
||||
{
|
||||
LM4_FAN_FANCMD(FAN_CH_KBLIGHT) = ((percent * MAX_PWM) / 100) << 16;
|
||||
LM4_FAN_FANCMD(FAN_CH_KBLIGHT) = ((percent * MAX_PWM + 50) / 100) << 16;
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -164,8 +171,9 @@ static int command_kblight(int argc, char **argv)
|
||||
int i;
|
||||
|
||||
if (argc < 2) {
|
||||
uart_puts("Usage: kblight <percent>\n");
|
||||
return EC_ERROR_UNKNOWN;
|
||||
uart_printf("Keyboard backlight is at %d%%\n",
|
||||
pwm_get_keyboard_backlight());
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
i = strtoi(argv[1], &e, 0);
|
||||
@@ -182,14 +190,6 @@ static int command_kblight(int argc, char **argv)
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(kblight, command_kblight);
|
||||
|
||||
static const struct console_command console_commands[] = {
|
||||
{"fanduty", command_fan_duty},
|
||||
{"faninfo", command_fan_info},
|
||||
{"fanset", command_fan_set},
|
||||
{"kblight", command_kblight},
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Initialization */
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
/* 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.
|
||||
*/
|
||||
@@ -176,13 +176,23 @@ static void command_process(int slot)
|
||||
return;
|
||||
#endif
|
||||
case EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS:
|
||||
lpc_send_host_response(slot, temp_sensor_command_get_readings(data));
|
||||
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));
|
||||
lpc_send_host_response(slot,
|
||||
pwm_command_set_fan_target_rpm(data));
|
||||
return;
|
||||
case EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT:
|
||||
lpc_send_host_response(slot,
|
||||
pwm_command_get_keyboard_backlight(data));
|
||||
return;
|
||||
case EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT:
|
||||
lpc_send_host_response(slot,
|
||||
pwm_command_set_keyboard_backlight(data));
|
||||
return;
|
||||
case EC_LPC_COMMAND_USB_CHARGE_SET_MODE:
|
||||
lpc_send_host_response(slot, usb_charge_command_set_mode(data));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
/* 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 module for Chrome EC */
|
||||
/* PWM host commands for Chrome EC */
|
||||
|
||||
#include "pwm.h"
|
||||
#include "pwm_commands.h"
|
||||
@@ -22,6 +22,7 @@ enum lpc_status pwm_command_get_fan_rpm(uint8_t *data)
|
||||
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 =
|
||||
@@ -30,3 +31,23 @@ enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data)
|
||||
pwm_set_fan_target_rpm(p->rpm);
|
||||
return EC_LPC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data)
|
||||
{
|
||||
struct lpc_response_pwm_get_keyboard_backlight *r =
|
||||
(struct lpc_response_pwm_get_keyboard_backlight *)data;
|
||||
|
||||
r->percent = pwm_get_keyboard_backlight();
|
||||
return EC_LPC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data)
|
||||
{
|
||||
struct lpc_params_pwm_set_keyboard_backlight *p =
|
||||
(struct lpc_params_pwm_set_keyboard_backlight *)data;
|
||||
|
||||
pwm_set_keyboard_backlight(p->percent);
|
||||
return EC_LPC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -222,6 +222,17 @@ struct lpc_params_pwm_set_fan_target_rpm {
|
||||
uint32_t rpm;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* Get keyboard backlight */
|
||||
#define EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT 0x22
|
||||
struct lpc_response_pwm_get_keyboard_backlight {
|
||||
uint8_t percent;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* Set keyboard backlight */
|
||||
#define EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT 0x23
|
||||
struct lpc_params_pwm_set_keyboard_backlight {
|
||||
uint8_t percent;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Temperature sensor commands */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
/* 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.
|
||||
*/
|
||||
@@ -19,6 +19,9 @@ int pwm_get_fan_rpm(void);
|
||||
/* Sets the target fan RPM. Pass -1 to set fan to maximum. */
|
||||
int pwm_set_fan_target_rpm(int rpm);
|
||||
|
||||
/* Gets the keyboard backlight percentage (0=off, 100=max). */
|
||||
int pwm_get_keyboard_backlight(void);
|
||||
|
||||
/* Sets the keyboard backlight percentage (0=off, 100=max). */
|
||||
int pwm_set_keyboard_backlight(int percent);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
/* 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.
|
||||
*/
|
||||
@@ -14,6 +14,8 @@
|
||||
/* 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);
|
||||
enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data);
|
||||
enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data);
|
||||
|
||||
|
||||
#endif /* __CROS_EC_PWM_COMMANDS_H */
|
||||
|
||||
@@ -40,6 +40,10 @@ const char help_str[] =
|
||||
" Prints current fan RPM\n"
|
||||
" pwmsetfanrpm <targetrpm>\n"
|
||||
" Set target fan RPM\n"
|
||||
" pwmgetkblight\n"
|
||||
" Prints current keyboard backlight percent\n"
|
||||
" pwmsetkblight <percent>\n"
|
||||
" Set keyboard backlight in percent\n"
|
||||
" usbchargemode <port> <mode>\n"
|
||||
" Set USB charging mode\n"
|
||||
"\n"
|
||||
@@ -508,6 +512,47 @@ int cmd_pwm_set_fan_rpm(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_pwm_get_keyboard_backlight(void)
|
||||
{
|
||||
struct lpc_response_pwm_get_keyboard_backlight r;
|
||||
int rv;
|
||||
|
||||
rv = ec_command(EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT,
|
||||
NULL, 0, &r, sizeof(r));
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
printf("Current keyboard backlight percent: %d\n", r.percent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_pwm_set_keyboard_backlight(int argc, char *argv[])
|
||||
{
|
||||
struct lpc_params_pwm_set_keyboard_backlight p;
|
||||
char *e;
|
||||
int rv;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr,
|
||||
"Usage: pwmsetkblight <percent>\n");
|
||||
return -1;
|
||||
}
|
||||
p.percent = strtol(argv[0], &e, 0);
|
||||
if (e && *e) {
|
||||
fprintf(stderr, "Bad percent.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ec_command(EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT,
|
||||
&p, sizeof(p), NULL, 0);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
printf("Keyboard backlight set.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_usb_charge_set_mode(int argc, char *argv[])
|
||||
{
|
||||
struct lpc_params_usb_charge_set_mode p;
|
||||
@@ -578,6 +623,10 @@ int main(int argc, char *argv[])
|
||||
return cmd_pwm_get_fan_rpm();
|
||||
if (!strcasecmp(argv[1], "pwmsetfanrpm"))
|
||||
return cmd_pwm_set_fan_rpm(argc - 2, argv + 2);
|
||||
if (!strcasecmp(argv[1], "pwmgetkblight"))
|
||||
return cmd_pwm_get_keyboard_backlight();
|
||||
if (!strcasecmp(argv[1], "pwmsetkblight"))
|
||||
return cmd_pwm_set_keyboard_backlight(argc - 2, argv + 2);
|
||||
if (!strcasecmp(argv[1], "usbchargemode"))
|
||||
return cmd_usb_charge_set_mode(argc - 2, argv + 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user