blob: 9e94a797dcf310bd4cd8fa148f3a1ef4938b2a5c [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) STMicroelectronics 2016
4 *
5 * Author: Gerald Baeza <gerald.baeza@st.com>
6 *
7 * Inspired by timer-stm32.c from Maxime Coquelin
8 * pwm-atmel.c from Bo Shen
9 */
10
11#include <linux/bitfield.h>
12#include <linux/mfd/stm32-timers.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/platform_device.h>
16#include <linux/pwm.h>
17
18#define CCMR_CHANNEL_SHIFT 8
19#define CCMR_CHANNEL_MASK 0xFF
20#define MAX_BREAKINPUT 2
21
22struct stm32_pwm {
23 struct pwm_chip chip;
24 struct mutex lock; /* protect pwm config/enable */
25 struct clk *clk;
26 struct regmap *regmap;
27 u32 max_arr;
28 bool have_complementary_output;
29 u32 capture[4] ____cacheline_aligned; /* DMA'able buffer */
30};
31
32struct stm32_breakinput {
33 u32 index;
34 u32 level;
35 u32 filter;
36};
37
38static inline struct stm32_pwm *to_stm32_pwm_dev(struct pwm_chip *chip)
39{
40 return container_of(chip, struct stm32_pwm, chip);
41}
42
43static u32 active_channels(struct stm32_pwm *dev)
44{
45 u32 ccer;
46
47 regmap_read(dev->regmap, TIM_CCER, &ccer);
48
49 return ccer & TIM_CCER_CCXE;
50}
51
52static int write_ccrx(struct stm32_pwm *dev, int ch, u32 value)
53{
54 switch (ch) {
55 case 0:
56 return regmap_write(dev->regmap, TIM_CCR1, value);
57 case 1:
58 return regmap_write(dev->regmap, TIM_CCR2, value);
59 case 2:
60 return regmap_write(dev->regmap, TIM_CCR3, value);
61 case 3:
62 return regmap_write(dev->regmap, TIM_CCR4, value);
63 }
64 return -EINVAL;
65}
66
67#define TIM_CCER_CC12P (TIM_CCER_CC1P | TIM_CCER_CC2P)
68#define TIM_CCER_CC12E (TIM_CCER_CC1E | TIM_CCER_CC2E)
69#define TIM_CCER_CC34P (TIM_CCER_CC3P | TIM_CCER_CC4P)
70#define TIM_CCER_CC34E (TIM_CCER_CC3E | TIM_CCER_CC4E)
71
72/*
73 * Capture using PWM input mode:
74 * ___ ___
75 * TI[1, 2, 3 or 4]: ........._| |________|
76 * ^0 ^1 ^2
77 * . . .
78 * . . XXXXX
79 * . . XXXXX |
80 * . XXXXX . |
81 * XXXXX . . |
82 * COUNTER: ______XXXXX . . . |_XXX
83 * start^ . . . ^stop
84 * . . . .
85 * v v . v
86 * v
87 * CCR1/CCR3: tx..........t0...........t2
88 * CCR2/CCR4: tx..............t1.........
89 *
90 * DMA burst transfer: | |
91 * v v
92 * DMA buffer: { t0, tx } { t2, t1 }
93 * DMA done: ^
94 *
95 * 0: IC1/3 snapchot on rising edge: counter value -> CCR1/CCR3
96 * + DMA transfer CCR[1/3] & CCR[2/4] values (t0, tx: doesn't care)
97 * 1: IC2/4 snapchot on falling edge: counter value -> CCR2/CCR4
98 * 2: IC1/3 snapchot on rising edge: counter value -> CCR1/CCR3
99 * + DMA transfer CCR[1/3] & CCR[2/4] values (t2, t1)
100 *
101 * DMA done, compute:
102 * - Period = t2 - t0
103 * - Duty cycle = t1 - t0
104 */
105static int stm32_pwm_raw_capture(struct stm32_pwm *priv, struct pwm_device *pwm,
106 unsigned long tmo_ms, u32 *raw_prd,
107 u32 *raw_dty)
108{
109 struct device *parent = priv->chip.dev->parent;
110 enum stm32_timers_dmas dma_id;
111 u32 ccen, ccr;
112 int ret;
113
114 /* Ensure registers have been updated, enable counter and capture */
115 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
116 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, TIM_CR1_CEN);
117
118 /* Use cc1 or cc3 DMA resp for PWM input channels 1 & 2 or 3 & 4 */
119 dma_id = pwm->hwpwm < 2 ? STM32_TIMERS_DMA_CH1 : STM32_TIMERS_DMA_CH3;
120 ccen = pwm->hwpwm < 2 ? TIM_CCER_CC12E : TIM_CCER_CC34E;
121 ccr = pwm->hwpwm < 2 ? TIM_CCR1 : TIM_CCR3;
122 regmap_update_bits(priv->regmap, TIM_CCER, ccen, ccen);
123
124 /*
125 * Timer DMA burst mode. Request 2 registers, 2 bursts, to get both
126 * CCR1 & CCR2 (or CCR3 & CCR4) on each capture event.
127 * We'll get two capture snapchots: { CCR1, CCR2 }, { CCR1, CCR2 }
128 * or { CCR3, CCR4 }, { CCR3, CCR4 }
129 */
130 ret = stm32_timers_dma_burst_read(parent, priv->capture, dma_id, ccr, 2,
131 2, tmo_ms);
132 if (ret)
133 goto stop;
134
135 /* Period: t2 - t0 (take care of counter overflow) */
136 if (priv->capture[0] <= priv->capture[2])
137 *raw_prd = priv->capture[2] - priv->capture[0];
138 else
139 *raw_prd = priv->max_arr - priv->capture[0] + priv->capture[2];
140
141 /* Duty cycle capture requires at least two capture units */
142 if (pwm->chip->npwm < 2)
143 *raw_dty = 0;
144 else if (priv->capture[0] <= priv->capture[3])
145 *raw_dty = priv->capture[3] - priv->capture[0];
146 else
147 *raw_dty = priv->max_arr - priv->capture[0] + priv->capture[3];
148
149 if (*raw_dty > *raw_prd) {
150 /*
151 * Race beetween PWM input and DMA: it may happen
152 * falling edge triggers new capture on TI2/4 before DMA
153 * had a chance to read CCR2/4. It means capture[1]
154 * contains period + duty_cycle. So, subtract period.
155 */
156 *raw_dty -= *raw_prd;
157 }
158
159stop:
160 regmap_update_bits(priv->regmap, TIM_CCER, ccen, 0);
161 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
162
163 return ret;
164}
165
166static int stm32_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
167 struct pwm_capture *result, unsigned long tmo_ms)
168{
169 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
170 unsigned long long prd, div, dty;
171 unsigned long rate;
172 unsigned int psc = 0, icpsc, scale;
173 u32 raw_prd = 0, raw_dty = 0;
174 int ret = 0;
175
176 mutex_lock(&priv->lock);
177
178 if (active_channels(priv)) {
179 ret = -EBUSY;
180 goto unlock;
181 }
182
183 ret = clk_enable(priv->clk);
184 if (ret) {
185 dev_err(priv->chip.dev, "failed to enable counter clock\n");
186 goto unlock;
187 }
188
189 rate = clk_get_rate(priv->clk);
190 if (!rate) {
191 ret = -EINVAL;
192 goto clk_dis;
193 }
194
195 /* prescaler: fit timeout window provided by upper layer */
196 div = (unsigned long long)rate * (unsigned long long)tmo_ms;
197 do_div(div, MSEC_PER_SEC);
198 prd = div;
199 while ((div > priv->max_arr) && (psc < MAX_TIM_PSC)) {
200 psc++;
201 div = prd;
202 do_div(div, psc + 1);
203 }
204 regmap_write(priv->regmap, TIM_ARR, priv->max_arr);
205 regmap_write(priv->regmap, TIM_PSC, psc);
206
207 /* Map TI1 or TI2 PWM input to IC1 & IC2 (or TI3/4 to IC3 & IC4) */
208 regmap_update_bits(priv->regmap,
209 pwm->hwpwm < 2 ? TIM_CCMR1 : TIM_CCMR2,
210 TIM_CCMR_CC1S | TIM_CCMR_CC2S, pwm->hwpwm & 0x1 ?
211 TIM_CCMR_CC1S_TI2 | TIM_CCMR_CC2S_TI2 :
212 TIM_CCMR_CC1S_TI1 | TIM_CCMR_CC2S_TI1);
213
214 /* Capture period on IC1/3 rising edge, duty cycle on IC2/4 falling. */
215 regmap_update_bits(priv->regmap, TIM_CCER, pwm->hwpwm < 2 ?
216 TIM_CCER_CC12P : TIM_CCER_CC34P, pwm->hwpwm < 2 ?
217 TIM_CCER_CC2P : TIM_CCER_CC4P);
218
219 ret = stm32_pwm_raw_capture(priv, pwm, tmo_ms, &raw_prd, &raw_dty);
220 if (ret)
221 goto stop;
222
223 /*
224 * Got a capture. Try to improve accuracy at high rates:
225 * - decrease counter clock prescaler, scale up to max rate.
226 * - use input prescaler, capture once every /2 /4 or /8 edges.
227 */
228 if (raw_prd) {
229 u32 max_arr = priv->max_arr - 0x1000; /* arbitrary margin */
230
231 scale = max_arr / min(max_arr, raw_prd);
232 } else {
233 scale = priv->max_arr; /* bellow resolution, use max scale */
234 }
235
236 if (psc && scale > 1) {
237 /* 2nd measure with new scale */
238 psc /= scale;
239 regmap_write(priv->regmap, TIM_PSC, psc);
240 ret = stm32_pwm_raw_capture(priv, pwm, tmo_ms, &raw_prd,
241 &raw_dty);
242 if (ret)
243 goto stop;
244 }
245
246 /* Compute intermediate period not to exceed timeout at low rates */
247 prd = (unsigned long long)raw_prd * (psc + 1) * NSEC_PER_SEC;
248 do_div(prd, rate);
249
250 for (icpsc = 0; icpsc < MAX_TIM_ICPSC ; icpsc++) {
251 /* input prescaler: also keep arbitrary margin */
252 if (raw_prd >= (priv->max_arr - 0x1000) >> (icpsc + 1))
253 break;
254 if (prd >= (tmo_ms * NSEC_PER_MSEC) >> (icpsc + 2))
255 break;
256 }
257
258 if (!icpsc)
259 goto done;
260
261 /* Last chance to improve period accuracy, using input prescaler */
262 regmap_update_bits(priv->regmap,
263 pwm->hwpwm < 2 ? TIM_CCMR1 : TIM_CCMR2,
264 TIM_CCMR_IC1PSC | TIM_CCMR_IC2PSC,
265 FIELD_PREP(TIM_CCMR_IC1PSC, icpsc) |
266 FIELD_PREP(TIM_CCMR_IC2PSC, icpsc));
267
268 ret = stm32_pwm_raw_capture(priv, pwm, tmo_ms, &raw_prd, &raw_dty);
269 if (ret)
270 goto stop;
271
272 if (raw_dty >= (raw_prd >> icpsc)) {
273 /*
274 * We may fall here using input prescaler, when input
275 * capture starts on high side (before falling edge).
276 * Example with icpsc to capture on each 4 events:
277 *
278 * start 1st capture 2nd capture
279 * v v v
280 * ___ _____ _____ _____ _____ ____
281 * TI1..4 |__| |__| |__| |__| |__|
282 * v v . . . . . v v
283 * icpsc1/3: . 0 . 1 . 2 . 3 . 0
284 * icpsc2/4: 0 1 2 3 0
285 * v v v v
286 * CCR1/3 ......t0..............................t2
287 * CCR2/4 ..t1..............................t1'...
288 * . . .
289 * Capture0: .<----------------------------->.
290 * Capture1: .<-------------------------->. .
291 * . . .
292 * Period: .<------> . .
293 * Low side: .<>.
294 *
295 * Result:
296 * - Period = Capture0 / icpsc
297 * - Duty = Period - Low side = Period - (Capture0 - Capture1)
298 */
299 raw_dty = (raw_prd >> icpsc) - (raw_prd - raw_dty);
300 }
301
302done:
303 prd = (unsigned long long)raw_prd * (psc + 1) * NSEC_PER_SEC;
304 result->period = DIV_ROUND_UP_ULL(prd, rate << icpsc);
305 dty = (unsigned long long)raw_dty * (psc + 1) * NSEC_PER_SEC;
306 result->duty_cycle = DIV_ROUND_UP_ULL(dty, rate);
307stop:
308 regmap_write(priv->regmap, TIM_CCER, 0);
309 regmap_write(priv->regmap, pwm->hwpwm < 2 ? TIM_CCMR1 : TIM_CCMR2, 0);
310 regmap_write(priv->regmap, TIM_PSC, 0);
311clk_dis:
312 clk_disable(priv->clk);
313unlock:
314 mutex_unlock(&priv->lock);
315
316 return ret;
317}
318
319static int stm32_pwm_config(struct stm32_pwm *priv, int ch,
320 int duty_ns, int period_ns)
321{
322 unsigned long long prd, div, dty;
323 unsigned int prescaler = 0;
324 u32 ccmr, mask, shift;
325
326 /* Period and prescaler values depends on clock rate */
327 div = (unsigned long long)clk_get_rate(priv->clk) * period_ns;
328
329 do_div(div, NSEC_PER_SEC);
330 prd = div;
331
332 while (div > priv->max_arr) {
333 prescaler++;
334 div = prd;
335 do_div(div, prescaler + 1);
336 }
337
338 prd = div;
339
340 if (!prd)
341 return -EINVAL;
342
343 if (prescaler > MAX_TIM_PSC)
344 return -EINVAL;
345
346 /*
347 * All channels share the same prescaler and counter so when two
348 * channels are active at the same time we can't change them
349 */
350 if (active_channels(priv) & ~(1 << ch * 4)) {
351 u32 psc, arr;
352
353 regmap_read(priv->regmap, TIM_PSC, &psc);
354 regmap_read(priv->regmap, TIM_ARR, &arr);
355
356 if ((psc != prescaler) || (arr != prd - 1))
357 return -EBUSY;
358 }
359
360 regmap_write(priv->regmap, TIM_PSC, prescaler);
361 regmap_write(priv->regmap, TIM_ARR, prd - 1);
362 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
363
364 /* Calculate the duty cycles */
365 dty = prd * duty_ns;
366 do_div(dty, period_ns);
367
368 write_ccrx(priv, ch, dty);
369
370 /* Configure output mode */
371 shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT;
372 ccmr = (TIM_CCMR_PE | TIM_CCMR_M1) << shift;
373 mask = CCMR_CHANNEL_MASK << shift;
374
375 if (ch < 2)
376 regmap_update_bits(priv->regmap, TIM_CCMR1, mask, ccmr);
377 else
378 regmap_update_bits(priv->regmap, TIM_CCMR2, mask, ccmr);
379
380 regmap_update_bits(priv->regmap, TIM_BDTR,
381 TIM_BDTR_MOE | TIM_BDTR_AOE,
382 TIM_BDTR_MOE | TIM_BDTR_AOE);
383
384 return 0;
385}
386
387static int stm32_pwm_set_polarity(struct stm32_pwm *priv, int ch,
388 enum pwm_polarity polarity)
389{
390 u32 mask;
391
392 mask = TIM_CCER_CC1P << (ch * 4);
393 if (priv->have_complementary_output)
394 mask |= TIM_CCER_CC1NP << (ch * 4);
395
396 regmap_update_bits(priv->regmap, TIM_CCER, mask,
397 polarity == PWM_POLARITY_NORMAL ? 0 : mask);
398
399 return 0;
400}
401
402static int stm32_pwm_enable(struct stm32_pwm *priv, int ch)
403{
404 u32 mask;
405 int ret;
406
407 ret = clk_enable(priv->clk);
408 if (ret)
409 return ret;
410
411 /* Enable channel */
412 mask = TIM_CCER_CC1E << (ch * 4);
413 if (priv->have_complementary_output)
414 mask |= TIM_CCER_CC1NE << (ch * 4);
415
416 regmap_update_bits(priv->regmap, TIM_CCER, mask, mask);
417
418 /* Make sure that registers are updated */
419 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
420
421 /* Enable controller */
422 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, TIM_CR1_CEN);
423
424 return 0;
425}
426
427static void stm32_pwm_disable(struct stm32_pwm *priv, int ch)
428{
429 u32 mask;
430
431 /* Disable channel */
432 mask = TIM_CCER_CC1E << (ch * 4);
433 if (priv->have_complementary_output)
434 mask |= TIM_CCER_CC1NE << (ch * 4);
435
436 regmap_update_bits(priv->regmap, TIM_CCER, mask, 0);
437
438 /* When all channels are disabled, we can disable the controller */
439 if (!active_channels(priv))
440 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
441
442 clk_disable(priv->clk);
443}
444
445static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
446 const struct pwm_state *state)
447{
448 bool enabled;
449 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
450 int ret;
451
452 enabled = pwm->state.enabled;
453
454 if (!state->enabled) {
455 if (enabled)
456 stm32_pwm_disable(priv, pwm->hwpwm);
457 return 0;
458 }
459
460 if (state->polarity != pwm->state.polarity)
461 stm32_pwm_set_polarity(priv, pwm->hwpwm, state->polarity);
462
463 ret = stm32_pwm_config(priv, pwm->hwpwm,
464 state->duty_cycle, state->period);
465 if (ret)
466 return ret;
467
468 if (!enabled && state->enabled)
469 ret = stm32_pwm_enable(priv, pwm->hwpwm);
470
471 return ret;
472}
473
474static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm,
475 const struct pwm_state *state)
476{
477 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
478 int ret;
479
480 /* protect common prescaler for all active channels */
481 mutex_lock(&priv->lock);
482 ret = stm32_pwm_apply(chip, pwm, state);
483 mutex_unlock(&priv->lock);
484
485 return ret;
486}
487
488static const struct pwm_ops stm32pwm_ops = {
489 .owner = THIS_MODULE,
490 .apply = stm32_pwm_apply_locked,
491 .capture = IS_ENABLED(CONFIG_DMA_ENGINE) ? stm32_pwm_capture : NULL,
492};
493
494static int stm32_pwm_set_breakinput(struct stm32_pwm *priv,
495 int index, int level, int filter)
496{
497 u32 bke = (index == 0) ? TIM_BDTR_BKE : TIM_BDTR_BK2E;
498 int shift = (index == 0) ? TIM_BDTR_BKF_SHIFT : TIM_BDTR_BK2F_SHIFT;
499 u32 mask = (index == 0) ? TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF
500 : TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F;
501 u32 bdtr = bke;
502
503 /*
504 * The both bits could be set since only one will be wrote
505 * due to mask value.
506 */
507 if (level)
508 bdtr |= TIM_BDTR_BKP | TIM_BDTR_BK2P;
509
510 bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift;
511
512 regmap_update_bits(priv->regmap, TIM_BDTR, mask, bdtr);
513
514 regmap_read(priv->regmap, TIM_BDTR, &bdtr);
515
516 return (bdtr & bke) ? 0 : -EINVAL;
517}
518
519static int stm32_pwm_apply_breakinputs(struct stm32_pwm *priv,
520 struct device_node *np)
521{
522 struct stm32_breakinput breakinput[MAX_BREAKINPUT];
523 int nb, ret, i, array_size;
524
525 nb = of_property_count_elems_of_size(np, "st,breakinput",
526 sizeof(struct stm32_breakinput));
527
528 /*
529 * Because "st,breakinput" parameter is optional do not make probe
530 * failed if it doesn't exist.
531 */
532 if (nb <= 0)
533 return 0;
534
535 if (nb > MAX_BREAKINPUT)
536 return -EINVAL;
537
538 array_size = nb * sizeof(struct stm32_breakinput) / sizeof(u32);
539 ret = of_property_read_u32_array(np, "st,breakinput",
540 (u32 *)breakinput, array_size);
541 if (ret)
542 return ret;
543
544 for (i = 0; i < nb && !ret; i++) {
545 ret = stm32_pwm_set_breakinput(priv,
546 breakinput[i].index,
547 breakinput[i].level,
548 breakinput[i].filter);
549 }
550
551 return ret;
552}
553
554static void stm32_pwm_detect_complementary(struct stm32_pwm *priv)
555{
556 u32 ccer;
557
558 /*
559 * If complementary bit doesn't exist writing 1 will have no
560 * effect so we can detect it.
561 */
562 regmap_update_bits(priv->regmap,
563 TIM_CCER, TIM_CCER_CC1NE, TIM_CCER_CC1NE);
564 regmap_read(priv->regmap, TIM_CCER, &ccer);
565 regmap_update_bits(priv->regmap, TIM_CCER, TIM_CCER_CC1NE, 0);
566
567 priv->have_complementary_output = (ccer != 0);
568}
569
570static int stm32_pwm_detect_channels(struct stm32_pwm *priv)
571{
572 u32 ccer;
573 int npwm = 0;
574
575 /*
576 * If channels enable bits don't exist writing 1 will have no
577 * effect so we can detect and count them.
578 */
579 regmap_update_bits(priv->regmap,
580 TIM_CCER, TIM_CCER_CCXE, TIM_CCER_CCXE);
581 regmap_read(priv->regmap, TIM_CCER, &ccer);
582 regmap_update_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE, 0);
583
584 if (ccer & TIM_CCER_CC1E)
585 npwm++;
586
587 if (ccer & TIM_CCER_CC2E)
588 npwm++;
589
590 if (ccer & TIM_CCER_CC3E)
591 npwm++;
592
593 if (ccer & TIM_CCER_CC4E)
594 npwm++;
595
596 return npwm;
597}
598
599static int stm32_pwm_probe(struct platform_device *pdev)
600{
601 struct device *dev = &pdev->dev;
602 struct device_node *np = dev->of_node;
603 struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
604 struct stm32_pwm *priv;
605 int ret;
606
607 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
608 if (!priv)
609 return -ENOMEM;
610
611 mutex_init(&priv->lock);
612 priv->regmap = ddata->regmap;
613 priv->clk = ddata->clk;
614 priv->max_arr = ddata->max_arr;
615 priv->chip.of_xlate = of_pwm_xlate_with_flags;
616 priv->chip.of_pwm_n_cells = 3;
617
618 if (!priv->regmap || !priv->clk)
619 return -EINVAL;
620
621 ret = stm32_pwm_apply_breakinputs(priv, np);
622 if (ret)
623 return ret;
624
625 stm32_pwm_detect_complementary(priv);
626
627 priv->chip.base = -1;
628 priv->chip.dev = dev;
629 priv->chip.ops = &stm32pwm_ops;
630 priv->chip.npwm = stm32_pwm_detect_channels(priv);
631
632 ret = pwmchip_add(&priv->chip);
633 if (ret < 0)
634 return ret;
635
636 platform_set_drvdata(pdev, priv);
637
638 return 0;
639}
640
641static int stm32_pwm_remove(struct platform_device *pdev)
642{
643 struct stm32_pwm *priv = platform_get_drvdata(pdev);
644 unsigned int i;
645
646 for (i = 0; i < priv->chip.npwm; i++)
647 pwm_disable(&priv->chip.pwms[i]);
648
649 pwmchip_remove(&priv->chip);
650
651 return 0;
652}
653
654static const struct of_device_id stm32_pwm_of_match[] = {
655 { .compatible = "st,stm32-pwm", },
656 { /* end node */ },
657};
658MODULE_DEVICE_TABLE(of, stm32_pwm_of_match);
659
660static struct platform_driver stm32_pwm_driver = {
661 .probe = stm32_pwm_probe,
662 .remove = stm32_pwm_remove,
663 .driver = {
664 .name = "stm32-pwm",
665 .of_match_table = stm32_pwm_of_match,
666 },
667};
668module_platform_driver(stm32_pwm_driver);
669
670MODULE_ALIAS("platform:stm32-pwm");
671MODULE_DESCRIPTION("STMicroelectronics STM32 PWM driver");
672MODULE_LICENSE("GPL v2");