[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1533818018-29005-8-git-send-email-ben.whitten@lairdtech.com>
Date: Thu, 9 Aug 2018 13:33:38 +0100
From: Ben Whitten <ben.whitten@...il.com>
To: afaerber@...e.de
Cc: starnight@...cu.edu.tw, hasnain.virk@....com,
netdev@...r.kernel.org, liuxuenetmail@...il.com, shess@...sware.de,
Ben Whitten <ben.whitten@...rdtech.com>
Subject: [PATCH lora-next v2 8/8] net: lora: sx1301: convert driver over to regmap reads and writes
The reads and writes are replaced with regmap versions and unneeded
functions, variable, and defines removed.
Signed-off-by: Ben Whitten <ben.whitten@...rdtech.com>
---
drivers/net/lora/sx1301.c | 204 +++++++++++++++-------------------------------
drivers/net/lora/sx1301.h | 30 +++++++
2 files changed, 95 insertions(+), 139 deletions(-)
diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c
index 766df06..4db5a43 100644
--- a/drivers/net/lora/sx1301.c
+++ b/drivers/net/lora/sx1301.c
@@ -24,29 +24,6 @@
#include "sx1301.h"
-#define REG_PAGE_RESET 0
-#define REG_MCU_PROM_ADDR 9
-#define REG_MCU_PROM_DATA 10
-#define REG_GPIO_SELECT_INPUT 27
-#define REG_GPIO_SELECT_OUTPUT 28
-#define REG_GPIO_MODE 29
-#define REG_MCU_AGC_STATUS 32
-#define REG_0_RADIO_SELECT 35
-#define REG_0_MCU 106
-#define REG_2_SPI_RADIO_A_DATA 33
-#define REG_2_SPI_RADIO_A_DATA_READBACK 34
-#define REG_2_SPI_RADIO_A_ADDR 35
-#define REG_2_SPI_RADIO_A_CS 37
-#define REG_2_SPI_RADIO_B_DATA 38
-#define REG_2_SPI_RADIO_B_DATA_READBACK 39
-#define REG_2_SPI_RADIO_B_ADDR 40
-#define REG_2_SPI_RADIO_B_CS 42
-#define REG_2_DBG_ARB_MCU_RAM_DATA 64
-#define REG_2_DBG_AGC_MCU_RAM_DATA 65
-#define REG_2_DBG_ARB_MCU_RAM_ADDR 80
-#define REG_2_DBG_AGC_MCU_RAM_ADDR 81
-#define REG_EMERGENCY_FORCE 127
-
#define REG_PAGE_RESET_SOFT_RESET BIT(7)
#define REG_16_GLOBAL_EN BIT(3)
@@ -99,8 +76,7 @@ static struct regmap_config sx1301_regmap_config = {
struct spi_sx1301 {
struct spi_device *parent;
- u8 page;
- u8 regs;
+ unsigned int regs;
};
struct sx1301_priv {
@@ -108,7 +84,6 @@ struct sx1301_priv {
struct spi_device *spi;
struct lora_priv lora;
struct gpio_desc *rst_gpio;
- u8 cur_page;
struct spi_controller *radio_a_ctrl, *radio_b_ctrl;
struct regmap *regmap;
};
@@ -140,50 +115,9 @@ static int sx1301_write(struct sx1301_priv *priv, u8 reg, u8 val)
return sx1301_write_burst(priv, reg, &val, 1);
}
-static int sx1301_page_switch(struct sx1301_priv *priv, u8 page)
-{
- int ret;
-
- if (priv->cur_page == page)
- return 0;
-
- dev_dbg(priv->dev, "switching to page %u\n", (unsigned)page);
- ret = sx1301_write(priv, REG_PAGE_RESET, page & 0x3);
- if (ret) {
- dev_err(priv->dev, "switching to page %u failed\n", (unsigned)page);
- return ret;
- }
-
- priv->cur_page = page;
-
- return 0;
-}
-
-static int sx1301_page_read(struct sx1301_priv *priv, u8 page, u8 reg, u8 *val)
-{
- int ret;
-
- ret = sx1301_page_switch(priv, page);
- if (ret)
- return ret;
-
- return sx1301_read(priv, reg, val);
-}
-
-static int sx1301_page_write(struct sx1301_priv *priv, u8 page, u8 reg, u8 val)
-{
- int ret;
-
- ret = sx1301_page_switch(priv, page);
- if (ret)
- return ret;
-
- return sx1301_write(priv, reg, val);
-}
-
static int sx1301_soft_reset(struct sx1301_priv *priv)
{
- return sx1301_write(priv, REG_PAGE_RESET, REG_PAGE_RESET_SOFT_RESET);
+ return regmap_write(priv->regmap, SX1301_PAGE, REG_PAGE_RESET_SOFT_RESET);
}
#define REG_RADIO_X_DATA 0
@@ -195,12 +129,12 @@ static int sx1301_radio_set_cs(struct spi_controller *ctrl, bool enable)
{
struct spi_sx1301 *ssx = spi_controller_get_devdata(ctrl);
struct sx1301_priv *priv = spi_get_drvdata(ssx->parent);
- u8 cs;
+ unsigned int cs;
int ret;
dev_dbg(&ctrl->dev, "setting CS to %s\n", enable ? "1" : "0");
- ret = sx1301_page_read(priv, ssx->page, ssx->regs + REG_RADIO_X_CS, &cs);
+ ret = regmap_read(priv->regmap, ssx->regs + REG_RADIO_X_CS, &cs);
if (ret) {
dev_warn(&ctrl->dev, "failed to read CS (%d)\n", ret);
cs = 0;
@@ -211,7 +145,7 @@ static int sx1301_radio_set_cs(struct spi_controller *ctrl, bool enable)
else
cs &= ~BIT(0);
- ret = sx1301_page_write(priv, ssx->page, ssx->regs + REG_RADIO_X_CS, cs);
+ ret = regmap_write(priv->regmap, ssx->regs + REG_RADIO_X_CS, cs);
if (ret) {
dev_err(&ctrl->dev, "failed to write CS (%d)\n", ret);
return ret;
@@ -235,8 +169,8 @@ static int sx1301_radio_spi_transfer_one(struct spi_controller *ctrl,
{
struct spi_sx1301 *ssx = spi_controller_get_devdata(ctrl);
struct sx1301_priv *priv = spi_get_drvdata(ssx->parent);
- const u8 *tx_buf = xfr->tx_buf;
- u8 *rx_buf = xfr->rx_buf;
+ const unsigned int *tx_buf = xfr->tx_buf;
+ unsigned int *rx_buf = xfr->rx_buf;
int ret;
if (xfr->len == 0 || xfr->len > 3)
@@ -245,13 +179,13 @@ static int sx1301_radio_spi_transfer_one(struct spi_controller *ctrl,
dev_dbg(&spi->dev, "transferring one (%u)\n", xfr->len);
if (tx_buf) {
- ret = sx1301_page_write(priv, ssx->page, ssx->regs + REG_RADIO_X_ADDR, tx_buf ? tx_buf[0] : 0);
+ ret = regmap_write(priv->regmap, ssx->regs + REG_RADIO_X_ADDR, tx_buf ? tx_buf[0] : 0);
if (ret) {
dev_err(&spi->dev, "SPI radio address write failed\n");
return ret;
}
- ret = sx1301_page_write(priv, ssx->page, ssx->regs + REG_RADIO_X_DATA, (tx_buf && xfr->len >= 2) ? tx_buf[1] : 0);
+ ret = regmap_write(priv->regmap, ssx->regs + REG_RADIO_X_DATA, (tx_buf && xfr->len >= 2) ? tx_buf[1] : 0);
if (ret) {
dev_err(&spi->dev, "SPI radio data write failed\n");
return ret;
@@ -271,7 +205,7 @@ static int sx1301_radio_spi_transfer_one(struct spi_controller *ctrl,
}
if (rx_buf) {
- ret = sx1301_page_read(priv, ssx->page, ssx->regs + REG_RADIO_X_DATA_READBACK, &rx_buf[xfr->len - 1]);
+ ret = regmap_read(priv->regmap, ssx->regs + REG_RADIO_X_DATA_READBACK, &rx_buf[xfr->len - 1]);
if (ret) {
dev_err(&spi->dev, "SPI radio data read failed\n");
return ret;
@@ -281,17 +215,17 @@ static int sx1301_radio_spi_transfer_one(struct spi_controller *ctrl,
return 0;
}
-static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, u8 *val)
+static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int *val)
{
int ret;
- ret = sx1301_page_write(priv, 2, REG_2_DBG_AGC_MCU_RAM_ADDR, addr);
+ ret = regmap_write(priv->regmap, SX1301_DBG_AGC_MCU_RAM_ADDR, addr);
if (ret) {
dev_err(priv->dev, "AGC RAM addr write failed\n");
return ret;
}
- ret = sx1301_page_read(priv, 2, REG_2_DBG_AGC_MCU_RAM_DATA, val);
+ ret = regmap_read(priv->regmap, SX1301_DBG_AGC_MCU_RAM_DATA, val);
if (ret) {
dev_err(priv->dev, "AGC RAM data read failed\n");
return ret;
@@ -300,17 +234,17 @@ static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, u8 *val)
return 0;
}
-static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, u8 *val)
+static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int *val)
{
int ret;
- ret = sx1301_page_write(priv, 2, REG_2_DBG_ARB_MCU_RAM_ADDR, addr);
+ ret = regmap_write(priv->regmap, SX1301_DBG_ARB_MCU_RAM_ADDR, addr);
if (ret) {
dev_err(priv->dev, "ARB RAM addr write failed\n");
return ret;
}
- ret = sx1301_page_read(priv, 2, REG_2_DBG_ARB_MCU_RAM_DATA, val);
+ ret = regmap_read(priv->regmap, SX1301_DBG_ARB_MCU_RAM_DATA, val);
if (ret) {
dev_err(priv->dev, "ARB RAM data read failed\n");
return ret;
@@ -322,7 +256,8 @@ static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, u8 *val)
static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct firmware *fw)
{
u8 *buf;
- u8 val, rst, select_mux;
+ u8 rst, select_mux;
+ unsigned int val;
int ret;
if (fw->size != SX1301_MCU_FW_BYTE) {
@@ -343,7 +278,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
return -EINVAL;
}
- ret = sx1301_page_read(priv, 0, REG_0_MCU, &val);
+ ret = regmap_read(priv->regmap, SX1301_MCU_CTRL, &val);
if (ret) {
dev_err(priv->dev, "MCU read failed\n");
return ret;
@@ -352,25 +287,25 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
val |= rst;
val &= ~select_mux;
- ret = sx1301_page_write(priv, 0, REG_0_MCU, val);
+ ret = regmap_write(priv->regmap, SX1301_MCU_CTRL, val);
if (ret) {
dev_err(priv->dev, "MCU reset / select mux write failed\n");
return ret;
}
- ret = sx1301_write(priv, REG_MCU_PROM_ADDR, 0);
+ ret = regmap_write(priv->regmap, SX1301_MPA, 0);
if (ret) {
dev_err(priv->dev, "MCU prom addr write failed\n");
return ret;
}
- ret = sx1301_write_burst(priv, REG_MCU_PROM_DATA, fw->data, fw->size);
+ ret = sx1301_write_burst(priv, SX1301_MPD, fw->data, fw->size);
if (ret) {
dev_err(priv->dev, "MCU prom data write failed\n");
return ret;
}
- ret = sx1301_read(priv, REG_MCU_PROM_DATA, &val);
+ ret = regmap_read(priv->regmap, SX1301_MPD, &val);
if (ret) {
dev_err(priv->dev, "MCU prom data dummy read failed\n");
return ret;
@@ -380,7 +315,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
if (!buf)
return -ENOMEM;
- ret = sx1301_read_burst(priv, REG_MCU_PROM_DATA, buf, fw->size);
+ ret = sx1301_read_burst(priv, SX1301_MPD, buf, fw->size);
if (ret) {
dev_err(priv->dev, "MCU prom data read failed\n");
kfree(buf);
@@ -395,7 +330,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
kfree(buf);
- ret = sx1301_page_read(priv, 0, REG_0_MCU, &val);
+ ret = regmap_read(priv->regmap, SX1301_MCU_CTRL, &val);
if (ret) {
dev_err(priv->dev, "MCU read (1) failed\n");
return ret;
@@ -403,7 +338,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
val |= select_mux;
- ret = sx1301_page_write(priv, 0, REG_0_MCU, val);
+ ret = regmap_write(priv->regmap, SX1301_MCU_CTRL, val);
if (ret) {
dev_err(priv->dev, "MCU reset / select mux write (1) failed\n");
return ret;
@@ -415,7 +350,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
static int sx1301_agc_calibrate(struct sx1301_priv *priv)
{
const struct firmware *fw;
- u8 val;
+ unsigned int val;
int ret;
ret = request_firmware(&fw, "sx1301_agc_calibration.bin", priv->dev);
@@ -431,7 +366,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
return ret;
}
- ret = sx1301_page_read(priv, 0, 105, &val);
+ ret = regmap_read(priv->regmap, SX1301_FORCE_CTRL, &val);
if (ret) {
dev_err(priv->dev, "0|105 read failed\n");
return ret;
@@ -439,7 +374,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
val &= ~REG_0_105_FORCE_HOST_RADIO_CTRL;
- ret = sx1301_page_write(priv, 0, 105, val);
+ ret = regmap_write(priv->regmap, SX1301_FORCE_CTRL, val);
if (ret) {
dev_err(priv->dev, "0|105 write failed\n");
return ret;
@@ -449,13 +384,13 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
if (false)
val |= BIT(5); /* SX1255 */
- ret = sx1301_page_write(priv, 0, REG_0_RADIO_SELECT, val);
+ ret = regmap_write(priv->regmap, SX1301_CHRS, val);
if (ret) {
dev_err(priv->dev, "radio select write failed\n");
return ret;
}
- ret = sx1301_page_read(priv, 0, REG_0_MCU, &val);
+ ret = regmap_read(priv->regmap, SX1301_MCU_CTRL, &val);
if (ret) {
dev_err(priv->dev, "MCU read (0) failed\n");
return ret;
@@ -463,7 +398,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
val &= ~REG_0_MCU_RST_1;
- ret = sx1301_page_write(priv, 0, REG_0_MCU, val);
+ ret = regmap_write(priv->regmap, SX1301_MCU_CTRL, val);
if (ret) {
dev_err(priv->dev, "MCU write (0) failed\n");
return ret;
@@ -483,13 +418,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
return -ENXIO;
}
- ret = sx1301_page_switch(priv, 3);
- if (ret) {
- dev_err(priv->dev, "page switch 3 failed\n");
- return ret;
- }
-
- ret = sx1301_read(priv, REG_EMERGENCY_FORCE, &val);
+ ret = regmap_read(priv->regmap, SX1301_EMERGENCY_FORCE_HOST_CTRL, &val);
if (ret) {
dev_err(priv->dev, "emergency force read failed\n");
return ret;
@@ -497,7 +426,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
val &= ~REG_EMERGENCY_FORCE_HOST_CTRL;
- ret = sx1301_write(priv, REG_EMERGENCY_FORCE, val);
+ ret = regmap_write(priv->regmap, SX1301_EMERGENCY_FORCE_HOST_CTRL, val);
if (ret) {
dev_err(priv->dev, "emergency force write failed\n");
return ret;
@@ -506,7 +435,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
dev_err(priv->dev, "starting calibration...\n");
msleep(2300);
- ret = sx1301_read(priv, REG_EMERGENCY_FORCE, &val);
+ ret = regmap_read(priv->regmap, SX1301_EMERGENCY_FORCE_HOST_CTRL, &val);
if (ret) {
dev_err(priv->dev, "emergency force read (1) failed\n");
return ret;
@@ -514,13 +443,13 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
val |= REG_EMERGENCY_FORCE_HOST_CTRL;
- ret = sx1301_write(priv, REG_EMERGENCY_FORCE, val);
+ ret = regmap_write(priv->regmap, SX1301_EMERGENCY_FORCE_HOST_CTRL, val);
if (ret) {
dev_err(priv->dev, "emergency force write (1) failed\n");
return ret;
}
- ret = sx1301_read(priv, REG_MCU_AGC_STATUS, &val);
+ ret = regmap_read(priv->regmap, SX1301_AGCSTS, &val);
if (ret) {
dev_err(priv->dev, "AGC status read failed\n");
return ret;
@@ -538,7 +467,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv)
static int sx1301_load_all_firmware(struct sx1301_priv *priv)
{
const struct firmware *fw;
- u8 val;
+ unsigned int val;
int ret;
ret = request_firmware(&fw, "sx1301_arb.bin", priv->dev);
@@ -563,7 +492,7 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv)
if (ret)
return ret;
- ret = sx1301_page_read(priv, 0, 105, &val);
+ ret = regmap_read(priv->regmap, SX1301_FORCE_CTRL, &val);
if (ret) {
dev_err(priv->dev, "0|105 read failed\n");
return ret;
@@ -571,19 +500,19 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv)
val &= ~(REG_0_105_FORCE_HOST_RADIO_CTRL | REG_0_105_FORCE_HOST_FE_CTRL | REG_0_105_FORCE_DEC_FILTER_GAIN);
- ret = sx1301_page_write(priv, 0, 105, val);
+ ret = regmap_write(priv->regmap, SX1301_FORCE_CTRL, val);
if (ret) {
dev_err(priv->dev, "0|105 write failed\n");
return ret;
}
- ret = sx1301_page_write(priv, 0, REG_0_RADIO_SELECT, 0);
+ ret = regmap_write(priv->regmap, SX1301_CHRS, 0);
if (ret) {
dev_err(priv->dev, "radio select write failed\n");
return ret;
}
- ret = sx1301_page_read(priv, 0, REG_0_MCU, &val);
+ ret = regmap_read(priv->regmap, SX1301_MCU_CTRL, &val);
if (ret) {
dev_err(priv->dev, "MCU read (0) failed\n");
return ret;
@@ -591,7 +520,7 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv)
val &= ~(REG_0_MCU_RST_1 | REG_0_MCU_RST_0);
- ret = sx1301_page_write(priv, 0, REG_0_MCU, val);
+ ret = regmap_write(priv->regmap, SX1301_MCU_CTRL, val);
if (ret) {
dev_err(priv->dev, "MCU write (0) failed\n");
return ret;
@@ -645,7 +574,7 @@ static int sx1301_probe(struct spi_device *spi)
struct gpio_desc *rst;
int ret;
unsigned int ver;
- u8 val;
+ unsigned int val;
rst = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(rst))
@@ -665,7 +594,6 @@ static int sx1301_probe(struct spi_device *spi)
priv = netdev_priv(netdev);
priv->rst_gpio = rst;
- priv->cur_page = 0xff;
spi_set_drvdata(spi, priv);
priv->dev = &spi->dev;
@@ -690,7 +618,7 @@ static int sx1301_probe(struct spi_device *spi)
return -ENXIO;
}
- ret = sx1301_write(priv, REG_PAGE_RESET, 0);
+ ret = regmap_write(priv->regmap, SX1301_PAGE, 0);
if (ret) {
dev_err(&spi->dev, "page/reset write failed\n");
return ret;
@@ -702,7 +630,7 @@ static int sx1301_probe(struct spi_device *spi)
return ret;
}
- ret = sx1301_read(priv, 16, &val);
+ ret = regmap_read(priv->regmap, SX1301_GEN, &val);
if (ret) {
dev_err(&spi->dev, "16 read failed\n");
return ret;
@@ -710,13 +638,13 @@ static int sx1301_probe(struct spi_device *spi)
val &= ~REG_16_GLOBAL_EN;
- ret = sx1301_write(priv, 16, val);
+ ret = regmap_write(priv->regmap, SX1301_GEN, val);
if (ret) {
dev_err(&spi->dev, "16 write failed\n");
return ret;
}
- ret = sx1301_read(priv, 17, &val);
+ ret = regmap_read(priv->regmap, SX1301_CKEN, &val);
if (ret) {
dev_err(&spi->dev, "17 read failed\n");
return ret;
@@ -724,13 +652,13 @@ static int sx1301_probe(struct spi_device *spi)
val &= ~REG_17_CLK32M_EN;
- ret = sx1301_write(priv, 17, val);
+ ret = regmap_write(priv->regmap, SX1301_CKEN, val);
if (ret) {
dev_err(&spi->dev, "17 write failed\n");
return ret;
}
- ret = sx1301_page_read(priv, 2, 43, &val);
+ ret = regmap_read(priv->regmap, SX1301_RADIO_CFG, &val);
if (ret) {
dev_err(&spi->dev, "2|43 read failed\n");
return ret;
@@ -738,7 +666,7 @@ static int sx1301_probe(struct spi_device *spi)
val |= REG_2_43_RADIO_B_EN | REG_2_43_RADIO_A_EN;
- ret = sx1301_page_write(priv, 2, 43, val);
+ ret = regmap_write(priv->regmap, SX1301_RADIO_CFG, val);
if (ret) {
dev_err(&spi->dev, "2|43 write failed\n");
return ret;
@@ -746,7 +674,7 @@ static int sx1301_probe(struct spi_device *spi)
msleep(500);
- ret = sx1301_page_read(priv, 2, 43, &val);
+ ret = regmap_read(priv->regmap, SX1301_RADIO_CFG, &val);
if (ret) {
dev_err(&spi->dev, "2|43 read failed\n");
return ret;
@@ -754,7 +682,7 @@ static int sx1301_probe(struct spi_device *spi)
val |= REG_2_43_RADIO_RST;
- ret = sx1301_page_write(priv, 2, 43, val);
+ ret = regmap_write(priv->regmap, SX1301_RADIO_CFG, val);
if (ret) {
dev_err(&spi->dev, "2|43 write failed\n");
return ret;
@@ -762,7 +690,7 @@ static int sx1301_probe(struct spi_device *spi)
msleep(5);
- ret = sx1301_page_read(priv, 2, 43, &val);
+ ret = regmap_read(priv->regmap, SX1301_RADIO_CFG, &val);
if (ret) {
dev_err(&spi->dev, "2|43 read failed\n");
return ret;
@@ -770,7 +698,7 @@ static int sx1301_probe(struct spi_device *spi)
val &= ~REG_2_43_RADIO_RST;
- ret = sx1301_page_write(priv, 2, 43, val);
+ ret = regmap_write(priv->regmap, SX1301_RADIO_CFG, val);
if (ret) {
dev_err(&spi->dev, "2|43 write failed\n");
return ret;
@@ -787,8 +715,7 @@ static int sx1301_probe(struct spi_device *spi)
priv->radio_a_ctrl->dev.of_node = of_get_child_by_name(spi->dev.of_node, "radio-a");
radio = spi_controller_get_devdata(priv->radio_a_ctrl);
- radio->page = 2;
- radio->regs = REG_2_SPI_RADIO_A_DATA;
+ radio->regs = SX1301_RADIO_A_SPI_DATA;
radio->parent = spi;
ret = devm_spi_register_controller(&spi->dev, priv->radio_a_ctrl);
@@ -809,8 +736,7 @@ static int sx1301_probe(struct spi_device *spi)
priv->radio_b_ctrl->dev.of_node = of_get_child_by_name(spi->dev.of_node, "radio-b");
radio = spi_controller_get_devdata(priv->radio_b_ctrl);
- radio->page = 2;
- radio->regs = REG_2_SPI_RADIO_B_DATA;
+ radio->regs = SX1301_RADIO_B_SPI_DATA;
radio->parent = spi;
ret = devm_spi_register_controller(&spi->dev, priv->radio_b_ctrl);
@@ -822,7 +748,7 @@ static int sx1301_probe(struct spi_device *spi)
/* GPIO */
- ret = sx1301_read(priv, REG_GPIO_MODE, &val);
+ ret = regmap_read(priv->regmap, SX1301_GPMODE, &val);
if (ret) {
dev_err(&spi->dev, "GPIO mode read failed\n");
return ret;
@@ -830,13 +756,13 @@ static int sx1301_probe(struct spi_device *spi)
val |= GENMASK(4, 0);
- ret = sx1301_write(priv, REG_GPIO_MODE, val);
+ ret = regmap_write(priv->regmap, SX1301_GPMODE, val);
if (ret) {
dev_err(&spi->dev, "GPIO mode write failed\n");
return ret;
}
- ret = sx1301_read(priv, REG_GPIO_SELECT_OUTPUT, &val);
+ ret = regmap_read(priv->regmap, SX1301_GPSO, &val);
if (ret) {
dev_err(&spi->dev, "GPIO select output read failed\n");
return ret;
@@ -845,7 +771,7 @@ static int sx1301_probe(struct spi_device *spi)
val &= ~GENMASK(3, 0);
val |= 2;
- ret = sx1301_write(priv, REG_GPIO_SELECT_OUTPUT, val);
+ ret = regmap_write(priv->regmap, SX1301_GPSO, val);
if (ret) {
dev_err(&spi->dev, "GPIO select output write failed\n");
return ret;
@@ -853,7 +779,7 @@ static int sx1301_probe(struct spi_device *spi)
/* TODO LBT */
- ret = sx1301_read(priv, 16, &val);
+ ret = regmap_read(priv->regmap, SX1301_GEN, &val);
if (ret) {
dev_err(&spi->dev, "16 read (1) failed\n");
return ret;
@@ -861,13 +787,13 @@ static int sx1301_probe(struct spi_device *spi)
val |= REG_16_GLOBAL_EN;
- ret = sx1301_write(priv, 16, val);
+ ret = regmap_write(priv->regmap, SX1301_GEN, val);
if (ret) {
dev_err(&spi->dev, "16 write (1) failed\n");
return ret;
}
- ret = sx1301_read(priv, 17, &val);
+ ret = regmap_read(priv->regmap, SX1301_CKEN, &val);
if (ret) {
dev_err(&spi->dev, "17 read (1) failed\n");
return ret;
@@ -875,7 +801,7 @@ static int sx1301_probe(struct spi_device *spi)
val |= REG_17_CLK32M_EN;
- ret = sx1301_write(priv, 17, val);
+ ret = regmap_write(priv->regmap, SX1301_CKEN, val);
if (ret) {
dev_err(&spi->dev, "17 write (1) failed\n");
return ret;
diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h
index 2fc283f..b21e5c6 100644
--- a/drivers/net/lora/sx1301.h
+++ b/drivers/net/lora/sx1301.h
@@ -18,11 +18,41 @@
/* Page independent */
#define SX1301_PAGE 0x00
#define SX1301_VER 0x01
+#define SX1301_MPA 0x09
+#define SX1301_MPD 0x0A
+#define SX1301_GEN 0x10
+#define SX1301_CKEN 0x11
+#define SX1301_GPSO 0x1C
+#define SX1301_GPMODE 0x1D
+#define SX1301_AGCSTS 0x20
#define SX1301_VIRT_BASE 0x100
#define SX1301_PAGE_LEN 0x80
#define SX1301_PAGE_BASE(n) (SX1301_VIRT_BASE + (SX1301_PAGE_LEN * n))
+/* Page 0 */
+#define SX1301_CHRS (SX1301_PAGE_BASE(0) + 0x23)
+#define SX1301_FORCE_CTRL (SX1301_PAGE_BASE(0) + 0x69)
+#define SX1301_MCU_CTRL (SX1301_PAGE_BASE(0) + 0x6A)
+
+/* Page 2 */
+#define SX1301_RADIO_A_SPI_DATA (SX1301_PAGE_BASE(2) + 0x21)
+#define SX1301_RADIO_A_SPI_DATA_RB (SX1301_PAGE_BASE(2) + 0x22)
+#define SX1301_RADIO_A_SPI_ADDR (SX1301_PAGE_BASE(2) + 0x23)
+#define SX1301_RADIO_A_SPI_CS (SX1301_PAGE_BASE(2) + 0x25)
+#define SX1301_RADIO_B_SPI_DATA (SX1301_PAGE_BASE(2) + 0x26)
+#define SX1301_RADIO_B_SPI_DATA_RB (SX1301_PAGE_BASE(2) + 0x27)
+#define SX1301_RADIO_B_SPI_ADDR (SX1301_PAGE_BASE(2) + 0x28)
+#define SX1301_RADIO_B_SPI_CS (SX1301_PAGE_BASE(2) + 0x2A)
+#define SX1301_RADIO_CFG (SX1301_PAGE_BASE(2) + 0x2B)
+#define SX1301_DBG_ARB_MCU_RAM_DATA (SX1301_PAGE_BASE(2) + 0x40)
+#define SX1301_DBG_AGC_MCU_RAM_DATA (SX1301_PAGE_BASE(2) + 0x41)
+#define SX1301_DBG_ARB_MCU_RAM_ADDR (SX1301_PAGE_BASE(2) + 0x50)
+#define SX1301_DBG_AGC_MCU_RAM_ADDR (SX1301_PAGE_BASE(2) + 0x51)
+
+/* Page 3 */
+#define SX1301_EMERGENCY_FORCE_HOST_CTRL (SX1301_PAGE_BASE(3) + 0x7F)
+
#define SX1301_MAX_REGISTER (SX1301_PAGE_BASE(3) + 0x7F)
#endif
--
2.7.4
Powered by blists - more mailing lists