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

pwm: stm32: Remove clutter from ternary operator

Remove usage of the ternary operator to assign values for register
fields. Instead, parameterize the register and field offset macros
and pass the index to them.

This removes clutter and improves readability.

Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

+13 -20
+9 -12
drivers/pwm/pwm-stm32.c
··· 493 493 static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, 494 494 int index, int level, int filter) 495 495 { 496 - u32 bke = (index == 0) ? TIM_BDTR_BKE : TIM_BDTR_BK2E; 497 - int shift = (index == 0) ? TIM_BDTR_BKF_SHIFT : TIM_BDTR_BK2F_SHIFT; 498 - u32 mask = (index == 0) ? TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF 499 - : TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F; 500 - u32 bdtr = bke; 496 + u32 shift = TIM_BDTR_BKF_SHIFT(index); 497 + u32 bke = TIM_BDTR_BKE(index); 498 + u32 bkp = TIM_BDTR_BKP(index); 499 + u32 bkf = TIM_BDTR_BKF(index); 500 + u32 mask = bkf | bkp | bke; 501 + u32 bdtr; 501 502 502 - /* 503 - * The both bits could be set since only one will be wrote 504 - * due to mask value. 505 - */ 503 + bdtr = (filter & TIM_BDTR_BKF_MASK) << shift | bke; 504 + 506 505 if (level) 507 - bdtr |= TIM_BDTR_BKP | TIM_BDTR_BK2P; 508 - 509 - bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift; 506 + bdtr |= bkp; 510 507 511 508 regmap_update_bits(priv->regmap, TIM_BDTR, mask, bdtr); 512 509
+4 -8
include/linux/mfd/stm32-timers.h
··· 70 70 #define TIM_CCER_CC4E BIT(12) /* Capt/Comp 4 out Ena */ 71 71 #define TIM_CCER_CC4P BIT(13) /* Capt/Comp 4 Polarity */ 72 72 #define TIM_CCER_CCXE (BIT(0) | BIT(4) | BIT(8) | BIT(12)) 73 - #define TIM_BDTR_BKE BIT(12) /* Break input enable */ 74 - #define TIM_BDTR_BKP BIT(13) /* Break input polarity */ 73 + #define TIM_BDTR_BKE(x) BIT(12 + (x) * 12) /* Break input enable */ 74 + #define TIM_BDTR_BKP(x) BIT(13 + (x) * 12) /* Break input polarity */ 75 75 #define TIM_BDTR_AOE BIT(14) /* Automatic Output Enable */ 76 76 #define TIM_BDTR_MOE BIT(15) /* Main Output Enable */ 77 - #define TIM_BDTR_BKF (BIT(16) | BIT(17) | BIT(18) | BIT(19)) 78 - #define TIM_BDTR_BK2F (BIT(20) | BIT(21) | BIT(22) | BIT(23)) 79 - #define TIM_BDTR_BK2E BIT(24) /* Break 2 input enable */ 80 - #define TIM_BDTR_BK2P BIT(25) /* Break 2 input polarity */ 77 + #define TIM_BDTR_BKF(x) (0xf << (16 + (x) * 4)) 81 78 #define TIM_DCR_DBA GENMASK(4, 0) /* DMA base addr */ 82 79 #define TIM_DCR_DBL GENMASK(12, 8) /* DMA burst len */ 83 80 ··· 84 87 #define TIM_CR2_MMS2_SHIFT 20 85 88 #define TIM_SMCR_TS_SHIFT 4 86 89 #define TIM_BDTR_BKF_MASK 0xF 87 - #define TIM_BDTR_BKF_SHIFT 16 88 - #define TIM_BDTR_BK2F_SHIFT 20 90 + #define TIM_BDTR_BKF_SHIFT(x) (16 + (x) * 4) 89 91 90 92 enum stm32_timers_dmas { 91 93 STM32_TIMERS_DMA_CH1,