diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2022-02-16 18:00:06 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-02-18 01:06:16 +0000 |
commit | 66fa9b729cfd2d64123c2b3b62519b8a172f5a6e (patch) | |
tree | c18166281781fb7e22060aa16dd7bad699a8392f | |
parent | 3639eb8ab632fb1f910f17059d181c3c65f9e119 (diff) | |
download | chrome-ec-66fa9b729cfd2d64123c2b3b62519b8a172f5a6e.tar.gz |
zephyr: replace the ecos kblight driver for a deshimmed one
Replace the ECOS pwm_kblight driver with one using the Zephyr APIs for
pwm and devicetree.
BRANCH=none
BUG=b:217741090
TEST=build and run on volteer, play with the keyboard backlight
TEST=zmake configure -b brya
TEST=zmake configure -b herobrine
TEST=zmake configure -b skyrim
TEST=zmake configure -b lazor
TEST=zmake configure -b npcx9
TEST=zmake configure -b npcx7
TEST=zmake configure -b nivviks
TEST=zmake configure -b nereid
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: Idb58f6bbecad4337148fd6a279ef0625247df6fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3468505
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
27 files changed, 241 insertions, 88 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 89bcad1362..d5d1d1c667 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -268,8 +268,7 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MKBP_INPUT_DEVICES zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD_VIVALDI "${PLATFORM_EC}/common/keyboard_vivaldi.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PWM_KBLIGHT - "${PLATFORM_EC}/common/keyboard_backlight.c" - "${PLATFORM_EC}/common/pwm_kblight.c") + "${PLATFORM_EC}/common/keyboard_backlight.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON "${PLATFORM_EC}/common/led_common.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_PWM diff --git a/zephyr/drivers/CMakeLists.txt b/zephyr/drivers/CMakeLists.txt index d246f31703..a9fab56f36 100644 --- a/zephyr/drivers/CMakeLists.txt +++ b/zephyr/drivers/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(cros_cbi) add_subdirectory(cros_flash) add_subdirectory(cros_kb_raw) +add_subdirectory(cros_kblight) add_subdirectory(cros_rtc) add_subdirectory(cros_shi) add_subdirectory(cros_system) diff --git a/zephyr/drivers/cros_kblight/CMakeLists.txt b/zephyr/drivers/cros_kblight/CMakeLists.txt new file mode 100644 index 0000000000..a9e8516f85 --- /dev/null +++ b/zephyr/drivers/cros_kblight/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2022 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. + +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PWM_KBLIGHT pwm_kblight.c) diff --git a/zephyr/drivers/cros_kblight/pwm_kblight.c b/zephyr/drivers/cros_kblight/pwm_kblight.c new file mode 100644 index 0000000000..0f82f3ce99 --- /dev/null +++ b/zephyr/drivers/cros_kblight/pwm_kblight.c @@ -0,0 +1,96 @@ +/* Copyright 2022 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. + */ + +#define DT_DRV_COMPAT cros_ec_kblight_pwm + +#include <devicetree.h> +#include <drivers/pwm.h> +#include <logging/log.h> + +#include "common.h" +#include "keyboard_backlight.h" +#include "util.h" + +LOG_MODULE_REGISTER(kblight, LOG_LEVEL_ERR); + +BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, + "Exactly one instance of cros-ec,kblight-pwm should be defined."); + +#define KBLIGHT_PWM_NODE DT_INST_PWMS_CTLR(0) +#define KBLIGHT_PWM_CHANNEL DT_INST_PWMS_CHANNEL(0) +#define KBLIGHT_PWM_FLAGS DT_INST_PWMS_FLAGS(0) +#define KBLIGHT_PWM_PERIOD_US (USEC_PER_SEC/DT_INST_PROP(0, frequency)) + +static bool kblight_enabled; +static int kblight_percent; + +static void kblight_pwm_set_duty(int percent) +{ + const struct device *pwm_dev = DEVICE_DT_GET(KBLIGHT_PWM_NODE); + uint32_t pulse_us; + int rv; + + if (!device_is_ready(pwm_dev)) { + LOG_ERR("PWM device %s not ready", pwm_dev->name); + return; + } + + pulse_us = DIV_ROUND_NEAREST(KBLIGHT_PWM_PERIOD_US * percent, 100); + + LOG_DBG("kblight PWM %s set percent (%d), pulse %d", + pwm_dev->name, percent, pulse_us); + + rv = pwm_pin_set_usec(pwm_dev, KBLIGHT_PWM_CHANNEL, + KBLIGHT_PWM_PERIOD_US, pulse_us, + KBLIGHT_PWM_FLAGS); + if (rv) { + LOG_ERR("pwm_pin_set_usec() failed %s (%d)", + pwm_dev->name, rv); + } +} + +static int kblight_pwm_set(int percent) +{ + kblight_percent = percent; + kblight_pwm_set_duty(percent); + return EC_SUCCESS; +} + +static int kblight_pwm_get(void) +{ + return kblight_percent; +} + +static int kblight_pwm_enable(int enable) +{ + kblight_enabled = enable; + if (enable) { + kblight_pwm_set_duty(kblight_percent); + } else { + /* Disable but hold kblight_percent. */ + kblight_pwm_set_duty(0); + } + return EC_SUCCESS; +} + +static int kblight_pwm_get_enabled(void) +{ + return kblight_enabled; +} + +static int kblight_pwm_init(void) +{ + kblight_percent = 0; + kblight_pwm_enable(0); + return EC_SUCCESS; +} + +const struct kblight_drv kblight_pwm = { + .init = kblight_pwm_init, + .set = kblight_pwm_set, + .get = kblight_pwm_get, + .enable = kblight_pwm_enable, + .get_enabled = kblight_pwm_get_enabled, +}; diff --git a/zephyr/dts/bindings/keyboard/cros-ec,kblight-pwm.yaml b/zephyr/dts/bindings/keyboard/cros-ec,kblight-pwm.yaml new file mode 100644 index 0000000000..e30e9c8bd2 --- /dev/null +++ b/zephyr/dts/bindings/keyboard/cros-ec,kblight-pwm.yaml @@ -0,0 +1,20 @@ +# Copyright 2022 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. + +description: PWM keyboard backlight configuration + +compatible: "cros-ec,kblight-pwm" + +include: base.yaml + +properties: + pwms: + type: phandle-array + required: true + description: PWM controlling the Keyboard backlight level. + + frequency: + type: int + required: true + description: PWM frequency in Hz. diff --git a/zephyr/projects/brya/brya/BUILD.py b/zephyr/projects/brya/brya/BUILD.py index cfc07db535..13725151b8 100644 --- a/zephyr/projects/brya/brya/BUILD.py +++ b/zephyr/projects/brya/brya/BUILD.py @@ -12,6 +12,7 @@ register_npcx_project( "fan.dts", "gpio.dts", "interrupts.dts", + "keyboard.dts", "motionsense.dts", "pwm.dts", "pwm_leds.dts", diff --git a/zephyr/projects/brya/brya/keyboard.dts b/zephyr/projects/brya/brya/keyboard.dts new file mode 100644 index 0000000000..04ce42fa1e --- /dev/null +++ b/zephyr/projects/brya/brya/keyboard.dts @@ -0,0 +1,16 @@ +/* Copyright 2022 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. + */ + +/ { + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm3 0 0>; + frequency = <2400>; + }; +}; + +&pwm3 { + status = "okay"; +}; diff --git a/zephyr/projects/brya/brya/pwm.dts b/zephyr/projects/brya/brya/pwm.dts index 210a70d874..b322912615 100644 --- a/zephyr/projects/brya/brya/pwm.dts +++ b/zephyr/projects/brya/brya/pwm.dts @@ -7,10 +7,6 @@ named-pwms { compatible = "named-pwms"; - kblight: kblight { - pwms = <&pwm3 0 0>; - frequency = <2400>; - }; pwm_fan: fan { pwms = <&pwm5 0 0>; frequency = <1000>; @@ -18,11 +14,6 @@ }; }; -/* Keyboard backlight */ -&pwm3 { - status = "okay"; -}; - /* Fan control */ &pwm5 { status = "okay"; diff --git a/zephyr/projects/herobrine/BUILD.py b/zephyr/projects/herobrine/BUILD.py index ce0391df35..4fb0cebb40 100644 --- a/zephyr/projects/herobrine/BUILD.py +++ b/zephyr/projects/herobrine/BUILD.py @@ -15,6 +15,7 @@ def register_variant(project_name, extra_dts_overlays=(), extra_kconfig_files=() here / "common.dts", here / "i2c.dts", here / "interrupts.dts", + here / "keyboard.dts", here / "motionsense.dts", here / "pwm.dts", here / "switchcap.dts", diff --git a/zephyr/projects/herobrine/keyboard.dts b/zephyr/projects/herobrine/keyboard.dts new file mode 100644 index 0000000000..70bdc47c53 --- /dev/null +++ b/zephyr/projects/herobrine/keyboard.dts @@ -0,0 +1,16 @@ +/* Copyright 2022 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. + */ + +/ { + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm3 0 0>; + frequency = <10000>; + }; +}; + +&pwm3 { + status = "okay"; +}; diff --git a/zephyr/projects/herobrine/pwm.dts b/zephyr/projects/herobrine/pwm.dts index b8c6165d72..54f3a3f015 100644 --- a/zephyr/projects/herobrine/pwm.dts +++ b/zephyr/projects/herobrine/pwm.dts @@ -7,10 +7,6 @@ named-pwms { compatible = "named-pwms"; - kblight: kb_bl_pwm { - pwms = <&pwm3 0 0>; - frequency = <10000>; - }; displight: ecl_bl_pwm_r { pwms = <&pwm5 0 0>; frequency = <4800>; @@ -18,11 +14,6 @@ }; }; -/* Keyboard backlight */ -&pwm3 { - status = "okay"; -}; - /* Display backlight */ &pwm5 { status = "okay"; diff --git a/zephyr/projects/nissa/BUILD.py b/zephyr/projects/nissa/BUILD.py index ab2225d499..0ba5bf2360 100644 --- a/zephyr/projects/nissa/BUILD.py +++ b/zephyr/projects/nissa/BUILD.py @@ -30,6 +30,7 @@ register_nissa_project( here / "nivviks_generated.dts", here / "nivviks_overlay.dts", here / "nivviks_motionsense.dts", + here / "nivviks_keyboard.dts", ], extra_kconfig_files=[here / "prj_nivviks.conf"], ) @@ -41,6 +42,7 @@ register_nissa_project( here / "nereid_generated.dts", here / "nereid_overlay.dts", here / "nereid_motionsense.dts", + here / "nereid_keyboard.dts", ], extra_kconfig_files=[here / "prj_nereid.conf"], ) diff --git a/zephyr/projects/nissa/nereid_keyboard.dts b/zephyr/projects/nissa/nereid_keyboard.dts new file mode 100644 index 0000000000..0e3a92900b --- /dev/null +++ b/zephyr/projects/nissa/nereid_keyboard.dts @@ -0,0 +1,12 @@ +/* Copyright 2022 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. + */ + +/ { + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm0 0 0>; + frequency = <10000>; + }; +}; diff --git a/zephyr/projects/nissa/nereid_overlay.dts b/zephyr/projects/nissa/nereid_overlay.dts index abe01434fd..d101dd11f1 100644 --- a/zephyr/projects/nissa/nereid_overlay.dts +++ b/zephyr/projects/nissa/nereid_overlay.dts @@ -164,16 +164,6 @@ /delete-node/ temp_sensor_3; }; - /* - * Alias kblist to correct node. - */ - named-pwms { - compatible = "named-pwms"; - - kblight: pwm_kb_bl { - }; - }; - usbc { port0 { bc12 { diff --git a/zephyr/projects/nissa/nivviks_keyboard.dts b/zephyr/projects/nissa/nivviks_keyboard.dts new file mode 100644 index 0000000000..5ef37fb216 --- /dev/null +++ b/zephyr/projects/nissa/nivviks_keyboard.dts @@ -0,0 +1,12 @@ +/* Copyright 2022 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. + */ + +/ { + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm6 6 0>; + frequency = <10000>; + }; +}; diff --git a/zephyr/projects/nissa/nivviks_overlay.dts b/zephyr/projects/nissa/nivviks_overlay.dts index 9d4db52327..52906f4bb8 100644 --- a/zephyr/projects/nissa/nivviks_overlay.dts +++ b/zephyr/projects/nissa/nivviks_overlay.dts @@ -144,18 +144,6 @@ }; }; - /* - * Alias kblist to correct node. - * It would be nice to use alias here, but the code - * uses DT_NODELABEL to directly reference the node label. - */ - named-pwms { - compatible = "named-pwms"; - - kblight: pwm_kb_bl { - }; - }; - usbc { port0 { bc12 { diff --git a/zephyr/projects/npcx_evb/npcx7/keyboard.dts b/zephyr/projects/npcx_evb/npcx7/keyboard.dts index fdeee3c02c..896999d2a6 100644 --- a/zephyr/projects/npcx_evb/npcx7/keyboard.dts +++ b/zephyr/projects/npcx_evb/npcx7/keyboard.dts @@ -28,4 +28,14 @@ 0xc8 /* C12 */ >; }; + + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm2 0 0>; + frequency = <10000>; + }; +}; + +&pwm2 { + status = "okay"; }; diff --git a/zephyr/projects/npcx_evb/npcx7/pwm.dts b/zephyr/projects/npcx_evb/npcx7/pwm.dts index 448fc53f7a..6a8029ecfe 100644 --- a/zephyr/projects/npcx_evb/npcx7/pwm.dts +++ b/zephyr/projects/npcx_evb/npcx7/pwm.dts @@ -11,10 +11,6 @@ pwms = <&pwm0 0 0>; frequency = <25000>; }; - kblight: kblight { - pwms = <&pwm2 0 0>; - frequency = <10000>; - }; }; }; @@ -23,8 +19,3 @@ status = "okay"; drive-open-drain; }; - -/* kblight */ -&pwm2 { - status = "okay"; -}; diff --git a/zephyr/projects/npcx_evb/npcx9/keyboard.dts b/zephyr/projects/npcx_evb/npcx9/keyboard.dts index fdeee3c02c..896999d2a6 100644 --- a/zephyr/projects/npcx_evb/npcx9/keyboard.dts +++ b/zephyr/projects/npcx_evb/npcx9/keyboard.dts @@ -28,4 +28,14 @@ 0xc8 /* C12 */ >; }; + + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm2 0 0>; + frequency = <10000>; + }; +}; + +&pwm2 { + status = "okay"; }; diff --git a/zephyr/projects/npcx_evb/npcx9/pwm.dts b/zephyr/projects/npcx_evb/npcx9/pwm.dts index 448fc53f7a..6a8029ecfe 100644 --- a/zephyr/projects/npcx_evb/npcx9/pwm.dts +++ b/zephyr/projects/npcx_evb/npcx9/pwm.dts @@ -11,10 +11,6 @@ pwms = <&pwm0 0 0>; frequency = <25000>; }; - kblight: kblight { - pwms = <&pwm2 0 0>; - frequency = <10000>; - }; }; }; @@ -23,8 +19,3 @@ status = "okay"; drive-open-drain; }; - -/* kblight */ -&pwm2 { - status = "okay"; -}; diff --git a/zephyr/projects/skyrim/BUILD.py b/zephyr/projects/skyrim/BUILD.py index 4f70ff7dfe..c8c70a7c02 100644 --- a/zephyr/projects/skyrim/BUILD.py +++ b/zephyr/projects/skyrim/BUILD.py @@ -15,6 +15,7 @@ def register_variant(project_name): here / "gpio.dts", here / "i2c.dts", here / "interrupts.dts", + here / "keyboard.dts", here / "pwm.dts", # Project-specific DTS customizations. here / f"{project_name}.dts", diff --git a/zephyr/projects/skyrim/keyboard.dts b/zephyr/projects/skyrim/keyboard.dts new file mode 100644 index 0000000000..7c77dd2d07 --- /dev/null +++ b/zephyr/projects/skyrim/keyboard.dts @@ -0,0 +1,17 @@ +/* Copyright 2022 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. + */ + +/ { + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm1 0 0>; + frequency = <100>; + }; +}; + +&pwm1 { + status = "okay"; + clock-bus = "NPCX_CLOCK_BUS_LFCLK"; +}; diff --git a/zephyr/projects/skyrim/pwm.dts b/zephyr/projects/skyrim/pwm.dts index 8853615074..14cba081cc 100644 --- a/zephyr/projects/skyrim/pwm.dts +++ b/zephyr/projects/skyrim/pwm.dts @@ -11,10 +11,6 @@ pwms = <&pwm0 0 0>; frequency = <25000>; }; - kblight: pwm_kb_bl { - pwms = <&pwm1 0 0>; - frequency = <100>; - }; led_charge: ec_pwm_led_chrg_l { pwms = <&pwm2 0 0>; frequency = <100>; @@ -32,12 +28,6 @@ drive-open-drain; }; -/* Keyboard backlight */ -&pwm1 { - status = "okay"; - clock-bus = "NPCX_CLOCK_BUS_LFCLK"; -}; - /* Amber charging LED */ &pwm2 { status = "okay"; diff --git a/zephyr/projects/trogdor/lazor/keyboard.dts b/zephyr/projects/trogdor/lazor/keyboard.dts index 1b683d0eba..4967cc161a 100644 --- a/zephyr/projects/trogdor/lazor/keyboard.dts +++ b/zephyr/projects/trogdor/lazor/keyboard.dts @@ -23,4 +23,14 @@ 0xca /* C12 */ >; }; + + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm3 0 0>; + frequency = <10000>; + }; +}; + +&pwm3 { + status = "okay"; }; diff --git a/zephyr/projects/trogdor/lazor/pwm.dts b/zephyr/projects/trogdor/lazor/pwm.dts index a06860d923..1cd70a3ea0 100644 --- a/zephyr/projects/trogdor/lazor/pwm.dts +++ b/zephyr/projects/trogdor/lazor/pwm.dts @@ -7,10 +7,6 @@ named-pwms { compatible = "named-pwms"; - kblight: kb_bl_pwm { - pwms = <&pwm3 0 0>; - frequency = <10000>; - }; displight: edp_bkltctl { pwms = <&pwm5 0 0>; frequency = <4800>; @@ -18,11 +14,6 @@ }; }; -/* Keyboard backlight */ -&pwm3 { - status = "okay"; -}; - /* Display backlight */ &pwm5 { status = "okay"; diff --git a/zephyr/projects/volteer/volteer/keyboard.dts b/zephyr/projects/volteer/volteer/keyboard.dts index e9b5cdf0a1..4988e14e2f 100644 --- a/zephyr/projects/volteer/volteer/keyboard.dts +++ b/zephyr/projects/volteer/volteer/keyboard.dts @@ -25,4 +25,14 @@ 0 /* C14 - for keypad */ >; }; + + kblight { + compatible = "cros-ec,kblight-pwm"; + pwms = <&pwm3 0 0>; + frequency = <2400>; + }; +}; + +&pwm3 { + status = "okay"; }; diff --git a/zephyr/projects/volteer/volteer/pwm.dts b/zephyr/projects/volteer/volteer/pwm.dts index c0b2d6f117..4050f54889 100644 --- a/zephyr/projects/volteer/volteer/pwm.dts +++ b/zephyr/projects/volteer/volteer/pwm.dts @@ -7,10 +7,6 @@ named-pwms { compatible = "named-pwms"; - kblight: ec_kb_bl_pwm { - pwms = <&pwm3 0 0>; - frequency = <2400>; - }; pwm_fan: fan_pwm { pwms = <&pwm5 0 0>; frequency = <25000>; @@ -18,11 +14,6 @@ }; }; -/* Keyboard backlight */ -&pwm3 { - status = "okay"; -}; - /* Fan control */ &pwm5 { status = "okay"; |