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.

Signed-off-by: Huan Yang <link@vivo.com>
Reviewed-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
This commit is contained in:
Huan Yang 2024-08-22 09:59:55 +08:00 committed by Jassi Brar
parent e92d87c9c5
commit 0d97651b75

View File

@ -62,7 +62,6 @@ struct sprd_mbox_priv {
void __iomem *outbox_base; void __iomem *outbox_base;
/* Base register address for supplementary outbox */ /* Base register address for supplementary outbox */
void __iomem *supp_base; void __iomem *supp_base;
struct clk *clk;
u32 outbox_fifo_depth; u32 outbox_fifo_depth;
struct mutex lock; struct mutex lock;
@ -291,19 +290,13 @@ static const struct mbox_chan_ops sprd_mbox_ops = {
.shutdown = sprd_mbox_shutdown, .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) static int sprd_mbox_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct sprd_mbox_priv *priv; struct sprd_mbox_priv *priv;
int ret, inbox_irq, outbox_irq, supp_irq; int ret, inbox_irq, outbox_irq, supp_irq;
unsigned long id, supp; unsigned long id, supp;
struct clk *clk;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
@ -331,20 +324,10 @@ static int sprd_mbox_probe(struct platform_device *pdev)
if (IS_ERR(priv->outbox_base)) if (IS_ERR(priv->outbox_base))
return PTR_ERR(priv->outbox_base); return PTR_ERR(priv->outbox_base);
priv->clk = devm_clk_get(dev, "enable"); clk = devm_clk_get_enabled(dev, "enable");
if (IS_ERR(priv->clk)) { if (IS_ERR(clk)) {
dev_err(dev, "failed to get mailbox clock\n"); dev_err(dev, "failed to get mailbox clock\n");
return PTR_ERR(priv->clk); return PTR_ERR(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;
} }
inbox_irq = platform_get_irq_byname(pdev, "inbox"); inbox_irq = platform_get_irq_byname(pdev, "inbox");