@@ -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;
}
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(-) -- 2.16.4