diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-10-10 11:24:44 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-14 22:01:13 +0000 |
commit | c7ce61e16ce0c88fcd4d1621c828f45ec1fdb773 (patch) | |
tree | 5e42bbffe7f85d2fcf2f6019f7f67ca787db3c58 | |
parent | 9f3d9ccd53800c7f8ce08437de38bc6c6e2ef121 (diff) | |
download | chrome-ec-c7ce61e16ce0c88fcd4d1621c828f45ec1fdb773.tar.gz |
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 <aaronmassey@google.com>
Change-Id: I81156f79c0b57ff6a64a64b59396cc8aa2a6c090
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3957263
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | include/pwm.h | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c | 47 |
2 files changed, 49 insertions, 0 deletions
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 <inttypes.h> +#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 = { |