Skip to contentSkip to conversation

mailbox: sprd: Use devm_clk_get_enabled() helpers

PATCH Superseded Huan Yang 3 participants 6 messages Aug 21, 2024 – Aug 22, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Huan Yang

author
#0 lore raw

PATCH v2 1/1 mailbox: sprd: Use devm_clk_get_enabled() helpers

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

---
v1 -> v2: remove clk pointer from sprd_mbox_priv

 drivers/mailbox/sprd-mailbox.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/mailbox/sprd-mailbox.c +4 -21
index 9ae57de77d4d..ee8539dfcef5 100644
@@ -62,7 +62,6 @@ struct sprd_mbox_priv {
 	void __iomem		*outbox_base;
 	/*  Base register address for supplementary outbox */
 	void __iomem		*supp_base;
-	struct clk		*clk;
 	u32			outbox_fifo_depth;
 
 	struct mutex		lock;
@@ -291,19 +290,13 @@ static const struct mbox_chan_ops sprd_mbox_ops = {
 	.shutdown	= sprd_mbox_shutdown,
 };
 
-static void sprd_mbox_disable(void *data)
-{
-	struct sprd_mbox_priv *priv = data;
-
-	clk_disable_unprepare(priv->clk);
-}
-
 static int sprd_mbox_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct sprd_mbox_priv *priv;
 	int ret, inbox_irq, outbox_irq, supp_irq;
 	unsigned long id, supp;
+	struct clk *clk;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -331,20 +324,10 @@ static int sprd_mbox_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->outbox_base))
 		return PTR_ERR(priv->outbox_base);
 
