ethernet: enc424j600: convert to _dt_spec
Convert enc424j600 ethernet driver to `spi_dt_spect` and `gpio_dt_spec`. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
a94cfb42a3
commit
128e8a4a6f
|
@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(ethdrv, CONFIG_ETHERNET_LOG_LEVEL);
|
|||
|
||||
static void enc424j600_write_sbc(const struct device *dev, uint8_t cmd)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[2] = { cmd, 0xFF };
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buf,
|
||||
|
@ -37,13 +37,13 @@ static void enc424j600_write_sbc(const struct device *dev, uint8_t cmd)
|
|||
.count = 1
|
||||
};
|
||||
|
||||
spi_write(context->spi, &context->spi_cfg, &tx);
|
||||
spi_write_dt(&config->spi, &tx);
|
||||
}
|
||||
|
||||
static void enc424j600_write_sfru(const struct device *dev, uint8_t addr,
|
||||
uint16_t value)
|
||||
uint16_t value)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[4];
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buf,
|
||||
|
@ -59,13 +59,13 @@ static void enc424j600_write_sfru(const struct device *dev, uint8_t addr,
|
|||
buf[2] = value;
|
||||
buf[3] = value >> 8;
|
||||
|
||||
spi_write(context->spi, &context->spi_cfg, &tx);
|
||||
spi_write_dt(&config->spi, &tx);
|
||||
}
|
||||
|
||||
static void enc424j600_read_sfru(const struct device *dev, uint8_t addr,
|
||||
uint16_t *value)
|
||||
uint16_t *value)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[4];
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buf,
|
||||
|
@ -87,7 +87,7 @@ static void enc424j600_read_sfru(const struct device *dev, uint8_t addr,
|
|||
buf[0] = ENC424J600_NBC_RCRU;
|
||||
buf[1] = addr;
|
||||
|
||||
if (!spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
||||
if (!spi_transceive_dt(&config->spi, &tx, &rx)) {
|
||||
*value = ((uint16_t)buf[3] << 8 | buf[2]);
|
||||
} else {
|
||||
LOG_DBG("Failure while reading register 0x%02x", addr);
|
||||
|
@ -98,7 +98,7 @@ static void enc424j600_read_sfru(const struct device *dev, uint8_t addr,
|
|||
static void enc424j600_modify_sfru(const struct device *dev, uint8_t opcode,
|
||||
uint16_t addr, uint16_t value)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[4];
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buf,
|
||||
|
@ -114,13 +114,13 @@ static void enc424j600_modify_sfru(const struct device *dev, uint8_t opcode,
|
|||
buf[2] = value;
|
||||
buf[3] = value >> 8;
|
||||
|
||||
spi_write(context->spi, &context->spi_cfg, &tx);
|
||||
spi_write_dt(&config->spi, &tx);
|
||||
}
|
||||
|
||||
#define enc424j600_set_sfru(dev, addr, value) \
|
||||
enc424j600_modify_sfru(dev, ENC424J600_NBC_BFSU, addr, value)
|
||||
|
||||
#define enc424j600_clear_sfru(dev, addr, value) \
|
||||
#define enc424j600_clear_sfru(dev, addr, value) \
|
||||
enc424j600_modify_sfru(dev, ENC424J600_NBC_BFCU, addr, value)
|
||||
|
||||
|
||||
|
@ -159,7 +159,7 @@ static void enc424j600_read_phy(const struct device *dev, uint16_t addr,
|
|||
static void enc424j600_write_mem(const struct device *dev, uint8_t opcode,
|
||||
uint8_t *data_buffer, uint16_t buf_len)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[1] = { opcode };
|
||||
const struct spi_buf tx_buf[2] = {
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ static void enc424j600_write_mem(const struct device *dev, uint8_t opcode,
|
|||
.count = 2
|
||||
};
|
||||
|
||||
if (spi_write(context->spi, &context->spi_cfg, &tx)) {
|
||||
if (spi_write_dt(&config->spi, &tx)) {
|
||||
LOG_ERR("Failed to write SRAM buffer");
|
||||
return;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ static void enc424j600_write_mem(const struct device *dev, uint8_t opcode,
|
|||
static void enc424j600_read_mem(const struct device *dev, uint8_t opcode,
|
||||
uint8_t *data_buffer, uint16_t buf_len)
|
||||
{
|
||||
struct enc424j600_runtime *context = dev->data;
|
||||
const struct enc424j600_config *config = dev->config;
|
||||
uint8_t buf[1] = { opcode };
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buf,
|
||||
|
@ -210,7 +210,7 @@ static void enc424j600_read_mem(const struct device *dev, uint8_t opcode,
|
|||
.count = 2
|
||||
};
|
||||
|
||||
if (spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
||||
if (spi_transceive_dt(&config->spi, &tx, &rx)) {
|
||||
LOG_ERR("Failed to read SRAM buffer");
|
||||
return;
|
||||
}
|
||||
|
@ -656,52 +656,32 @@ static int enc424j600_init(const struct device *dev)
|
|||
context->dev = dev;
|
||||
|
||||
/* SPI config */
|
||||
context->spi_cfg.operation = SPI_WORD_SET(8);
|
||||
context->spi_cfg.frequency = config->spi_freq;
|
||||
context->spi_cfg.slave = config->spi_slave;
|
||||
|
||||
context->spi = device_get_binding((char *)config->spi_port);
|
||||
if (!context->spi) {
|
||||
LOG_ERR("SPI master port %s not found", config->spi_port);
|
||||
if (!spi_is_ready(&config->spi)) {
|
||||
LOG_ERR("SPI master port %s not ready", config->spi.bus->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
context->spi_cs.gpio_dev =
|
||||
device_get_binding((char *)config->spi_cs_port);
|
||||
if (!context->spi_cs.gpio_dev) {
|
||||
LOG_ERR("SPI CS port %s not found", config->spi_cs_port);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
context->spi_cs.gpio_pin = config->spi_cs_pin;
|
||||
context->spi_cs.gpio_dt_flags = config->spi_cs_dt_flags;
|
||||
context->spi_cfg.cs = &context->spi_cs;
|
||||
#endif
|
||||
|
||||
/* Initialize GPIO */
|
||||
context->gpio = device_get_binding((char *)config->gpio_port);
|
||||
if (!context->gpio) {
|
||||
LOG_ERR("GPIO port %s not found", config->gpio_port);
|
||||
if (!device_is_ready(config->interrupt.port)) {
|
||||
LOG_ERR("GPIO port %s not ready", config->interrupt.port->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gpio_pin_configure(context->gpio, config->gpio_pin,
|
||||
GPIO_INPUT | config->gpio_flags)) {
|
||||
LOG_ERR("Unable to configure GPIO pin %u", config->gpio_pin);
|
||||
if (gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT)) {
|
||||
LOG_ERR("Unable to configure GPIO pin %u",
|
||||
config->interrupt.pin);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gpio_init_callback(&(context->gpio_cb), enc424j600_gpio_callback,
|
||||
BIT(config->gpio_pin));
|
||||
BIT(config->interrupt.pin));
|
||||
|
||||
if (gpio_add_callback(context->gpio, &(context->gpio_cb))) {
|
||||
if (gpio_add_callback(config->interrupt.port, &(context->gpio_cb))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gpio_pin_interrupt_configure(context->gpio,
|
||||
config->gpio_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
gpio_pin_interrupt_configure_dt(&config->interrupt,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
|
||||
/* Check SPI connection */
|
||||
do {
|
||||
|
@ -808,17 +788,8 @@ static struct enc424j600_runtime enc424j600_0_runtime = {
|
|||
};
|
||||
|
||||
static const struct enc424j600_config enc424j600_0_config = {
|
||||
.gpio_port = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
||||
.spi_port = DT_INST_BUS_LABEL(0),
|
||||
.spi_freq = DT_INST_PROP(0, spi_max_frequency),
|
||||
.spi_slave = DT_INST_REG_ADDR(0),
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
.spi_cs_port = DT_INST_SPI_DEV_CS_GPIOS_LABEL(0),
|
||||
.spi_cs_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0),
|
||||
.spi_cs_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(0),
|
||||
#endif
|
||||
.spi = SPI_DT_SPEC_INST_GET(0, SPI_WORD_SET(8), 0),
|
||||
.interrupt = GPIO_DT_SPEC_INST_GET(0, int_gpios),
|
||||
.timeout = CONFIG_ETH_ENC424J600_TIMEOUT,
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <kernel.h>
|
||||
#include <drivers/gpio.h>
|
||||
#include <drivers/spi.h>
|
||||
|
||||
#ifndef _ENC424J600_
|
||||
#define _ENC424J600_
|
||||
|
@ -273,15 +274,8 @@
|
|||
#define ENC424J600_PHY_READY_DELAY 260U
|
||||
|
||||
struct enc424j600_config {
|
||||
const char *gpio_port;
|
||||
uint8_t gpio_pin;
|
||||
gpio_dt_flags_t gpio_flags;
|
||||
const char *spi_port;
|
||||
gpio_pin_t spi_cs_pin;
|
||||
gpio_dt_flags_t spi_cs_dt_flags;
|
||||
const char *spi_cs_port;
|
||||
uint32_t spi_freq;
|
||||
uint8_t spi_slave;
|
||||
struct spi_dt_spec spi;
|
||||
struct gpio_dt_spec interrupt;
|
||||
uint8_t full_duplex;
|
||||
int32_t timeout;
|
||||
};
|
||||
|
@ -295,10 +289,6 @@ struct enc424j600_runtime {
|
|||
|
||||
struct k_thread thread;
|
||||
uint8_t mac_address[6];
|
||||
const struct device *gpio;
|
||||
const struct device *spi;
|
||||
struct spi_cs_control spi_cs;
|
||||
struct spi_config spi_cfg;
|
||||
struct gpio_callback gpio_cb;
|
||||
struct k_sem tx_rx_sem;
|
||||
struct k_sem int_sem;
|
||||
|
|
Loading…
Reference in a new issue