Skip to content

Commit f445cb9

Browse files
bbilascfriedt
authored andcommitted
drivers: ieee802154_rf2xx: convert to use spi_dt_spec
Convert ieee802154_rf2xx driver to use `spi_dt_spec` helpers. Signed-off-by: Bartosz Bilas <[email protected]>
1 parent 8979fbc commit f445cb9

File tree

3 files changed

+16
-73
lines changed

3 files changed

+16
-73
lines changed

drivers/ieee802154/ieee802154_rf2xx.c

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -841,44 +841,14 @@ static inline int configure_gpios(const struct device *dev)
841841

842842
static inline int configure_spi(const struct device *dev)
843843
{
844-
struct rf2xx_context *ctx = dev->data;
845844
const struct rf2xx_config *conf = dev->config;
846845

847-
/* Get SPI Driver Instance*/
848-
ctx->spi = device_get_binding(conf->spi.devname);
849-
if (!ctx->spi) {
850-
LOG_ERR("Failed to get instance of %s device",
851-
conf->spi.devname);
852-
846+
if (!spi_is_ready(&conf->spi)) {
847+
LOG_ERR("SPI bus %s is not ready",
848+
conf->spi.bus->name);
853849
return -ENODEV;
854850
}
855851

856-
/* Apply SPI Config: 8-bit, MSB First, MODE-0 */
857-
ctx->spi_cfg.operation = SPI_WORD_SET(8) |
858-
SPI_TRANSFER_MSB;
859-
ctx->spi_cfg.slave = conf->spi.addr;
860-
ctx->spi_cfg.frequency = conf->spi.freq;
861-
ctx->spi_cfg.cs = NULL;
862-
863-
/*
864-
* Get SPI Chip Select Instance
865-
*
866-
* This is an optinal feature configured on DTS. Some SPI controllers
867-
* automatically set CS line by device slave address. Check your SPI
868-
* device driver to understand if you need this option enabled.
869-
*/
870-
ctx->spi_cs.gpio_dev = device_get_binding(conf->spi.cs.devname);
871-
if (ctx->spi_cs.gpio_dev) {
872-
ctx->spi_cs.gpio_pin = conf->spi.cs.pin;
873-
ctx->spi_cs.gpio_dt_flags = conf->spi.cs.flags;
874-
ctx->spi_cs.delay = 0U;
875-
876-
ctx->spi_cfg.cs = &ctx->spi_cs;
877-
878-
LOG_DBG("SPI GPIO CS configured on %s:%u",
879-
conf->spi.cs.devname, conf->spi.cs.pin);
880-
}
881-
882852
return 0;
883853
}
884854

@@ -981,18 +951,6 @@ static struct ieee802154_radio_api rf2xx_radio_api = {
981951
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \
982952
DT_INST_GPIO_FLAGS(n, gpio_pha))
983953

984-
#define DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n) \
985-
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
986-
DT_INST_SPI_DEV_CS_GPIOS_LABEL(n))
987-
988-
#define DRV_INST_SPI_DEV_CS_GPIOS_PIN(n) \
989-
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
990-
DT_INST_SPI_DEV_CS_GPIOS_PIN(n))
991-
992-
#define DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n) \
993-
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
994-
DT_INST_SPI_DEV_CS_GPIOS_FLAGS(n))
995-
996954
#define DRV_INST_LOCAL_MAC_ADDRESS(n) \
997955
UTIL_AND(DT_INST_NODE_HAS_PROP(n, local_mac_address), \
998956
UTIL_AND(DT_INST_PROP_LEN(n, local_mac_address) == 8, \
@@ -1023,12 +981,8 @@ static struct ieee802154_radio_api rf2xx_radio_api = {
1023981
.clkm.pin = DRV_INST_GPIO_PIN(n, clkm_gpios), \
1024982
.clkm.flags = DRV_INST_GPIO_FLAGS(n, clkm_gpios), \
1025983
\
1026-
.spi.devname = DT_INST_BUS_LABEL(n), \
1027-
.spi.addr = DT_INST_REG_ADDR(n), \
1028-
.spi.freq = DT_INST_PROP(n, spi_max_frequency), \
1029-
.spi.cs.devname = DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n), \
1030-
.spi.cs.pin = DRV_INST_SPI_DEV_CS_GPIOS_PIN(n), \
1031-
.spi.cs.flags = DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n), \
984+
.spi = SPI_DT_SPEC_INST_GET(n, SPI_WORD_SET(8) | \
985+
SPI_TRANSFER_MSB, 0), \
1032986
}
1033987

1034988
#define IEEE802154_RF2XX_DEVICE_DATA(n) \

drivers/ieee802154/ieee802154_rf2xx.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,14 @@ struct rf2xx_dt_gpio_t {
8080
uint32_t flags;
8181
};
8282

