|
20 | 20 | #include <linux/types.h>
|
21 | 21 |
|
22 | 22 | struct stm32_lptim_cnt {
|
23 |
| - struct counter_device counter; |
24 | 23 | struct device *dev;
|
25 | 24 | struct regmap *regmap;
|
26 | 25 | struct clk *clk;
|
@@ -411,38 +410,44 @@ static struct counter_count stm32_lptim_in1_counts = {
|
411 | 410 | static int stm32_lptim_cnt_probe(struct platform_device *pdev)
|
412 | 411 | {
|
413 | 412 | struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
|
| 413 | + struct counter_device *counter; |
414 | 414 | struct stm32_lptim_cnt *priv;
|
| 415 | + int ret; |
415 | 416 |
|
416 | 417 | if (IS_ERR_OR_NULL(ddata))
|
417 | 418 | return -EINVAL;
|
418 | 419 |
|
419 |
| - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
420 |
| - if (!priv) |
| 420 | + counter = devm_counter_alloc(&pdev->dev, sizeof(*priv)); |
| 421 | + if (!counter) |
421 | 422 | return -ENOMEM;
|
| 423 | + priv = counter_priv(counter); |
422 | 424 |
|
423 | 425 | priv->dev = &pdev->dev;
|
424 | 426 | priv->regmap = ddata->regmap;
|
425 | 427 | priv->clk = ddata->clk;
|
426 | 428 | priv->ceiling = STM32_LPTIM_MAX_ARR;
|
427 | 429 |
|
428 | 430 | /* Initialize Counter device */
|
429 |
| - priv->counter.name = dev_name(&pdev->dev); |
430 |
| - priv->counter.parent = &pdev->dev; |
431 |
| - priv->counter.ops = &stm32_lptim_cnt_ops; |
| 431 | + counter->name = dev_name(&pdev->dev); |
| 432 | + counter->parent = &pdev->dev; |
| 433 | + counter->ops = &stm32_lptim_cnt_ops; |
432 | 434 | if (ddata->has_encoder) {
|
433 |
| - priv->counter.counts = &stm32_lptim_enc_counts; |
434 |
| - priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals); |
| 435 | + counter->counts = &stm32_lptim_enc_counts; |
| 436 | + counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals); |
435 | 437 | } else {
|
436 |
| - priv->counter.counts = &stm32_lptim_in1_counts; |
437 |
| - priv->counter.num_signals = 1; |
| 438 | + counter->counts = &stm32_lptim_in1_counts; |
| 439 | + counter->num_signals = 1; |
438 | 440 | }
|
439 |
| - priv->counter.num_counts = 1; |
440 |
| - priv->counter.signals = stm32_lptim_cnt_signals; |
441 |
| - priv->counter.priv = priv; |
| 441 | + counter->num_counts = 1; |
| 442 | + counter->signals = stm32_lptim_cnt_signals; |
442 | 443 |
|
443 | 444 | platform_set_drvdata(pdev, priv);
|
444 | 445 |
|
445 |
| - return devm_counter_register(&pdev->dev, &priv->counter); |
| 446 | + ret = devm_counter_add(&pdev->dev, counter); |
| 447 | + if (ret < 0) |
| 448 | + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); |
| 449 | + |
| 450 | + return 0; |
446 | 451 | }
|
447 | 452 |
|
448 | 453 | #ifdef CONFIG_PM_SLEEP
|
|
0 commit comments