Skip to content

Commit 8779972

Browse files
bbilasnashif
authored andcommitted
drivers: ethernet: dsa_ksz8xxx: convert to spi_dt_spec
Convert dsa_ksz8xxx driver to use `spi_dt_spec` helpers. Signed-off-by: Bartosz Bilas <[email protected]>
1 parent b565683 commit 8779972

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

drivers/ethernet/dsa_ksz8xxx.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ struct ksz8xxx_data {
3838
int iface_init_count;
3939
bool is_init;
4040
#if defined(CONFIG_DSA_SPI)
41-
const struct device *spi;
42-
struct spi_config spi_cfg;
43-
struct spi_cs_control cs_ctrl;
41+
struct spi_dt_spec spi;
4442
#endif
4543
};
4644

@@ -66,7 +64,7 @@ static void dsa_ksz8xxx_write_reg(const struct ksz8xxx_data *pdev,
6664
buf[1] = (reg_addr << 1) & 0xFE;
6765
buf[2] = value;
6866

69-
spi_write(pdev->spi, &pdev->spi_cfg, &tx);
67+
spi_write_dt(&pdev->spi, &tx);
7068
#endif
7169
}
7270

@@ -98,7 +96,7 @@ static void dsa_ksz8xxx_read_reg(const struct ksz8xxx_data *pdev,
9896
buf[1] = (reg_addr << 1) & 0xFE;
9997
buf[2] = 0x0;
10098

101-
if (!spi_transceive(pdev->spi, &pdev->spi_cfg, &tx, &rx)) {
99+
if (!spi_transceive_dt(&pdev->spi, &tx, &rx)) {
102100
*value = buf[2];
103101
} else {
104102
LOG_DBG("Failure while reading register 0x%04x", reg_addr);
@@ -669,29 +667,19 @@ static int dsa_ksz8xxx_configure_bus(struct ksz8xxx_data *pdev)
669667
{
670668
#if defined(CONFIG_DSA_SPI)
671669
/* SPI config */
672-
pdev->spi_cfg.operation =
670+
pdev->spi = (struct spi_dt_spec) SPI_DT_SPEC_INST_GET(0,
673671
#if DT_INST_PROP(0, spi_cpol)
674672
SPI_MODE_CPOL |
675673
#endif
676674
#if DT_INST_PROP(0, spi_cpha)
677675
SPI_MODE_CPHA |
678676
#endif
679-
SPI_WORD_SET(8);
680-
681-
pdev->spi_cfg.frequency = DT_INST_PROP(0, spi_max_frequency);
682-
pdev->spi_cfg.slave = DT_INST_REG_ADDR(0);
683-
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
684-
pdev->cs_ctrl.gpio_dev =
685-
device_get_binding(DT_INST_SPI_DEV_CS_GPIOS_LABEL(0));
686-
pdev->cs_ctrl.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
687-
pdev->cs_ctrl.gpio_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(0);
688-
pdev->cs_ctrl.delay = 0U;
689-
pdev->spi_cfg.cs = &(pdev->cs_ctrl);
690-
#else
691-
pdev->spi_cfg.cs = NULL;
692-
#endif
693-
pdev->spi = device_get_binding(DT_INST_BUS_LABEL(0));
694-
if (!pdev->spi) {
677+
SPI_WORD_SET(8),
678+
0U);
679+
680+
if (!spi_is_ready(&pdev->spi)) {
681+
LOG_ERR("SPI bus %s is not ready",
682+
pdev->spi.bus->name);
695683
return -ENODEV;
696684
}
697685
#endif

0 commit comments

Comments
 (0)