[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190128161306.27805-5-ben.whitten@lairdtech.com>
Date: Mon, 28 Jan 2019 16:12:58 +0000
From: Ben Whitten <ben.whitten@...il.com>
To: afaerber@...e.de
Cc: linux-lpwan@...ts.infradead.org,
Ben Whitten <ben.whitten@...il.com>,
"David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH lora-next 04/11] net: lora: sx130x: add helper function for writing to the SX130x MCU
From: Ben Whitten <ben.whitten@...il.com>
The transaction to the internal MCU starts with CMD_WAIT to start a
transaction, written to CHRS followed by writing the value, the status of
the command is read back from AGCSTS.
Signed-off-by: Ben Whitten <ben.whitten@...il.com>
---
drivers/net/lora/sx130x.c | 28 ++++++++++++++++++++++++++++
drivers/net/lora/sx130x.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/drivers/net/lora/sx130x.c b/drivers/net/lora/sx130x.c
index 529ca6622878..818a1c9192b3 100644
--- a/drivers/net/lora/sx130x.c
+++ b/drivers/net/lora/sx130x.c
@@ -337,6 +337,34 @@ static int sx130x_load_firmware(struct sx130x_priv *priv, int mcu, const struct
return 0;
}
+static int sx130x_agc_transaction(struct sx130x_priv *priv, unsigned int val,
+ unsigned int *status)
+{
+ int ret;
+
+ ret = regmap_write(priv->regmap, SX1301_CHRS, SX1301_AGC_CMD_WAIT);
+ if (ret) {
+ dev_err(priv->dev, "AGC transaction start failed\n");
+ return ret;
+ }
+ usleep_range(1000, 2000);
+
+ ret = regmap_write(priv->regmap, SX1301_CHRS, val);
+ if (ret) {
+ dev_err(priv->dev, "AGC transaction value failed\n");
+ return ret;
+ }
+ usleep_range(1000, 2000);
+
+ ret = regmap_read(priv->regmap, SX1301_AGCSTS, status);
+ if (ret) {
+ dev_err(priv->dev, "AGC status read failed\n");
+ return ret;
+ }
+
+ return 0;
+}
+
static int sx130x_agc_calibrate(struct sx130x_priv *priv)
{
const struct firmware *fw;
diff --git a/drivers/net/lora/sx130x.h b/drivers/net/lora/sx130x.h
index 6330777f4eac..69bb9cbd1aba 100644
--- a/drivers/net/lora/sx130x.h
+++ b/drivers/net/lora/sx130x.h
@@ -18,6 +18,8 @@
#define SX1301_MCU_AGC_FW_VERSION 4
#define SX1301_MCU_AGC_CAL_FW_VERSION 2
+#define SX1301_AGC_CMD_WAIT 16
+
#define SX1301_TX_GAIN_LUT_MAX 16
/* Page independent */
--
2.17.1
Powered by blists - more mailing lists