diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2022-02-17 18:13:23 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-03-08 23:05:21 +0000 |
commit | 3b342bfefe77b2d4f67257d9f26f8346b20ed789 (patch) | |
tree | 14e38259e0435ec8016b99ac9a8f929ea6de4c13 /zephyr/shim/src/pwm_led.c | |
parent | 6f87da8cbcb094f1dc91669ab54d77627f693065 (diff) | |
download | chrome-ec-3b342bfefe77b2d4f67257d9f26f8346b20ed789.tar.gz |
zephyr: pwm_led: check for device ready before using it
Check that the PWM device is actually ready before trying to use it, log
an error if it's not.
BRANCH=none
BUG=b:217741090
TEST=build and run on volteer
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I060ebc6dabe78745df29c940da634ee90ef8fdf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3472244
Reviewed-by: Sam Hurst <shurst@google.com>
Diffstat (limited to 'zephyr/shim/src/pwm_led.c')
-rw-r--r-- | zephyr/shim/src/pwm_led.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c index e128a4b486..cfa7005f04 100644 --- a/zephyr/shim/src/pwm_led.c +++ b/zephyr/shim/src/pwm_led.c @@ -44,6 +44,11 @@ static void pwm_led_set_duty(const struct pwm_led_dt_channel *ch, int percent) uint32_t pulse_us; int rv; + if (!device_is_ready(ch->dev)) { + LOG_ERR("PWM device %s not ready", ch->dev->name); + return; + } + pulse_us = DIV_ROUND_NEAREST(ch->period_us * percent, 100); LOG_DBG("LED PWM %s set percent (%d), pulse %d", ch->dev->name, percent, |