diff --git a/drivers/dac/dac_dacx3608.c b/drivers/dac/dac_dacx3608.c index e6f95405e90..45f476420b5 100644 --- a/drivers/dac/dac_dacx3608.c +++ b/drivers/dac/dac_dacx3608.c @@ -28,24 +28,20 @@ LOG_MODULE_REGISTER(dac_dacx3608, CONFIG_DAC_LOG_LEVEL); #define DACX3608_MAX_CHANNEL 8 struct dacx3608_config { - const char *i2c_bus; - uint16_t i2c_addr; + struct i2c_dt_spec bus; uint8_t resolution; }; struct dacx3608_data { - const struct device *i2c; uint8_t configured; }; static int dacx3608_reg_read(const struct device *dev, uint8_t reg, uint16_t *val) { - struct dacx3608_data *data = dev->data; const struct dacx3608_config *cfg = dev->config; - if (i2c_burst_read(data->i2c, cfg->i2c_addr, - reg, (uint8_t *) val, 2) < 0) { + if (i2c_burst_read_dt(&cfg->bus, reg, (uint8_t *) val, 2) < 0) { LOG_ERR("I2C read failed"); return -EIO; } @@ -58,11 +54,10 @@ static int dacx3608_reg_read(const struct device *dev, uint8_t reg, static int dacx3608_reg_write(const struct device *dev, uint8_t reg, uint16_t val) { - struct dacx3608_data *data = dev->data; const struct dacx3608_config *cfg = dev->config; uint8_t buf[3] = {reg, val >> 8, val & 0xFF}; - return i2c_write(data->i2c, buf, sizeof(buf), cfg->i2c_addr); + return i2c_write_dt(&cfg->bus, buf, sizeof(buf)); } int dacx3608_reg_update(const struct device *dev, uint8_t reg, @@ -216,10 +211,9 @@ static int dacx3608_init(const struct device *dev) struct dacx3608_data *data = dev->data; int ret; - data->i2c = device_get_binding(config->i2c_bus); - if (!data->i2c) { - LOG_ERR("Could not find I2C device"); - return -EINVAL; + if (!device_is_ready(config->bus.bus)) { + LOG_ERR("I2C device not ready"); + return -ENODEV; } ret = dacx3608_soft_reset(dev); @@ -250,8 +244,7 @@ static const struct dac_driver_api dacx3608_driver_api = { #define DACX3608_DEVICE(t, n, res) \ static struct dacx3608_data dac##t##_data_##n; \ static const struct dacx3608_config dac##t##_config_##n = { \ - .i2c_bus = DT_BUS_LABEL(INST_DT_DACX3608(n, t)), \ - .i2c_addr = DT_REG_ADDR(INST_DT_DACX3608(n, t)), \ + .bus = I2C_DT_SPEC_GET(INST_DT_DACX3608(n, t)), \ .resolution = res, \ }; \ DEVICE_DT_DEFINE(INST_DT_DACX3608(n, t), \