From f8d1123934bd5c19e62d13f7e9bd5e6300d31706 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 11 Oct 2022 13:18:14 -0600 Subject: [PATCH] pwm: Reload counters when they reach 0 Add IT5570E register that controls when the down counters are updated. Set them to update when they reach 0, instead of immediately when DCRi is written. Fixes keyboard color changing when changing brightness levels if not using 0xFF for an RGB value. Signed-off-by: Tim Crawford --- src/board/system76/common/pwm.c | 5 +++++ src/ec/ite/include/ec/pwm.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/board/system76/common/pwm.c b/src/board/system76/common/pwm.c index df9633c..77d049f 100644 --- a/src/board/system76/common/pwm.c +++ b/src/board/system76/common/pwm.c @@ -26,6 +26,11 @@ void pwm_init(void) { // Turn off CPU fan (temperature control in peci_get_fan_duty) DCR2 = 0; +#ifdef it5570e + // Reload counters when they reach 0 instead of immediately + PWMLCCR = 0xFF; +#endif + // Enable PWM ZTIER = BIT(1); } diff --git a/src/ec/ite/include/ec/pwm.h b/src/ec/ite/include/ec/pwm.h index b45ae2c..6676a0c 100644 --- a/src/ec/ite/include/ec/pwm.h +++ b/src/ec/ite/include/ec/pwm.h @@ -62,4 +62,9 @@ volatile uint8_t __xdata __at(0x1823) ZTIER; // Tachometer switch control register volatile uint8_t __xdata __at(0x1848) TSWCTLR; +#ifdef it5570e +// PWM Load Counter Control Register +volatile uint8_t __xdata __at(0x185A) PWMLCCR; +#endif + #endif // _EC_PWM_H