lkml.org 
[lkml]   [2018]   [Dec]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH lora-next] net: lora: sx1301: Fix clk32m handling
Date
We can't get the clk32m during probe because the radio is not yet probed then.
When doing it during netdev open we also need to undo that during netdev stop.
Revamp the error handling for open and tidy our debug output while at it.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
drivers/net/lora/sx1301.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c
index 23cbddc364e5..533fd37c350d 100644
--- a/drivers/net/lora/sx1301.c
+++ b/drivers/net/lora/sx1301.c
@@ -379,58 +379,73 @@ static int sx130x_loradev_open(struct net_device *netdev)
return -ENXIO;
}

- priv->clk32m = devm_clk_get(priv->dev, "clk32m");
+ priv->clk32m = clk_get(priv->dev, "clk32m");
if (IS_ERR(priv->clk32m)) {
- dev_err(priv->dev, "failed to get clk32m\n");
+ dev_err(priv->dev, "failed to get clk32m (%ld)\n", PTR_ERR(priv->clk32m));
return PTR_ERR(priv->clk32m);
}

ret = clk_prepare_enable(priv->clk32m);
if (ret) {
- dev_err(priv->dev, "failed to enable clk32m: %d\n", ret);
- return ret;
+ dev_err(priv->dev, "failed to enable clk32m (%d)\n", ret);
+ goto err_clk_enable;
}

ret = sx1301_field_write(priv, F_GLOBAL_EN, 1);
if (ret) {
- dev_err(priv->dev, "enable global clocks failed\n");
- return ret;
+ dev_err(priv->dev, "enable global clocks failed (%d)\n", ret);
+ goto err_reg;
}

ret = sx1301_field_write(priv, F_CLK32M_EN, 1);
if (ret) {
- dev_err(priv->dev, "enable 32M clock failed\n");
- return ret;
+ dev_err(priv->dev, "enable 32M clock failed (%d)\n", ret);
+ goto err_reg;
}

/* calibration */

ret = sx1301_agc_calibrate(priv);
if (ret)
- return ret;
+ goto err_calibrate;

/* TODO */

ret = sx1301_load_all_firmware(priv);
if (ret)
- return ret;
+ goto err_firmware;

ret = open_loradev(netdev);
if (ret)
- return ret;
+ goto err_open;

netif_start_queue(netdev);

return 0;
+
+err_open:
+err_firmware:
+err_calibrate:
+err_reg:
+ clk_disable_unprepare(priv->clk32m);
+err_clk_enable:
+ clk_put(priv->clk32m);
+ return ret;
}

static int sx130x_loradev_stop(struct net_device *netdev)
{
+ struct sx1301_priv *priv = netdev_priv(netdev);
+
netdev_dbg(netdev, "%s", __func__);

netif_stop_queue(netdev);
close_loradev(netdev);

+ clk_disable_unprepare(priv->clk32m);
+ clk_put(priv->clk32m);
+ priv->clk32m = NULL;
+
return 0;
}

--
2.16.4
\
 
 \ /
  Last update: 2018-12-30 20:45    [W:0.084 / U:2.612 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site