Commit ef7b8aa8 authored by Quentin Schulz's avatar Quentin Schulz Committed by Marc Kleine-Budde

can: m_can: factorize clock gating and ungating

This creates a function to ungate M_CAN clocks and another to gate the
same clocks, then swaps all gating/ungating code with their respective
function.
Signed-off-by: default avatarQuentin Schulz <quentin.schulz@free-electrons.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 8a3f3f24
...@@ -621,10 +621,8 @@ static int __m_can_get_berr_counter(const struct net_device *dev, ...@@ -621,10 +621,8 @@ static int __m_can_get_berr_counter(const struct net_device *dev,
return 0; return 0;
} }
static int m_can_get_berr_counter(const struct net_device *dev, static int m_can_clk_start(struct m_can_priv *priv)
struct can_berr_counter *bec)
{ {
struct m_can_priv *priv = netdev_priv(dev);
int err; int err;
err = clk_prepare_enable(priv->hclk); err = clk_prepare_enable(priv->hclk);
...@@ -632,15 +630,31 @@ static int m_can_get_berr_counter(const struct net_device *dev, ...@@ -632,15 +630,31 @@ static int m_can_get_berr_counter(const struct net_device *dev,
return err; return err;
err = clk_prepare_enable(priv->cclk); err = clk_prepare_enable(priv->cclk);
if (err) { if (err)
clk_disable_unprepare(priv->hclk); clk_disable_unprepare(priv->hclk);
return err;
}
__m_can_get_berr_counter(dev, bec); return err;
}
static void m_can_clk_stop(struct m_can_priv *priv)
{
clk_disable_unprepare(priv->cclk); clk_disable_unprepare(priv->cclk);
clk_disable_unprepare(priv->hclk); clk_disable_unprepare(priv->hclk);
}
static int m_can_get_berr_counter(const struct net_device *dev,
struct can_berr_counter *bec)
{
struct m_can_priv *priv = netdev_priv(dev);
int err;
err = m_can_clk_start(priv);
if (err)
return err;
__m_can_get_berr_counter(dev, bec);
m_can_clk_stop(priv);
return 0; return 0;
} }
...@@ -1276,19 +1290,15 @@ static int m_can_open(struct net_device *dev) ...@@ -1276,19 +1290,15 @@ static int m_can_open(struct net_device *dev)
struct m_can_priv *priv = netdev_priv(dev); struct m_can_priv *priv = netdev_priv(dev);
int err; int err;
err = clk_prepare_enable(priv->hclk); err = m_can_clk_start(priv);
if (err) if (err)
return err; return err;
err = clk_prepare_enable(priv->cclk);
if (err)
goto exit_disable_hclk;
/* open the can device */ /* open the can device */
err = open_candev(dev); err = open_candev(dev);
if (err) { if (err) {
netdev_err(dev, "failed to open can device\n"); netdev_err(dev, "failed to open can device\n");
goto exit_disable_cclk; goto exit_disable_clks;
} }
/* register interrupt handler */ /* register interrupt handler */
...@@ -1310,10 +1320,8 @@ static int m_can_open(struct net_device *dev) ...@@ -1310,10 +1320,8 @@ static int m_can_open(struct net_device *dev)
exit_irq_fail: exit_irq_fail:
close_candev(dev); close_candev(dev);
exit_disable_cclk: exit_disable_clks:
clk_disable_unprepare(priv->cclk); m_can_clk_stop(priv);
exit_disable_hclk:
clk_disable_unprepare(priv->hclk);
return err; return err;
} }
...@@ -1335,8 +1343,7 @@ static int m_can_close(struct net_device *dev) ...@@ -1335,8 +1343,7 @@ static int m_can_close(struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
napi_disable(&priv->napi); napi_disable(&priv->napi);
m_can_stop(dev); m_can_stop(dev);
clk_disable_unprepare(priv->hclk); m_can_clk_stop(priv);
clk_disable_unprepare(priv->cclk);
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
close_candev(dev); close_candev(dev);
can_led_event(dev, CAN_LED_EVENT_STOP); can_led_event(dev, CAN_LED_EVENT_STOP);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment