From patchwork Sun Dec 30 19:44:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 154621 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp10248496ljp; Sun, 30 Dec 2018 11:44:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN65clMxdwSZgOhF7foW70vtGBgn6gHyi+96Frk3+AIFtNZtWVOOKTzSmNndymLItcbjqbLB X-Received: by 2002:a63:62c4:: with SMTP id w187mr4941795pgb.230.1546199095790; Sun, 30 Dec 2018 11:44:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546199095; cv=none; d=google.com; s=arc-20160816; b=ojZpEjcdSjPbxZWosIYxXvhhVzCfUKz40QYTk2TZaXjOtZk1AfJV7OHzGr/V6DVKFo pNSuf2Cmm8wMOTNJe5h7LqgPYdRu8spSA6KADR7v+N/l5yh6XBOX4aFe1BkjAF7QIDLj pnkRnvNKQ+5dZGlO3J8f2SoZuKD3FQMold8obB70DUm3/QpTIhbFis4TcpdDbbFEW1HD /p8oL5yKY9AiNAB8wMRo6MSGR2CyrNliefC2cHjvPxqxJNNf+xiRdI6bXzUK+gUyl2xo zquyomofb1d9WQRgVxlXXA3axIpCcsSOZ659z1FIr0O5zwwLNYy8ufMP7nzmHxncrwG+ 51KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PmVCL8IyoURhXwSXOJMHV9eDgEiFaq+vwDhdEcwxZvY=; b=DpAw3PWGniUBEQtPA4cI2tOAnhfLjhEioWERGg6GVqRgVgEMm7Jt1roAa8aFLQ9ISD KgJ5yyYmiJPsPt2Vf4qGpTcxccTEyW8nUX76535kOghGwdAWMxkP/+9gTVrIT6ig4FrR js2js0mxgqMcxFCKMGskU2+f6MmgecDztbilCAzanoPzpzBfm3b4SSwiG5ZRMUMZ0P8k uEaWqjFnNU3/zicXUIjmh2nuroYZyRlAM4I3LdDPERNBCC9eg07eLCmXzDbXT58X1dnb YQHluArWKb/EYi02PZBlrL35VSCCTiBpw0fisfoT5KzXHfCukAJFRR0Ug8Axa9QxrRik j+Hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12si8036323pgb.563.2018.12.30.11.44.55; Sun, 30 Dec 2018 11:44:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbeL3Tox (ORCPT + 31 others); Sun, 30 Dec 2018 14:44:53 -0500 Received: from mx2.suse.de ([195.135.220.15]:39338 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726432AbeL3Tox (ORCPT ); Sun, 30 Dec 2018 14:44:53 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BDA13AE1D; Sun, 30 Dec 2018 19:44:51 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: linux-lpwan@lists.infradead.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Whitten , Ben Whitten , =?utf-8?q?Andreas_F=C3=A4rber?= Subject: [PATCH lora-next] net: lora: sx1301: Fix clk32m handling Date: Sun, 30 Dec 2018 20:44:44 +0100 Message-Id: <20181230194444.11970-1-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <491d1a46-c112-1106-9f25-14149f0dcbd0@suse.de> References: <491d1a46-c112-1106-9f25-14149f0dcbd0@suse.de> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/lora/sx1301.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) -- 2.16.4 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; }