blob: 4b05b198a8d8bc65358bafb565cdfc63df454aec [file] [log] [blame]
Benjamin Gaignardad299372019-04-02 15:30:42 +09001// SPDX-License-Identifier: GPL-2.0
2/*
3 * STM32 Timer Encoder and Counter driver
4 *
5 * Copyright (C) STMicroelectronics 2018
6 *
7 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
8 *
9 */
10#include <linux/counter.h>
Benjamin Gaignardad299372019-04-02 15:30:42 +090011#include <linux/mfd/stm32-timers.h>
Fabrice Gasnier15e85732020-02-11 11:56:06 +010012#include <linux/mod_devicetable.h>
Benjamin Gaignardad299372019-04-02 15:30:42 +090013#include <linux/module.h>
Fabrice Gasnierc5b84252020-02-10 18:19:58 +010014#include <linux/pinctrl/consumer.h>
Benjamin Gaignardad299372019-04-02 15:30:42 +090015#include <linux/platform_device.h>
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090016#include <linux/types.h>
Benjamin Gaignardad299372019-04-02 15:30:42 +090017
18#define TIM_CCMR_CCXS (BIT(8) | BIT(0))
19#define TIM_CCMR_MASK (TIM_CCMR_CC1S | TIM_CCMR_CC2S | \
20 TIM_CCMR_IC1F | TIM_CCMR_IC2F)
21#define TIM_CCER_MASK (TIM_CCER_CC1P | TIM_CCER_CC1NP | \
22 TIM_CCER_CC2P | TIM_CCER_CC2NP)
23
Fabrice Gasnierc5b84252020-02-10 18:19:58 +010024struct stm32_timer_regs {
25 u32 cr1;
26 u32 cnt;
27 u32 smcr;
28 u32 arr;
29};
30
Benjamin Gaignardad299372019-04-02 15:30:42 +090031struct stm32_timer_cnt {
32 struct counter_device counter;
33 struct regmap *regmap;
34 struct clk *clk;
Fabrice Gasniere4c3e132021-03-02 15:43:55 +010035 u32 max_arr;
Fabrice Gasnierc5b84252020-02-10 18:19:58 +010036 bool enabled;
37 struct stm32_timer_regs bak;
Benjamin Gaignardad299372019-04-02 15:30:42 +090038};
39
William Breathitt Gray394a0152021-08-03 21:06:15 +090040static const enum counter_function stm32_count_functions[] = {
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090041 COUNTER_FUNCTION_INCREASE,
42 COUNTER_FUNCTION_QUADRATURE_X2_A,
43 COUNTER_FUNCTION_QUADRATURE_X2_B,
44 COUNTER_FUNCTION_QUADRATURE_X4,
Benjamin Gaignardad299372019-04-02 15:30:42 +090045};
46
47static int stm32_count_read(struct counter_device *counter,
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090048 struct counter_count *count, u64 *val)
Benjamin Gaignardad299372019-04-02 15:30:42 +090049{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +010050 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +090051 u32 cnt;
52
53 regmap_read(priv->regmap, TIM_CNT, &cnt);
William Breathitt Grayd49e6ee2019-10-06 16:03:09 -040054 *val = cnt;
Benjamin Gaignardad299372019-04-02 15:30:42 +090055
56 return 0;
57}
58
59static int stm32_count_write(struct counter_device *counter,
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090060 struct counter_count *count, const u64 val)
Benjamin Gaignardad299372019-04-02 15:30:42 +090061{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +010062 struct stm32_timer_cnt *const priv = counter_priv(counter);
Fabrice Gasnierb14d72a2021-03-03 18:49:49 +010063 u32 ceiling;
Benjamin Gaignardad299372019-04-02 15:30:42 +090064
Fabrice Gasnierb14d72a2021-03-03 18:49:49 +010065 regmap_read(priv->regmap, TIM_ARR, &ceiling);
66 if (val > ceiling)
Benjamin Gaignardad299372019-04-02 15:30:42 +090067 return -EINVAL;
68
William Breathitt Grayd49e6ee2019-10-06 16:03:09 -040069 return regmap_write(priv->regmap, TIM_CNT, val);
Benjamin Gaignardad299372019-04-02 15:30:42 +090070}
71
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090072static int stm32_count_function_read(struct counter_device *counter,
73 struct counter_count *count,
74 enum counter_function *function)
Benjamin Gaignardad299372019-04-02 15:30:42 +090075{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +010076 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +090077 u32 smcr;
78
79 regmap_read(priv->regmap, TIM_SMCR, &smcr);
80
81 switch (smcr & TIM_SMCR_SMS) {
William Breathitt Grayea434ff2021-08-27 12:47:46 +090082 case TIM_SMCR_SMS_SLAVE_MODE_DISABLED:
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090083 *function = COUNTER_FUNCTION_INCREASE;
William Breathitt Grayfae6f622021-02-26 10:29:31 +090084 return 0;
William Breathitt Grayea434ff2021-08-27 12:47:46 +090085 case TIM_SMCR_SMS_ENCODER_MODE_1:
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090086 *function = COUNTER_FUNCTION_QUADRATURE_X2_A;
Benjamin Gaignardad299372019-04-02 15:30:42 +090087 return 0;
William Breathitt Grayea434ff2021-08-27 12:47:46 +090088 case TIM_SMCR_SMS_ENCODER_MODE_2:
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090089 *function = COUNTER_FUNCTION_QUADRATURE_X2_B;
Benjamin Gaignardad299372019-04-02 15:30:42 +090090 return 0;
William Breathitt Grayea434ff2021-08-27 12:47:46 +090091 case TIM_SMCR_SMS_ENCODER_MODE_3:
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090092 *function = COUNTER_FUNCTION_QUADRATURE_X4;
Benjamin Gaignardad299372019-04-02 15:30:42 +090093 return 0;
William Breathitt Grayfae6f622021-02-26 10:29:31 +090094 default:
95 return -EINVAL;
Benjamin Gaignardad299372019-04-02 15:30:42 +090096 }
Benjamin Gaignardad299372019-04-02 15:30:42 +090097}
98
William Breathitt Grayaaec1a02021-08-27 12:47:47 +090099static int stm32_count_function_write(struct counter_device *counter,
100 struct counter_count *count,
101 enum counter_function function)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900102{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100103 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900104 u32 cr1, sms;
105
106 switch (function) {
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900107 case COUNTER_FUNCTION_INCREASE:
William Breathitt Grayea434ff2021-08-27 12:47:46 +0900108 sms = TIM_SMCR_SMS_SLAVE_MODE_DISABLED;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900109 break;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900110 case COUNTER_FUNCTION_QUADRATURE_X2_A:
William Breathitt Grayea434ff2021-08-27 12:47:46 +0900111 sms = TIM_SMCR_SMS_ENCODER_MODE_1;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900112 break;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900113 case COUNTER_FUNCTION_QUADRATURE_X2_B:
William Breathitt Grayea434ff2021-08-27 12:47:46 +0900114 sms = TIM_SMCR_SMS_ENCODER_MODE_2;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900115 break;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900116 case COUNTER_FUNCTION_QUADRATURE_X4:
William Breathitt Grayea434ff2021-08-27 12:47:46 +0900117 sms = TIM_SMCR_SMS_ENCODER_MODE_3;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900118 break;
119 default:
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900120 return -EINVAL;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900121 }
122
123 /* Store enable status */
124 regmap_read(priv->regmap, TIM_CR1, &cr1);
125
126 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
127
Benjamin Gaignardad299372019-04-02 15:30:42 +0900128 regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms);
129
130 /* Make sure that registers are updated */
131 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
132
133 /* Restore the enable status */
134 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, cr1);
135
136 return 0;
137}
138
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900139static int stm32_count_direction_read(struct counter_device *counter,
Benjamin Gaignardad299372019-04-02 15:30:42 +0900140 struct counter_count *count,
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900141 enum counter_count_direction *direction)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900142{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100143 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900144 u32 cr1;
145
146 regmap_read(priv->regmap, TIM_CR1, &cr1);
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900147 *direction = (cr1 & TIM_CR1_DIR) ? COUNTER_COUNT_DIRECTION_BACKWARD :
148 COUNTER_COUNT_DIRECTION_FORWARD;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900149
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900150 return 0;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900151}
152
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900153static int stm32_count_ceiling_read(struct counter_device *counter,
154 struct counter_count *count, u64 *ceiling)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900155{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100156 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900157 u32 arr;
158
159 regmap_read(priv->regmap, TIM_ARR, &arr);
160
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900161 *ceiling = arr;
162
163 return 0;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900164}
165
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900166static int stm32_count_ceiling_write(struct counter_device *counter,
167 struct counter_count *count, u64 ceiling)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900168{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100169 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900170
Fabrice Gasniere4c3e132021-03-02 15:43:55 +0100171 if (ceiling > priv->max_arr)
172 return -ERANGE;
173
Benjamin Gaignardad299372019-04-02 15:30:42 +0900174 /* TIMx_ARR register shouldn't be buffered (ARPE=0) */
175 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0);
176 regmap_write(priv->regmap, TIM_ARR, ceiling);
177
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900178 return 0;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900179}
180
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900181static int stm32_count_enable_read(struct counter_device *counter,
182 struct counter_count *count, u8 *enable)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900183{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100184 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900185 u32 cr1;
186
187 regmap_read(priv->regmap, TIM_CR1, &cr1);
188
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900189 *enable = cr1 & TIM_CR1_CEN;
190
191 return 0;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900192}
193
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900194static int stm32_count_enable_write(struct counter_device *counter,
195 struct counter_count *count, u8 enable)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900196{
Uwe Kleine-Könige1528332021-12-30 16:02:49 +0100197 struct stm32_timer_cnt *const priv = counter_priv(counter);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900198 u32 cr1;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900199
200 if (enable) {
201 regmap_read(priv->regmap, TIM_CR1, &cr1);
Colin Ian King76510ec2019-09-25 10:51:26 +0100202 if (!(cr1 & TIM_CR1_CEN))
203 clk_enable(priv->clk);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900204
205 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
206 TIM_CR1_CEN);
207 } else {
208 regmap_read(priv->regmap, TIM_CR1, &cr1);
209 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
210 if (cr1 & TIM_CR1_CEN)
211 clk_disable(priv->clk);
212 }
213
Fabrice Gasnierc5b84252020-02-10 18:19:58 +0100214 /* Keep enabled state to properly handle low power states */
215 priv->enabled = enable;
216
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900217 return 0;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900218}
219
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900220static struct counter_comp stm32_count_ext[] = {
221 COUNTER_COMP_DIRECTION(stm32_count_direction_read),
222 COUNTER_COMP_ENABLE(stm32_count_enable_read, stm32_count_enable_write),
223 COUNTER_COMP_CEILING(stm32_count_ceiling_read,
224 stm32_count_ceiling_write),
Benjamin Gaignardad299372019-04-02 15:30:42 +0900225};
226
William Breathitt Grayd0ce3d52021-06-09 10:31:20 +0900227static const enum counter_synapse_action stm32_synapse_actions[] = {
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900228 COUNTER_SYNAPSE_ACTION_NONE,
229 COUNTER_SYNAPSE_ACTION_BOTH_EDGES
Benjamin Gaignardad299372019-04-02 15:30:42 +0900230};
231
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900232static int stm32_action_read(struct counter_device *counter,
233 struct counter_count *count,
234 struct counter_synapse *synapse,
235 enum counter_synapse_action *action)
Benjamin Gaignardad299372019-04-02 15:30:42 +0900236{
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900237 enum counter_function function;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900238 int err;
239
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900240 err = stm32_count_function_read(counter, count, &function);
Benjamin Gaignardad299372019-04-02 15:30:42 +0900241 if (err)
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900242 return err;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900243
244 switch (function) {
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900245 case COUNTER_FUNCTION_INCREASE:
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900246 /* counts on internal clock when CEN=1 */
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900247 *action = COUNTER_SYNAPSE_ACTION_NONE;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900248 return 0;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900249 case COUNTER_FUNCTION_QUADRATURE_X2_A:
Benjamin Gaignardad299372019-04-02 15:30:42 +0900250 /* counts up/down on TI1FP1 edge depending on TI2FP2 level */
251 if (synapse->signal->id == count->synapses[0].signal->id)
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900252 *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900253 else
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900254 *action = COUNTER_SYNAPSE_ACTION_NONE;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900255 return 0;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900256 case COUNTER_FUNCTION_QUADRATURE_X2_B:
Benjamin Gaignardad299372019-04-02 15:30:42 +0900257 /* counts up/down on TI2FP2 edge depending on TI1FP1 level */
258 if (synapse->signal->id == count->synapses[1].signal->id)
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900259 *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900260 else
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900261 *action = COUNTER_SYNAPSE_ACTION_NONE;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900262 return 0;
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900263 case COUNTER_FUNCTION_QUADRATURE_X4:
Benjamin Gaignardad299372019-04-02 15:30:42 +0900264 /* counts up/down on both TI1FP1 and TI2FP2 edges */
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900265 *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
William Breathitt Grayfae6f622021-02-26 10:29:31 +0900266 return 0;
267 default:
268 return -EINVAL;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900269 }
Benjamin Gaignardad299372019-04-02 15:30:42 +0900270}
271
272static const struct counter_ops stm32_timer_cnt_ops = {
273 .count_read = stm32_count_read,
274 .count_write = stm32_count_write,
William Breathitt Grayaaec1a02021-08-27 12:47:47 +0900275 .function_read = stm32_count_function_read,
276 .function_write = stm32_count_function_write,
277 .action_read = stm32_action_read,
Benjamin Gaignardad299372019-04-02 15:30:42 +0900278};
279
280static struct counter_signal stm32_signals[] = {
281 {
282 .id = 0,
283 .name = "Channel 1 Quadrature A"
284 },
285 {
286 .id = 1,
287 .name = "Channel 1 Quadrature B"
288 }
289};
290
291static struct counter_synapse stm32_count_synapses[] = {
292 {
293 .actions_list = stm32_synapse_actions,
294 .num_actions = ARRAY_SIZE(stm32_synapse_actions),
295 .signal = &stm32_signals[0]
296 },
297 {
298 .actions_list = stm32_synapse_actions,
299 .num_actions = ARRAY_SIZE(stm32_synapse_actions),
300 .signal = &stm32_signals[1]
301 }
302};
303
304static struct counter_count stm32_counts = {
305 .id = 0,
306 .name = "Channel 1 Count",
307 .functions_list = stm32_count_functions,
308 .num_functions = ARRAY_SIZE(stm32_count_functions),
309 .synapses = stm32_count_synapses,
310 .num_synapses = ARRAY_SIZE(stm32_count_synapses),
311 .ext = stm32_count_ext,
312 .num_ext = ARRAY_SIZE(stm32_count_ext)
313};
314
315static int stm32_timer_cnt_probe(struct platform_device *pdev)
316{
317 struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
318 struct device *dev = &pdev->dev;
319 struct stm32_timer_cnt *priv;
320
321 if (IS_ERR_OR_NULL(ddata))
322 return -EINVAL;
323
324 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
325 if (!priv)
326 return -ENOMEM;
327
328 priv->regmap = ddata->regmap;
329 priv->clk = ddata->clk;
Fabrice Gasniere4c3e132021-03-02 15:43:55 +0100330 priv->max_arr = ddata->max_arr;
Benjamin Gaignardad299372019-04-02 15:30:42 +0900331
332 priv->counter.name = dev_name(dev);
333 priv->counter.parent = dev;
334 priv->counter.ops = &stm32_timer_cnt_ops;
335 priv->counter.counts = &stm32_counts;
336 priv->counter.num_counts = 1;
337 priv->counter.signals = stm32_signals;
338 priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
339 priv->counter.priv = priv;
340
Fabrice Gasnierc5b84252020-02-10 18:19:58 +0100341 platform_set_drvdata(pdev, priv);
342
Benjamin Gaignardad299372019-04-02 15:30:42 +0900343 /* Register Counter device */
344 return devm_counter_register(dev, &priv->counter);
345}
346
Fabrice Gasnierc5b84252020-02-10 18:19:58 +0100347static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)
348{
349 struct stm32_timer_cnt *priv = dev_get_drvdata(dev);
350
351 /* Only take care of enabled counter: don't disturb other MFD child */
352 if (priv->enabled) {
353 /* Backup registers that may get lost in low power mode */
354 regmap_read(priv->regmap, TIM_SMCR, &priv->bak.smcr);
355 regmap_read(priv->regmap, TIM_ARR, &priv->bak.arr);
356 regmap_read(priv->regmap, TIM_CNT, &priv->bak.cnt);
357 regmap_read(priv->regmap, TIM_CR1, &priv->bak.cr1);
358
359 /* Disable the counter */
360 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
361 clk_disable(priv->clk);
362 }
363
364 return pinctrl_pm_select_sleep_state(dev);
365}
366
367static int __maybe_unused stm32_timer_cnt_resume(struct device *dev)
368{
369 struct stm32_timer_cnt *priv = dev_get_drvdata(dev);
370 int ret;
371
372 ret = pinctrl_pm_select_default_state(dev);
373 if (ret)
374 return ret;
375
376 if (priv->enabled) {
377 clk_enable(priv->clk);
378
379 /* Restore registers that may have been lost */
380 regmap_write(priv->regmap, TIM_SMCR, priv->bak.smcr);
381 regmap_write(priv->regmap, TIM_ARR, priv->bak.arr);
382 regmap_write(priv->regmap, TIM_CNT, priv->bak.cnt);
383
384 /* Also re-enables the counter */
385 regmap_write(priv->regmap, TIM_CR1, priv->bak.cr1);
386 }
387
388 return 0;
389}
390
391static SIMPLE_DEV_PM_OPS(stm32_timer_cnt_pm_ops, stm32_timer_cnt_suspend,
392 stm32_timer_cnt_resume);
393
Benjamin Gaignardad299372019-04-02 15:30:42 +0900394static const struct of_device_id stm32_timer_cnt_of_match[] = {
395 { .compatible = "st,stm32-timer-counter", },
396 {},
397};
398MODULE_DEVICE_TABLE(of, stm32_timer_cnt_of_match);
399
400static struct platform_driver stm32_timer_cnt_driver = {
401 .probe = stm32_timer_cnt_probe,
402 .driver = {
403 .name = "stm32-timer-counter",
404 .of_match_table = stm32_timer_cnt_of_match,
Fabrice Gasnierc5b84252020-02-10 18:19:58 +0100405 .pm = &stm32_timer_cnt_pm_ops,
Benjamin Gaignardad299372019-04-02 15:30:42 +0900406 },
407};
408module_platform_driver(stm32_timer_cnt_driver);
409
410MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
411MODULE_ALIAS("platform:stm32-timer-counter");
412MODULE_DESCRIPTION("STMicroelectronics STM32 TIMER counter driver");
413MODULE_LICENSE("GPL v2");