diff --git a/drivers/display/ssd16xx.c b/drivers/display/ssd16xx.c index 7739a86d435..ab0ce7b3b27 100644 --- a/drivers/display/ssd16xx.c +++ b/drivers/display/ssd16xx.c @@ -25,16 +25,9 @@ LOG_MODULE_REGISTER(ssd16xx); * SSD1673, SSD1608, SSD1681, ILI3897 compatible EPD controller driver. */ -#define SSD16XX_SPI_FREQ DT_INST_PROP(0, spi_max_frequency) -#define SSD16XX_BUS_NAME DT_INST_BUS_LABEL(0) #define SSD16XX_DC_PIN DT_INST_GPIO_PIN(0, dc_gpios) #define SSD16XX_DC_FLAGS DT_INST_GPIO_FLAGS(0, dc_gpios) #define SSD16XX_DC_CNTRL DT_INST_GPIO_LABEL(0, dc_gpios) -#define SSD16XX_CS_PIN DT_INST_SPI_DEV_CS_GPIOS_PIN(0) -#define SSD16XX_CS_FLAGS DT_INST_SPI_DEV_CS_GPIOS_FLAGS(0) -#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0) -#define SSD16XX_CS_CNTRL DT_INST_SPI_DEV_CS_GPIOS_LABEL(0) -#endif #define SSD16XX_BUSY_PIN DT_INST_GPIO_PIN(0, busy_gpios) #define SSD16XX_BUSY_CNTRL DT_INST_GPIO_LABEL(0, busy_gpios) #define SSD16XX_BUSY_FLAGS DT_INST_GPIO_FLAGS(0, busy_gpios) @@ -62,15 +55,15 @@ struct ssd16xx_data { const struct device *reset; const struct device *dc; const struct device *busy; - const struct device *spi_dev; - struct spi_config spi_config; -#if defined(SSD16XX_CS_CNTRL) - struct spi_cs_control cs_ctrl; -#endif + const struct ssd16xx_config *config; uint8_t scan_mode; uint8_t update_cmd; }; +struct ssd16xx_config { + struct spi_dt_spec bus; +}; + #if DT_INST_NODE_HAS_PROP(0, lut_initial) static uint8_t ssd16xx_lut_initial[] = DT_INST_PROP(0, lut_initial); #endif @@ -91,7 +84,7 @@ static inline int ssd16xx_write_cmd(struct ssd16xx_data *driver, struct spi_buf_set buf_set = {.buffers = &buf, .count = 1}; gpio_pin_set(driver->dc, SSD16XX_DC_PIN, 1); - err = spi_write(driver->spi_dev, &driver->spi_config, &buf_set); + err = spi_write_dt(&driver->config->bus, &buf_set); if (err < 0) { return err; } @@ -100,7 +93,7 @@ static inline int ssd16xx_write_cmd(struct ssd16xx_data *driver, buf.buf = data; buf.len = len; gpio_pin_set(driver->dc, SSD16XX_DC_PIN, 0); - err = spi_write(driver->spi_dev, &driver->spi_config, &buf_set); + err = spi_write_dt(&driver->config->bus, &buf_set); if (err < 0) { return err; } @@ -643,21 +636,16 @@ static int ssd16xx_controller_init(const struct device *dev) static int ssd16xx_init(const struct device *dev) { + const struct ssd16xx_config *config = dev->config; struct ssd16xx_data *driver = dev->data; LOG_DBG(""); - driver->spi_dev = device_get_binding(SSD16XX_BUS_NAME); - if (driver->spi_dev == NULL) { - LOG_ERR("Could not get SPI device for SSD16XX"); - return -EIO; + if (!spi_is_ready(&config->bus)) { + LOG_ERR("SPI bus %s not ready", config->bus.bus->name); + return -ENODEV; } - driver->spi_config.frequency = SSD16XX_SPI_FREQ; - driver->spi_config.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - driver->spi_config.slave = DT_INST_REG_ADDR(0); - driver->spi_config.cs = NULL; - driver->reset = device_get_binding(SSD16XX_RESET_CNTRL); if (driver->reset == NULL) { LOG_ERR("Could not get GPIO port for SSD16XX reset"); @@ -685,23 +673,17 @@ static int ssd16xx_init(const struct device *dev) gpio_pin_configure(driver->busy, SSD16XX_BUSY_PIN, GPIO_INPUT | SSD16XX_BUSY_FLAGS); -#if defined(SSD16XX_CS_CNTRL) - driver->cs_ctrl.gpio_dev = device_get_binding(SSD16XX_CS_CNTRL); - if (!driver->cs_ctrl.gpio_dev) { - LOG_ERR("Unable to get SPI GPIO CS device"); - return -EIO; - } - - driver->cs_ctrl.gpio_pin = SSD16XX_CS_PIN; - driver->cs_ctrl.gpio_dt_flags = SSD16XX_CS_FLAGS; - driver->cs_ctrl.delay = 0U; - driver->spi_config.cs = &driver->cs_ctrl; -#endif - return ssd16xx_controller_init(dev); } -static struct ssd16xx_data ssd16xx_driver; +static const struct ssd16xx_config ssd16xx_config = { + .bus = SPI_DT_SPEC_INST_GET( + 0, SPI_OP_MODE_MASTER | SPI_WORD_SET(8), 0) +}; + +static struct ssd16xx_data ssd16xx_driver = { + .config = &ssd16xx_config +}; static struct display_driver_api ssd16xx_driver_api = { .blanking_on = ssd16xx_blanking_on,