From: Simon Glass <sjg@chromium.org>
Date: Wed, 3 Nov 2021 19:21:33 +0000 (-0600)
Subject: exynos: pwm: Deal with a PWM at 100%
X-Git-Tag: v2025.01-rc5-pxa1908~1646^2~2
X-Git-Url: http://git.dujemihanovic.xyz/img/static/%7B%7B?a=commitdiff_plain;h=dfb8470fd0b3b8a87c047b9c1765a1b9123b83b7;p=u-boot.git

exynos: pwm: Deal with a PWM at 100%

At present the counter never hits the comparitor in this case. Add a
special case.

This ensures that the snow backlight works when at full brightness.

Fixes: 76c2ff3e5fd video: backlight: fix pwm's duty cycle calculation

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
---

diff --git a/drivers/pwm/exynos_pwm.c b/drivers/pwm/exynos_pwm.c
index 1afaf784da..609025d680 100644
--- a/drivers/pwm/exynos_pwm.c
+++ b/drivers/pwm/exynos_pwm.c
@@ -43,6 +43,10 @@ static int exynos_pwm_set_config(struct udevice *dev, uint channel,
 		tcnt = period_ns / rate_ns;
 		tcmp = duty_ns / rate_ns;
 		debug("%s: tcnt %u, tcmp %u\n", __func__, tcnt, tcmp);
+
+		/* Ensure that the comparitor will actually hit the target */
+		if (tcmp == tcnt)
+			tcmp = tcnt - 1;
 		offset = channel * 3;
 		writel(tcnt, &regs->tcntb0 + offset);
 		writel(tcmp, &regs->tcmpb0 + offset);