Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: mediatek: Introduce and use a few more register defines

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>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
88863c9d c95ab56a

+5 -4
+5 -4
drivers/pwm/pwm-mediatek.c
··· 7 7 * 8 8 */ 9 9 10 + #include <linux/bitfield.h> 10 11 #include <linux/err.h> 11 12 #include <linux/io.h> 12 13 #include <linux/ioport.h> ··· 22 21 23 22 /* PWM registers and bits definitions */ 24 23 #define PWMCON 0x00 24 + #define PWMCON_CLKDIV GENMASK(2, 0) 25 25 #define PWMHDUR 0x04 26 26 #define PWMLDUR 0x08 27 27 #define PWMGDUR 0x0c 28 28 #define PWMWAVENUM 0x28 29 29 #define PWMDWIDTH 0x2c 30 + #define PWMDWIDTH_PERIOD GENMASK(12, 0) 30 31 #define PWM45DWIDTH_FIXUP 0x30 31 32 #define PWMTHRES 0x30 32 33 #define PWM45THRES_FIXUP 0x34 33 34 #define PWM_CK_26M_SEL_V3 0x74 34 35 #define PWM_CK_26M_SEL 0x210 35 - 36 - #define PWM_CLK_DIV_MAX 7 37 36 38 37 struct pwm_mediatek_of_data { 39 38 unsigned int num_pwms; ··· 163 162 if (!cnt_period) 164 163 return -EINVAL; 165 164 166 - while (cnt_period > 8192) { 165 + while (cnt_period - 1 > FIELD_MAX(PWMDWIDTH_PERIOD)) { 167 166 resolution *= 2; 168 167 clkdiv++; 169 168 cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, 170 169 resolution); 171 170 } 172 171 173 - if (clkdiv > PWM_CLK_DIV_MAX) { 172 + if (clkdiv > FIELD_MAX(PWMCON_CLKDIV)) { 174 173 dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns); 175 174 ret = -EINVAL; 176 175 goto out;