]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pwm: mediatek: Introduce and use a few more register defines
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Fri, 25 Jul 2025 15:45:06 +0000 (17:45 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 15 Sep 2025 09:39:44 +0000 (11:39 +0200)
Instead of using a magic constant for bound checking, derive the numbers
from appropriate register defines.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20250725154506.2610172-12-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-mediatek.c

index c4169ae614bcbf3637313b4df3dd00d41a1ee332..c592ff9b7ed9fd66be672d8af3b5569b1e8f5ba2 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 
+#include <linux/bitfield.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
 
 /* PWM registers and bits definitions */
 #define PWMCON                 0x00
+#define PWMCON_CLKDIV                  GENMASK(2, 0)
 #define PWMHDUR                        0x04
 #define PWMLDUR                        0x08
 #define PWMGDUR                        0x0c
 #define PWMWAVENUM             0x28
 #define PWMDWIDTH              0x2c
+#define PWMDWIDTH_PERIOD               GENMASK(12, 0)
 #define PWM45DWIDTH_FIXUP      0x30
 #define PWMTHRES               0x30
 #define PWM45THRES_FIXUP       0x34
 #define PWM_CK_26M_SEL_V3      0x74
 #define PWM_CK_26M_SEL         0x210
 
-#define PWM_CLK_DIV_MAX                7
-
 struct pwm_mediatek_of_data {
        unsigned int num_pwms;
        bool pwm45_fixup;
@@ -162,14 +163,14 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
        if (!cnt_period)
                return -EINVAL;
 
-       while (cnt_period > 8192) {
+       while (cnt_period - 1 > FIELD_MAX(PWMDWIDTH_PERIOD)) {
                resolution *= 2;
                clkdiv++;
                cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000,
                                                   resolution);
        }
 
-       if (clkdiv > PWM_CLK_DIV_MAX) {
+       if (clkdiv > FIELD_MAX(PWMCON_CLKDIV)) {
                dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns);
                ret = -EINVAL;
                goto out;