Skip to contentSkip to conversation

counter/ftm-quaddec: Use device-managed registration API

PATCH In review Chuhong Yuan 3 participants 3 messages Jul 26, 2019 – Jul 29, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 counter/ftm-quaddec: Use device-managed registration API

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

---
Changes in v2:
- Use devm_add_action_or_reset to keep
resource release order.
- remove() function is redundant now,
delete it.

 drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/counter/ftm-quaddec.c +12 -18
index 68a9b7393457..4046aa9f9234 100644
@@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
 	ftm_set_write_protection(ftm);
 }
 
-static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+static void ftm_quaddec_disable(void *ftm)
 {
-	ftm_clear_write_protection(ftm);
-	ftm_write(ftm, FTM_MODE, 0);
-	ftm_write(ftm, FTM_QDCTRL, 0);
+	struct ftm_quaddec *ftm_qua = ftm;
+
+	ftm_clear_write_protection(ftm_qua);
+	ftm_write(ftm_qua, FTM_MODE, 0);
+	ftm_write(ftm_qua, FTM_QDCTRL, 0);
 	/*
 	 * This is enough to disable the counter. No clock has been
 	 * selected by writing to FTM_SC in init()
 	 */
-	ftm_set_write_protection(ftm);
+	ftm_set_write_protection(ftm_qua);
 }
 
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
 	ftm_quaddec_init(ftm);
 
-	ret = counter_register(&ftm->counter);
+	ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
 	if (ret)
-		ftm_quaddec_disable(ftm);
-
-	return ret;
-}
+		return ret;
 
-static int ftm_quaddec_remove(struct platform_device *pdev)
-{
-	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
-
-	counter_unregister(&ftm->counter);
-
-	ftm_quaddec_disable(ftm);
+	ret = devm_counter_register(&pdev->dev, &ftm->counter);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
 		.of_match_table = ftm_quaddec_match,
 	},
 	.probe = ftm_quaddec_probe,
-	.remove = ftm_quaddec_remove,
 };
 
 module_platform_driver(ftm_quaddec_driver);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · On Fri, 26 Jul 2019 21:39:16 +0800 Chuhong Yuan <[email protected]> wrote:

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 72 lines

---
Changes in v2:
- Use devm_add_action_or_reset to keep
resource release order.
- remove() function is redundant now,
delete it.

 drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/counter/ftm-quaddec.c +12 -18
index 68a9b7393457..4046aa9f9234 100644
@@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
 	ftm_set_write_protection(ftm);
 }
 
-static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+static void ftm_quaddec_disable(void *ftm)
 {
-	ftm_clear_write_protection(ftm);
-	ftm_write(ftm, FTM_MODE, 0);
-	ftm_write(ftm, FTM_QDCTRL, 0);
+	struct ftm_quaddec *ftm_qua = ftm;
+
+	ftm_clear_write_protection(ftm_qua);
+	ftm_write(ftm_qua, FTM_MODE, 0);
+	ftm_write(ftm_qua, FTM_QDCTRL, 0);
 	/*
 	 * This is enough to disable the counter. No clock has been
 	 * selected by writing to FTM_SC in init()
 	 */
-	ftm_set_write_protection(ftm);
+	ftm_set_write_protection(ftm_qua);
 }
 
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
 	ftm_quaddec_init(ftm);
 
-	ret = counter_register(&ftm->counter);
+	ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
 	if (ret)
-		ftm_quaddec_disable(ftm);
-
-	return ret;
-}
+		return ret;
 
-static int ftm_quaddec_remove(struct platform_device *pdev)
-{
-	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
-
-	counter_unregister(&ftm->counter);
-
-	ftm_quaddec_disable(ftm);
+	ret = devm_counter_register(&pdev->dev, &ftm->counter);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
 		.of_match_table = ftm_quaddec_match,
 	},
 	.probe = ftm_quaddec_probe,
-	.remove = ftm_quaddec_remove,
 };
 
 module_platform_driver(ftm_quaddec_driver);
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Chuhong Yuan
Quoted 6 lines · Chuhong Yuan

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

Maybe a bit too late, sorry for that. Thanks for the patch.

Patrick H.

Quoted 75 lines

---
Changes in v2:
- Use devm_add_action_or_reset to keep
resource release order.
- remove() function is redundant now,
delete it.

 drivers/counter/ftm-quaddec.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/counter/ftm-quaddec.c +12 -19
index 68a9b7393457..4046aa9f9234 100644
@@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
        ftm_set_write_protection(ftm);
 }
 
-static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+static void ftm_quaddec_disable(void *ftm)
 {
-       ftm_clear_write_protection(ftm);
-       ftm_write(ftm, FTM_MODE, 0);
-       ftm_write(ftm, FTM_QDCTRL, 0);
+       struct ftm_quaddec *ftm_qua = ftm;
+
+       ftm_clear_write_protection(ftm_qua);
+       ftm_write(ftm_qua, FTM_MODE, 0);
+       ftm_write(ftm_qua, FTM_QDCTRL, 0);
        /*
         * This is enough to disable the counter. No clock has been
         * selected by writing to FTM_SC in init()
         */
-       ftm_set_write_protection(ftm);
+       ftm_set_write_protection(ftm_qua);
 }
 
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
        ftm_quaddec_init(ftm);
 
-       ret = counter_register(&ftm->counter);
+       ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
        if (ret)
-               ftm_quaddec_disable(ftm);
-
-       return ret;
-}
+               return ret;
 
-static int ftm_quaddec_remove(struct platform_device *pdev)
-{
-       struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
-
-       counter_unregister(&ftm->counter);
-
-       ftm_quaddec_disable(ftm);
+       ret = devm_counter_register(&pdev->dev, &ftm->counter);
+       if (ret)
+               return ret;
 
        return 0;
 }
@@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
                .of_match_table = ftm_quaddec_match,
        },
        .probe = ftm_quaddec_probe,
-       .remove = ftm_quaddec_remove,
 };
 
 module_platform_driver(ftm_quaddec_driver);
--

2.20.1