summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhuohao Lee <zhuohao@chromium.org>2020-09-25 16:58:53 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-28 14:27:22 +0000
commit71912007d11d907367e9676a7e616549014bd050 (patch)
tree6a8a64259ddc3592e285def2469ec785669a1b8d
parent4707c9e8ad9d0aabb7296fce5c6773f9271f3f0d (diff)
downloadchrome-ec-71912007d11d907367e9676a7e616549014bd050.tar.gz
fennel: add host command for the ioexpander pwm
In order to support the kernel driver to use the ioexpander pwm driver, we add two host command EC_CMD_PWM_SET_DUTY and EC_CMD_PWM_GET_DUTY to the board layer to support it. Besides, to avoid the RO rom size overflow, we remove the ioexpander pwm function and keyboard backlight function from the RO rom. BUG=b:162902808 BRANCH=firmware-kukui-12573.B TEST=build pass Change-Id: Ibbd66164c19cd792a865f471c0c32ecb595f75e7 Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2434594 Reviewed-by: Aaron Zhang <zhangjianbo@huaqin.corp-partner.google.com> Tested-by: Aaron Zhang <zhangjianbo@huaqin.corp-partner.google.com>
-rw-r--r--board/fennel/board.c56
-rw-r--r--board/fennel/board.h2
2 files changed, 58 insertions, 0 deletions
diff --git a/board/fennel/board.c b/board/fennel/board.c
index 0499be2585..bb825653c1 100644
--- a/board/fennel/board.c
+++ b/board/fennel/board.c
@@ -468,3 +468,59 @@ int board_get_battery_i2c(void)
{
return board_get_version() >= 1 ? 2 : 1;
}
+
+#ifdef SECTION_IS_RW
+static int it8801_get_target_channel(enum pwm_channel *channel,
+ int type, int index)
+{
+ switch (type) {
+ case EC_PWM_TYPE_GENERIC:
+ *channel = index;
+ break;
+ default:
+ return -1;
+ }
+
+ return *channel >= 1;
+}
+
+static enum ec_status
+host_command_pwm_set_duty(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_pwm_set_duty *p = args->params;
+ enum pwm_channel channel;
+ uint16_t duty;
+
+ if (it8801_get_target_channel(&channel, p->pwm_type, p->index))
+ return EC_RES_INVALID_PARAM;
+
+ duty = (uint32_t) p->duty * 255 / 65535;
+ it8801_pwm_set_raw_duty(channel, duty);
+ it8801_pwm_enable(channel, p->duty > 0);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_DUTY,
+ host_command_pwm_set_duty,
+ EC_VER_MASK(0));
+
+static enum ec_status
+host_command_pwm_get_duty(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_pwm_get_duty *p = args->params;
+ struct ec_response_pwm_get_duty *r = args->response;
+
+ enum pwm_channel channel;
+
+ if (it8801_get_target_channel(&channel, p->pwm_type, p->index))
+ return EC_RES_INVALID_PARAM;
+
+ r->duty = (uint32_t) it8801_pwm_get_raw_duty(channel) * 65535 / 255;
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_DUTY,
+ host_command_pwm_get_duty,
+ EC_VER_MASK(0));
+#endif
diff --git a/board/fennel/board.h b/board/fennel/board.h
index ab036dc476..aa24e60526 100644
--- a/board/fennel/board.h
+++ b/board/fennel/board.h
@@ -61,8 +61,10 @@
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
+#ifdef SECTION_IS_RW
#define CONFIG_IO_EXPANDER_IT8801_PWM
#define CONFIG_KEYBOARD_BACKLIGHT
+#endif
#endif /* VARIANT_KUKUI_NO_SENSORS */