83-
struct rf2xx_dt_spi_t {
84-
const char *devname;
85-
uint32_t freq;
86-
uint32_t addr;
87-
struct rf2xx_dt_gpio_t cs;
88-
};
89-
9083
struct rf2xx_config {
9184
struct rf2xx_dt_gpio_t irq;
9285
struct rf2xx_dt_gpio_t reset;
9386
struct rf2xx_dt_gpio_t slptr;
9487
struct rf2xx_dt_gpio_t dig2;
9588
struct rf2xx_dt_gpio_t clkm;
9689

97-
struct rf2xx_dt_spi_t spi;
90+
struct spi_dt_spec spi;
9891

9992
uint8_t inst;
10093
uint8_t has_mac;
@@ -111,10 +104,6 @@ struct rf2xx_context {
111104
const struct device *dig2_gpio;
112105
const struct device *clkm_gpio;
113106

114-
const struct device *spi;
115-
struct spi_config spi_cfg;
116-
struct spi_cs_control spi_cs;
117-
118107
struct gpio_callback irq_cb;
119108

120109
struct k_thread trx_thread;

drivers/ieee802154/ieee802154_rf2xx_iface.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void rf2xx_iface_phy_tx_start(const struct device *dev)
5656
uint8_t rf2xx_iface_reg_read(const struct device *dev,
5757
uint8_t addr)
5858
{
59-
const struct rf2xx_context *ctx = dev->data;
59+
const struct rf2xx_config *conf = dev->config;
6060
uint8_t status;
6161
uint8_t regval = 0;
6262

@@ -85,7 +85,7 @@ uint8_t rf2xx_iface_reg_read(const struct device *dev,
8585
.count = 2
8686
};
8787

88-
if (spi_transceive(ctx->spi, &ctx->spi_cfg, &tx, &rx) != 0) {
88+
if (spi_transceive_dt(&conf->spi, &tx, &rx) != 0) {
8989
LOG_ERR("Failed to exec rf2xx_reg_read CMD at address %d",
9090
addr);
9191
}
@@ -100,7 +100,7 @@ void rf2xx_iface_reg_write(const struct device *dev,
100100
uint8_t addr,
101101
uint8_t data)
102102
{
103-
const struct rf2xx_context *ctx = dev->data;
103+
const struct rf2xx_config *conf = dev->config;
104104
uint8_t status;
105105

106106
addr |= RF2XX_RF_CMD_REG_W;
@@ -128,7 +128,7 @@ void rf2xx_iface_reg_write(const struct device *dev,
128128
.count = 1
129129
};
130130

131-
if (spi_transceive(ctx->spi, &ctx->spi_cfg, &tx, &rx) != 0) {
131+
if (spi_transceive_dt(&conf->spi, &tx, &rx) != 0) {
132132
LOG_ERR("Failed to exec rf2xx_reg_write at address %d",
133133
addr);
134134
}
@@ -171,7 +171,7 @@ void rf2xx_iface_frame_read(const struct device *dev,
171171
uint8_t *data,
172172
uint8_t length)
173173
{
174-
const struct rf2xx_context *ctx = dev->data;
174+
const struct rf2xx_config *conf = dev->config;
175175
uint8_t cmd = RF2XX_RF_CMD_FRAME_R;
176176

177177
const struct spi_buf tx_buf = {
@@ -191,7 +191,7 @@ void rf2xx_iface_frame_read(const struct device *dev,
191191
.count = 1
192192
};
193193

194-
if (spi_transceive(ctx->spi, &ctx->spi_cfg, &tx, &rx) != 0) {
194+
if (spi_transceive_dt(&conf->spi, &tx, &rx) != 0) {
195195
LOG_ERR("Failed to exec rf2xx_frame_read PHR");
196196
}
197197

@@ -203,7 +203,7 @@ void rf2xx_iface_frame_write(const struct device *dev,
203203
uint8_t *data,
204204
uint8_t length)
205205
{
206-
const struct rf2xx_context *ctx = dev->data;
206+
const struct rf2xx_config *conf = dev->config;
207207
uint8_t cmd = RF2XX_RF_CMD_FRAME_W;
208208
uint8_t status;
209209
uint8_t phr;
@@ -242,7 +242,7 @@ void rf2xx_iface_frame_write(const struct device *dev,
242242
.count = 1
243243
};
244244

245-
if (spi_transceive(ctx->spi, &ctx->spi_cfg, &tx, &rx) != 0) {
245+
if (spi_transceive_dt(&conf->spi, &tx, &rx) != 0) {
246246
LOG_ERR("Failed to exec rf2xx_frame_write");
247247
}
248248

@@ -255,7 +255,7 @@ void rf2xx_iface_sram_read(const struct device *dev,
255255
uint8_t *data,
256256
uint8_t length)
257257
{
258-
const struct rf2xx_context *ctx = dev->data;
258+
const struct rf2xx_config *conf = dev->config;
259259
uint8_t cmd = RF2XX_RF_CMD_SRAM_R;
260260
uint8_t status[2];
261261

@@ -288,7 +288,7 @@ void rf2xx_iface_sram_read(const struct device *dev,
288288
.count = 2
289289
};
290290

291-
if (spi_transceive(ctx->spi, &ctx->spi_cfg, &tx, &rx) != 0) {
291+
if (spi_transceive_dt(&conf->spi, &tx, &rx) != 0) {
292292
LOG_ERR("Failed to exec rf2xx_sram_read");
293293
}
294294

0 commit comments

Comments
 (0)