diff --git a/drivers/spi/spi_context.h b/drivers/spi/spi_context.h index d899f4f6b70..557e81a1a22 100644 --- a/drivers/spi/spi_context.h +++ b/drivers/spi/spi_context.h @@ -183,29 +183,34 @@ gpio_dt_flags_t spi_context_cs_active_level(struct spi_context *ctx) return GPIO_ACTIVE_LOW; } -static inline void spi_context_cs_configure(struct spi_context *ctx) +static inline int spi_context_cs_configure(struct spi_context *ctx) { - if (ctx->config->cs && ctx->config->cs->gpio_dev) { + int ret; + + if (ctx->config->cs && ctx->config->cs->gpio.port) { /* Validate CS active levels are equivalent */ __ASSERT(spi_context_cs_active_level(ctx) == - (ctx->config->cs->gpio_dt_flags & GPIO_ACTIVE_LOW), + (ctx->config->cs->gpio.dt_flags & GPIO_ACTIVE_LOW), "Devicetree and spi_context CS levels are not equal"); - gpio_pin_configure(ctx->config->cs->gpio_dev, - ctx->config->cs->gpio_pin, - ctx->config->cs->gpio_dt_flags | - GPIO_OUTPUT_INACTIVE); + ret = gpio_pin_configure_dt(&ctx->config->cs->gpio, + GPIO_OUTPUT_INACTIVE); + if (ret < 0) { + LOG_ERR("Failed to configure 'cs' gpio: %d", ret); + return ret; + } } else { LOG_INF("CS control inhibited (no GPIO device)"); } + + return 0; } static inline void _spi_context_cs_control(struct spi_context *ctx, bool on, bool force_off) { - if (ctx->config && ctx->config->cs && ctx->config->cs->gpio_dev) { + if (ctx->config && ctx->config->cs && ctx->config->cs->gpio.port) { if (on) { - gpio_pin_set(ctx->config->cs->gpio_dev, - ctx->config->cs->gpio_pin, 1); + gpio_pin_set_dt(&ctx->config->cs->gpio, 1); k_busy_wait(ctx->config->cs->delay); } else { if (!force_off && @@ -214,8 +219,7 @@ static inline void _spi_context_cs_control(struct spi_context *ctx, } k_busy_wait(ctx->config->cs->delay); - gpio_pin_set(ctx->config->cs->gpio_dev, - ctx->config->cs->gpio_pin, 0); + gpio_pin_set_dt(&ctx->config->cs->gpio, 0); } } } diff --git a/include/drivers/spi.h b/include/drivers/spi.h index 1cc055d4b48..79a5d9d1cd8 100644 --- a/include/drivers/spi.h +++ b/include/drivers/spi.h @@ -193,13 +193,10 @@ struct spi_cs_control { * @param delay_ The @p delay field to set in the @p spi_cs_control * @return a pointer to the @p spi_cs_control structure */ -#define SPI_CS_CONTROL_PTR_DT(node_id, delay_) \ - (&(struct spi_cs_control) { \ - .gpio_dev = DEVICE_DT_GET( \ - DT_SPI_DEV_CS_GPIOS_CTLR(node_id)), \ - .delay = (delay_), \ - .gpio_pin = DT_SPI_DEV_CS_GPIOS_PIN(node_id), \ - .gpio_dt_flags = DT_SPI_DEV_CS_GPIOS_FLAGS(node_id), \ +#define SPI_CS_CONTROL_PTR_DT(node_id, delay_) \ + (&(struct spi_cs_control) { \ + .gpio = DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET(node_id), \ + .delay = (delay_), \ }) /** @@ -439,7 +436,7 @@ static inline bool spi_is_ready(const struct spi_dt_spec *spec) } /* Validate CS gpio port is ready, if it is used */ if (spec->config.cs && - !device_is_ready(spec->config.cs->gpio_dev)) { + !device_is_ready(spec->config.cs->gpio.port)) { return false; } return true;