From c7ce61e16ce0c88fcd4d1621c828f45ec1fdb773 Mon Sep 17 00:00:00 2001 From: Aaron Massey Date: Mon, 10 Oct 2022 11:24:44 -0600 Subject: test: pwm_hc.c EC_CMD_PWM_SET_DUTY Add test that verifies the EC_CMD_PWM_SET_DUTY sets the duty values for PWMs associated with either display light or keyboard backlight. Scenarios: * Set KBlight duty * Set Displaylight duty * Set invalid PWM type duty BRANCH=none BUG=b:252817310 TEST=twister --clobber -i -s zephyr/test/drivers/drivers.shim_pwm_hc Signed-off-by: Aaron Massey Change-Id: I81156f79c0b57ff6a64a64b59396cc8aa2a6c090 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3957263 Reviewed-by: Keith Short Commit-Queue: Keith Short Code-Coverage: Zoss --- include/pwm.h | 2 + .../drivers/shim_pwm_hc/src/test_shim_pwm_hc.c | 47 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/pwm.h b/include/pwm.h index 03e424ee05..48963d9d3c 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -8,6 +8,8 @@ #include +#include "util.h" + #define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX) #define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100) diff --git a/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c index 5fc7344b75..847326c0ba 100644 --- a/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c +++ b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c @@ -16,6 +16,53 @@ #include "pwm.h" #include "test/drivers/test_state.h" +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__kblight) +{ + struct ec_params_pwm_set_duty p = { + .index = DT_REG_ADDR(DT_NODELABEL(pwm_kblight)), + .pwm_type = EC_PWM_TYPE_KB_LIGHT, + /* Arbitrary 56% */ + .duty = PWM_PERCENT_TO_RAW(56), + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_ok(host_command_process(&args)); + zassert_equal(kblight_get(), PWM_RAW_TO_PERCENT(p.duty)); +} + +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__displight) +{ + struct ec_params_pwm_set_duty p = { + p.index = DT_REG_ADDR(DT_NODELABEL(pwm_displight)), + p.pwm_type = EC_PWM_TYPE_DISPLAY_LIGHT, + /* Arbitrary 72% */ + .duty = PWM_PERCENT_TO_RAW(72) + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_ok(host_command_process(&args)); + zassert_equal(displight_get(), PWM_RAW_TO_PERCENT(p.duty)); +} + +ZTEST(shim_pwm_hc, test_pwm_set_duty_hc__bad_pwm_type) +{ + struct ec_params_pwm_set_duty p = { + /* Arbitrary, don't care */ + p.index = 0, + /* PWM Type doesn't actually exist */ + p.pwm_type = EC_PWM_TYPE_COUNT, + }; + + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_PWM_SET_DUTY, 0, p); + + zassert_equal(EC_RES_INVALID_PARAM, host_command_process(&args)); +} + ZTEST(shim_pwm_hc, test_pwm_get_duty_hc__kblight) { struct ec_params_pwm_get_duty p = { -- cgit v1.2.1