-	priv->clk = devm_clk_get(dev, "enable");
-	if (IS_ERR(priv->clk)) {
+	clk = devm_clk_get_enabled(dev, "enable");
+	if (IS_ERR(clk)) {
 		dev_err(dev, "failed to get mailbox clock\n");
-		return PTR_ERR(priv->clk);
-	}
-
-	ret = clk_prepare_enable(priv->clk);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(dev, sprd_mbox_disable, priv);
-	if (ret) {
-		dev_err(dev, "failed to add mailbox disable action\n");
-		return ret;
+		return PTR_ERR(clk);
 	}
 
 	inbox_irq = platform_get_irq_byname(pdev, "inbox");
Signature · 1 line
2.45.2
Reviewed-by on v2 1/1
#1 lore raw

Le 21/08/2024 à 03:39, Huan Yang a écrit :

Quoted 5 lines

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

Quoted 7 lines

This simplifies the code and avoids the calls to clk_disable_unprepare().

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

Nitpick: no need to add this S-b. I just made a comment when looking at your patch in order to improve it. I'm not the one that suggested the initial change. All merit is yours.

Also, I think that, if used, it should be above your Signed-off.

Quoted 63 lines

---
v1 -> v2: remove clk pointer from sprd_mbox_priv

  drivers/mailbox/sprd-mailbox.c | 25 ++++---------------------
  1 file changed, 4 insertions(+), 21 deletions(-)
drivers/mailbox/sprd-mailbox.c +4 -21
index 9ae57de77d4d..ee8539dfcef5 100644
@@ -62,7 +62,6 @@ struct sprd_mbox_priv {
  	void __iomem		*outbox_base;
  	/*  Base register address for supplementary outbox */
  	void __iomem		*supp_base;
-	struct clk		*clk;
  	u32			outbox_fifo_depth;
 
  	struct mutex		lock;
@@ -291,19 +290,13 @@ static const struct mbox_chan_ops sprd_mbox_ops = {
  	.shutdown	= sprd_mbox_shutdown,
  };
 
-static void sprd_mbox_disable(void *data)
-{
-	struct sprd_mbox_priv *priv = data;
-
-	clk_disable_unprepare(priv->clk);
-}
-
  static int sprd_mbox_probe(struct platform_device *pdev)
  {
  	struct device *dev = &pdev->dev;
  	struct sprd_mbox_priv *priv;
  	int ret, inbox_irq, outbox_irq, supp_irq;
  	unsigned long id, supp;
+	struct clk *clk;
 
  	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  	if (!priv)
@@ -331,20 +324,10 @@ static int sprd_mbox_probe(struct platform_device *pdev)
  	if (IS_ERR(priv->outbox_base))
  		return PTR_ERR(priv->outbox_base);
 
-	priv->clk = devm_clk_get(dev, "enable");
-	if (IS_ERR(priv->clk)) {
+	clk = devm_clk_get_enabled(dev, "enable");
+	if (IS_ERR(clk)) {
  		dev_err(dev, "failed to get mailbox clock\n");
-		return PTR_ERR(priv->clk);
-	}
-
-	ret = clk_prepare_enable(priv->clk);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(dev, sprd_mbox_disable, priv);
-	if (ret) {
-		dev_err(dev, "failed to add mailbox disable action\n");
-		return ret;
+		return PTR_ERR(clk);
  	}
 
  	inbox_irq = platform_get_irq_byname(pdev, "inbox");
author
#2 lore raw
Quoted 8 lines · Christophe JAILLET

Le 21/08/2024 à 03:39, Huan Yang a écrit :

Quoted 7 lines

The devm_clk_get_enabled() helpers:
      - call devm_clk_get()
      - call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Quoted 8 lines
Quoted 5 lines

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

Nitpick: no need to add this S-b. I just made a comment when looking at your patch in order to improve it. I'm not the one that suggested the initial change. All merit is yours.

Your suggestion is helpfull, help this patch be better.

Quoted 2 lines

Also, I think that, if used, it should be above your Signed-off.

Hmmm, it's neccessary? If so, I'd like to update it.

Quoted 65 lines
Quoted 60 lines

---
v1 -> v2: remove clk pointer from sprd_mbox_priv

  drivers/mailbox/sprd-mailbox.c | 25 ++++---------------------

  1 file changed, 4 insertions(+), 21 deletions(-)
drivers/mailbox/sprd-mailbox.c +4 -19
index 9ae57de77d4d..ee8539dfcef5 100644
@@ -62,7 +62,6 @@ struct sprd_mbox_priv {
       void __iomem        *outbox_base;
       /*  Base register address for supplementary outbox */
       void __iomem        *supp_base;
-    struct clk        *clk;
       u32            outbox_fifo_depth;
         struct mutex        lock;
@@ -291,19 +290,13 @@ static const struct mbox_chan_ops sprd_mbox_ops 
 = {
       .shutdown    = sprd_mbox_shutdown,
   };
   -static void sprd_mbox_disable(void *data)
-{
-    struct sprd_mbox_priv *priv = data;
-
-    clk_disable_unprepare(priv->clk);
-}
-
   static int sprd_mbox_probe(struct platform_device *pdev)
   {
       struct device *dev = &pdev->dev;
       struct sprd_mbox_priv *priv;
       int ret, inbox_irq, outbox_irq, supp_irq;
       unsigned long id, supp;
+    struct clk *clk;
         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
       if (!priv)
@@ -331,20 +324,10 @@ static int sprd_mbox_probe(struct 
 platform_device *pdev)
       if (IS_ERR(priv->outbox_base))
           return PTR_ERR(priv->outbox_base);
   -    priv->clk = devm_clk_get(dev, "enable");
-    if (IS_ERR(priv->clk)) {
+    clk = devm_clk_get_enabled(dev, "enable");
+    if (IS_ERR(clk)) {
           dev_err(dev, "failed to get mailbox clock\n");
-        return PTR_ERR(priv->clk);
-    }
-
-    ret = clk_prepare_enable(priv->clk);
-    if (ret)
-        return ret;
-
-    ret = devm_add_action_or_reset(dev, sprd_mbox_disable, priv);
-    if (ret) {
-        dev_err(dev, "failed to add mailbox disable action\n");
-        return ret;
+        return PTR_ERR(clk);
       }
         inbox_irq = platform_get_irq_byname(pdev, "inbox");
#3 lore raw

Le 21/08/2024 à 09:08, Huan Yang a écrit :

Quoted 17 lines · Christophe JAILLET
Quoted 15 lines

Le 21/08/2024 à 03:39, Huan Yang a écrit :

Quoted 12 lines

The devm_clk_get_enabled() helpers:
      - call devm_clk_get()
      - call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

Quoted 5 lines
Quoted 1 line

Nitpick: no need to add this S-b. I just made a comment when looking at your patch in order to improve it. I'm not the one that suggested the initial change. All merit is yours.

Your suggestion is helpfull, help this patch be better.

Quoted 2 lines

Also, I think that, if used, it should be above your Signed-off.

Hmmm, it's neccessary? If so, I'd like to update it.

I don't think it is useful and personally I would remove it, but you can keep it if it makes sense to you.

CJ

maintainer
#4 lore raw
Quoted 24 lines · Christophe JAILLET
Quoted 22 lines · Huan Yang
Quoted 20 lines · Christophe JAILLET
Quoted 6 lines · Huan Yang

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in
order to
call clk_disable_unprepare() when needed, as a managed resource.

Quoted 8 lines

This simplifies the code and avoids the calls to
clk_disable_unprepare().

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

Nitpick: no need to add this S-b. I just made a comment when looking at your patch in order to improve it. I'm not the one that suggested the initial change. All merit is yours.

Quoted 8 lines
Quoted 4 lines

Your suggestion is helpfull, help this patch be better.

Quoted 2 lines

Also, I think that, if used, it should be above your Signed-off.

Hmmm, it's neccessary? If so, I'd like to update it.

I don't think it is useful and personally I would remove it, but you can keep it if it makes sense to you.

I think Reviewed-by is appropriate.

cheers!

author
#5 lore raw
Quoted 23 lines · Jassi Brar
Quoted 21 lines · Christophe JAILLET
Quoted 20 lines · Huan Yang
Quoted 19 lines · Christophe JAILLET
Quoted 6 lines · Huan Yang

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in
order to
call clk_disable_unprepare() when needed, as a managed resource.

Quoted 8 lines

This simplifies the code and avoids the calls to
clk_disable_unprepare().

Due to clk only used in probe, not in suspend\resume, this pointer can remove from sprd_mbox_priv to save a little memory.

Nitpick: no need to add this S-b. I just made a comment when looking at your patch in order to improve it. I'm not the one that suggested the initial change. All merit is yours.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Your suggestion is helpfull, help this patch be better.

Quoted 1 line

Also, I think that, if used, it should be above your Signed-off.

Hmmm, it's neccessary? If so, I'd like to update it.

I don't think it is useful and personally I would remove it, but you can keep it if it makes sense to you.

I think Reviewed-by is appropriate.

OK, I'll update it

Quoted 2 lines

cheers!