Skip to content

Commit ea434ff

Browse files
William Breathitt GrayJonathan Cameron
authored andcommitted
counter: stm32-timer-cnt: Provide defines for slave mode selection
The STM32 timer permits configuration of the counter encoder mode via the slave mode control register (SMCR) slave mode selection (SMS) bits. This patch provides preprocessor defines for the supported encoder modes. Cc: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Link: https://lore.kernel.org/r/ad3d9cd7af580d586316d368f74964cbc394f981.1630031207.git.vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 05593a3 commit ea434ff

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎drivers/counter/stm32-timer-cnt.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ static int stm32_count_function_get(struct counter_device *counter,
9393
regmap_read(priv->regmap, TIM_SMCR, &smcr);
9494

9595
switch (smcr & TIM_SMCR_SMS) {
96-
case 0:
96+
case TIM_SMCR_SMS_SLAVE_MODE_DISABLED:
9797
*function = STM32_COUNT_SLAVE_MODE_DISABLED;
9898
return 0;
99-
case 1:
99+
case TIM_SMCR_SMS_ENCODER_MODE_1:
100100
*function = STM32_COUNT_ENCODER_MODE_1;
101101
return 0;
102-
case 2:
102+
case TIM_SMCR_SMS_ENCODER_MODE_2:
103103
*function = STM32_COUNT_ENCODER_MODE_2;
104104
return 0;
105-
case 3:
105+
case TIM_SMCR_SMS_ENCODER_MODE_3:
106106
*function = STM32_COUNT_ENCODER_MODE_3;
107107
return 0;
108108
default:
@@ -119,16 +119,16 @@ static int stm32_count_function_set(struct counter_device *counter,
119119

120120
switch (function) {
121121
case STM32_COUNT_SLAVE_MODE_DISABLED:
122-
sms = 0;
122+
sms = TIM_SMCR_SMS_SLAVE_MODE_DISABLED;
123123
break;
124124
case STM32_COUNT_ENCODER_MODE_1:
125-
sms = 1;
125+
sms = TIM_SMCR_SMS_ENCODER_MODE_1;
126126
break;
127127
case STM32_COUNT_ENCODER_MODE_2:
128-
sms = 2;
128+
sms = TIM_SMCR_SMS_ENCODER_MODE_2;
129129
break;
130130
case STM32_COUNT_ENCODER_MODE_3:
131-
sms = 3;
131+
sms = TIM_SMCR_SMS_ENCODER_MODE_3;
132132
break;
133133
default:
134134
return -EINVAL;

‎include/linux/mfd/stm32-timers.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#define MAX_TIM_ICPSC 0x3
8383
#define TIM_CR2_MMS_SHIFT 4
8484
#define TIM_CR2_MMS2_SHIFT 20
85+
#define TIM_SMCR_SMS_SLAVE_MODE_DISABLED 0 /* counts on internal clock when CEN=1 */
86+
#define TIM_SMCR_SMS_ENCODER_MODE_1 1 /* counts TI1FP1 edges, depending on TI2FP2 level */
87+
#define TIM_SMCR_SMS_ENCODER_MODE_2 2 /* counts TI2FP2 edges, depending on TI1FP1 level */
88+
#define TIM_SMCR_SMS_ENCODER_MODE_3 3 /* counts on both TI1FP1 and TI2FP2 edges */
8589
#define TIM_SMCR_TS_SHIFT 4
8690
#define TIM_BDTR_BKF_MASK 0xF
8791
#define TIM_BDTR_BKF_SHIFT(x) (16 + (x) * 4)

0 commit comments

Comments
 (0)