drivers: spi: telink_b91: replace Pinmux by Pinctrl
Updated driver to use new Pinctrl driver. Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
This commit is contained in:
parent
b7f1b58810
commit
f47d8568f2
1 changed files with 32 additions and 41 deletions
|
@ -20,8 +20,7 @@ LOG_MODULE_REGISTER(spi_telink);
|
||||||
|
|
||||||
#include <drivers/spi.h>
|
#include <drivers/spi.h>
|
||||||
#include "spi_context.h"
|
#include "spi_context.h"
|
||||||
#include <drivers/pinmux.h>
|
#include <drivers/pinctrl.h>
|
||||||
#include <dt-bindings/pinctrl/b91-pinctrl.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define CHIP_SELECT_COUNT 3u
|
#define CHIP_SELECT_COUNT 3u
|
||||||
|
@ -33,8 +32,7 @@ LOG_MODULE_REGISTER(spi_telink);
|
||||||
struct spi_b91_cfg {
|
struct spi_b91_cfg {
|
||||||
uint8_t peripheral_id;
|
uint8_t peripheral_id;
|
||||||
gpio_pin_e cs_pin[CHIP_SELECT_COUNT];
|
gpio_pin_e cs_pin[CHIP_SELECT_COUNT];
|
||||||
const uint32_t *pinctrl_list;
|
const struct pinctrl_dev_config *pcfg;
|
||||||
size_t pinctrl_list_size;
|
|
||||||
};
|
};
|
||||||
#define SPI_CFG(dev) ((struct spi_b91_cfg *) ((dev)->config))
|
#define SPI_CFG(dev) ((struct spi_b91_cfg *) ((dev)->config))
|
||||||
|
|
||||||
|
@ -297,7 +295,7 @@ static bool spi_b91_is_config_supported(const struct spi_config *config,
|
||||||
static int spi_b91_config(const struct device *dev,
|
static int spi_b91_config(const struct device *dev,
|
||||||
const struct spi_config *config)
|
const struct spi_config *config)
|
||||||
{
|
{
|
||||||
const struct device *pinmux;
|
int status = 0;
|
||||||
spi_mode_type_e mode = SPI_MODE0;
|
spi_mode_type_e mode = SPI_MODE0;
|
||||||
struct spi_b91_cfg *b91_config = SPI_CFG(dev);
|
struct spi_b91_cfg *b91_config = SPI_CFG(dev);
|
||||||
struct spi_b91_data *b91_data = SPI_DATA(dev);
|
struct spi_b91_data *b91_data = SPI_DATA(dev);
|
||||||
|
@ -349,16 +347,11 @@ static int spi_b91_config(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get pinmux driver */
|
/* configure pins */
|
||||||
pinmux = DEVICE_DT_GET(DT_NODELABEL(pinmux));
|
status = pinctrl_apply_state(b91_config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||||
if (!device_is_ready(pinmux)) {
|
if (status < 0) {
|
||||||
return -ENODEV;
|
LOG_ERR("Failed to configure SPI pins");
|
||||||
}
|
return status;
|
||||||
|
|
||||||
/* config pins */
|
|
||||||
for (int i = 0; i < b91_config->pinctrl_list_size; i++) {
|
|
||||||
pinmux_pin_set(pinmux, B91_PINMUX_GET_PIN(b91_config->pinctrl_list[i]),
|
|
||||||
B91_PINMUX_GET_FUNC(b91_config->pinctrl_list[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save context config */
|
/* save context config */
|
||||||
|
@ -466,32 +459,30 @@ static struct spi_driver_api spi_b91_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* SPI driver registration */
|
/* SPI driver registration */
|
||||||
#define SPI_B91_INIT(inst) \
|
#define SPI_B91_INIT(inst) \
|
||||||
\
|
\
|
||||||
static const uint32_t spi_pins_##inst[] = \
|
PINCTRL_DT_INST_DEFINE(inst); \
|
||||||
B91_PINMUX_DT_INST_GET_ARRAY(inst, 0); \
|
\
|
||||||
\
|
static struct spi_b91_data spi_b91_data_##inst = { \
|
||||||
static struct spi_b91_data spi_b91_data_##inst = { \
|
SPI_CONTEXT_INIT_LOCK(spi_b91_data_##inst, ctx), \
|
||||||
SPI_CONTEXT_INIT_LOCK(spi_b91_data_##inst, ctx), \
|
SPI_CONTEXT_INIT_SYNC(spi_b91_data_##inst, ctx), \
|
||||||
SPI_CONTEXT_INIT_SYNC(spi_b91_data_##inst, ctx), \
|
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx) \
|
||||||
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx) \
|
}; \
|
||||||
}; \
|
\
|
||||||
\
|
static struct spi_b91_cfg spi_b91_cfg_##inst = { \
|
||||||
static struct spi_b91_cfg spi_b91_cfg_##inst = { \
|
.peripheral_id = DT_INST_ENUM_IDX(inst, peripheral_id), \
|
||||||
.peripheral_id = DT_INST_ENUM_IDX(inst, peripheral_id), \
|
.cs_pin[0] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs0_pin), \
|
||||||
.cs_pin[0] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs0_pin), \
|
.cs_pin[1] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs1_pin), \
|
||||||
.cs_pin[1] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs1_pin), \
|
.cs_pin[2] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs2_pin), \
|
||||||
.cs_pin[2] = DT_STRING_TOKEN(DT_DRV_INST(inst), cs2_pin), \
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||||
.pinctrl_list_size = ARRAY_SIZE(spi_pins_##inst), \
|
}; \
|
||||||
.pinctrl_list = spi_pins_##inst \
|
\
|
||||||
}; \
|
DEVICE_DT_INST_DEFINE(inst, spi_b91_init, \
|
||||||
\
|
NULL, \
|
||||||
DEVICE_DT_INST_DEFINE(inst, spi_b91_init, \
|
&spi_b91_data_##inst, \
|
||||||
NULL, \
|
&spi_b91_cfg_##inst, \
|
||||||
&spi_b91_data_##inst, \
|
POST_KERNEL, \
|
||||||
&spi_b91_cfg_##inst, \
|
CONFIG_SPI_INIT_PRIORITY, \
|
||||||
POST_KERNEL, \
|
|
||||||
CONFIG_SPI_INIT_PRIORITY, \
|
|
||||||
&spi_b91_api);
|
&spi_b91_api);
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(SPI_B91_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(SPI_B91_INIT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue