drivers: spi: rv32m1: lpspi: add pinctrl support

Add pinctrl support to the OpenISA RV32M1 LPSPI SPI driver.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
Henrik Brix Andersen 2022-05-01 22:32:33 +02:00 committed by David Leach
parent 7b33d4af6c
commit c83a0d5d1f
2 changed files with 25 additions and 1 deletions

View file

@ -12,6 +12,9 @@
#include <drivers/spi.h>
#include <drivers/clock_control.h>
#include <fsl_lpspi.h>
#ifdef CONFIG_PINCTRL
#include <drivers/pinctrl.h>
#endif
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
#include <logging/log.h>
@ -29,6 +32,9 @@ struct spi_mcux_config {
clock_ip_name_t clock_ip_name;
uint32_t clock_ip_src;
void (*irq_config_func)(const struct device *dev);
#ifdef CONFIG_PINCTRL
const struct pinctrl_dev_config *pincfg;
#endif
};
struct spi_mcux_data {
@ -274,6 +280,13 @@ static int spi_mcux_init(const struct device *dev)
return err;
}
#ifdef CONFIG_PINCTRL
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
if (err != 0) {
return err;
}
#endif
spi_context_unlock_unconditionally(&data->ctx);
return 0;
@ -287,7 +300,17 @@ static const struct spi_driver_api spi_mcux_driver_api = {
.release = spi_mcux_release,
};
#ifdef CONFIG_PINCTRL
#define PINCTRL_INIT(n) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),
#define PINCTRL_DEFINE(n) PINCTRL_DT_INST_DEFINE(n);
#else
#define PINCTRL_DEFINE(n)
#define PINCTRL_INIT(n)
#endif
#define SPI_RV32M1_INIT(n) \
PINCTRL_DEFINE(n) \
\
static void spi_mcux_config_func_##n(const struct device *dev); \
\
static const struct spi_mcux_config spi_mcux_config_##n = { \
@ -298,6 +321,7 @@ static const struct spi_driver_api spi_mcux_driver_api = {
.irq_config_func = spi_mcux_config_func_##n, \
.clock_ip_name = INST_DT_CLOCK_IP_NAME(n), \
.clock_ip_src = kCLOCK_IpSrcFircAsync, \
PINCTRL_INIT(n) \
}; \
\
static struct spi_mcux_data spi_mcux_data_##n = { \

View file

@ -5,7 +5,7 @@ description: OpenISA LPSPI controller
compatible: "openisa,rv32m1-lpspi"
include: spi-controller.yaml
include: [spi-controller.yaml, pinctrl-device.yaml]
properties:
reg: