Skip to content

Commit 00062a9

Browse files
JuliaLawalljic23
authored andcommitted
drivers/iio/adc/at91_adc.c: use clk_prepare_enable and clk_disable_unprepare
Clk_prepare_enable and clk_disable_unprepare combine clk_prepare and clk_enable, and clk_disable and clk_unprepare. They make the code more concise, and ensure that clk_unprepare is called when clk_enable fails. A simplified version of the semantic patch that introduces calls to these functions is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression e; @@ - clk_prepare(e); - clk_enable(e); + clk_prepare_enable(e); @@ expression e; @@ - clk_disable(e); - clk_unprepare(e); + clk_disable_unprepare(e); // </smpl> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent f5ed9c3 commit 00062a9

1 file changed

Lines changed: 9 additions & 24 deletions

File tree

‎drivers/iio/adc/at91_adc.c‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -589,37 +589,27 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
589589
goto error_free_irq;
590590
}
591591

592-
ret = clk_prepare(st->clk);
592+
ret = clk_prepare_enable(st->clk);
593593
if (ret) {
594-
dev_err(&pdev->dev, "Could not prepare the clock.\n");
594+
dev_err(&pdev->dev,
595+
"Could not prepare or enable the clock.\n");
595596
goto error_free_irq;
596597
}
597598

598-
ret = clk_enable(st->clk);
599-
if (ret) {
600-
dev_err(&pdev->dev, "Could not enable the clock.\n");
601-
goto error_unprepare_clk;
602-
}
603-
604599
st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
605600
if (IS_ERR(st->adc_clk)) {
606601
dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
607602
ret = PTR_ERR(st->clk);
608603
goto error_disable_clk;
609604
}
610605

611-
ret = clk_prepare(st->adc_clk);
606+
ret = clk_prepare_enable(st->adc_clk);
612607
if (ret) {
613-
dev_err(&pdev->dev, "Could not prepare the ADC clock.\n");
608+
dev_err(&pdev->dev,
609+
"Could not prepare or enable the ADC clock.\n");
614610
goto error_disable_clk;
615611
}
616612

617-
ret = clk_enable(st->adc_clk);
618-
if (ret) {
619-
dev_err(&pdev->dev, "Could not enable the ADC clock.\n");
620-
goto error_unprepare_adc_clk;
621-
}
622-
623613
/*
624614
* Prescaler rate computation using the formula from the Atmel's
625615
* datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being
@@ -681,13 +671,9 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
681671
error_unregister_buffer:
682672
at91_adc_buffer_remove(idev);
683673
error_disable_adc_clk:
684-
clk_disable(st->adc_clk);
685-
error_unprepare_adc_clk:
686-
clk_unprepare(st->adc_clk);
674+
clk_disable_unprepare(st->adc_clk);
687675
error_disable_clk:
688-
clk_disable(st->clk);
689-
error_unprepare_clk:
690-
clk_unprepare(st->clk);
676+
clk_disable_unprepare(st->clk);
691677
error_free_irq:
692678
free_irq(st->irq, idev);
693679
error_free_device:
@@ -705,8 +691,7 @@ static int __devexit at91_adc_remove(struct platform_device *pdev)
705691
at91_adc_trigger_remove(idev);
706692
at91_adc_buffer_remove(idev);
707693
clk_disable_unprepare(st->adc_clk);
708-
clk_disable(st->clk);
709-
clk_unprepare(st->clk);
694+
clk_disable_unprepare(st->clk);
710695
free_irq(st->irq, idev);
711696
iio_device_free(idev);
712697

0 commit comments

Comments
 (0)