Skip to content

Commit 9bb7c97

Browse files
benjaminbjornssonMaureenHelm
authored andcommitted
drivers: sensor: fdc2x1x: Update driver to use i2c_dt_spec
Simplify driver by using i2c_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
1 parent e245a21 commit 9bb7c97

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

drivers/sensor/fdc2x1x/fdc2x1x.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ static int fdc2x1x_bus_access(const struct device *dev, uint8_t reg,
7575
const struct fdc2x1x_config *cfg = dev->config;
7676

7777
if (reg & FDC2X1X_READ) {
78-
return i2c_burst_read(cfg->bus,
79-
cfg->i2c_addr,
80-
FDC2X1X_TO_I2C_REG(reg),
81-
data, length);
78+
return i2c_burst_read_dt(&cfg->i2c, FDC2X1X_TO_I2C_REG(reg), data, length);
8279
} else {
8380
if (length != 2) {
8481
return -EINVAL;
@@ -89,8 +86,7 @@ static int fdc2x1x_bus_access(const struct device *dev, uint8_t reg,
8986
buf[0] = FDC2X1X_TO_I2C_REG(reg);
9087
memcpy(buf + 1, data, sizeof(uint16_t));
9188

92-
return i2c_write(cfg->bus, buf,
93-
sizeof(buf), cfg->i2c_addr);
89+
return i2c_write_dt(&cfg->i2c, buf, sizeof(buf));
9490
}
9591
}
9692

@@ -931,8 +927,8 @@ static int fdc2x1x_init(const struct device *dev)
931927
}
932928
}
933929

934-
if (!device_is_ready(cfg->bus)) {
935-
LOG_ERR("%s: fdc2x1x device not ready", dev->name);
930+
if (!device_is_ready(cfg->i2c.bus)) {
931+
LOG_ERR("I2C bus device not ready");
936932
return -ENODEV;
937933
}
938934

@@ -1007,8 +1003,7 @@ static int fdc2x1x_init(const struct device *dev)
10071003
}; \
10081004
\
10091005
static const struct fdc2x1x_config fdc2x1x_config_##n = { \
1010-
.bus = DEVICE_DT_GET(DT_INST_BUS(n)), \
1011-
.i2c_addr = DT_INST_REG_ADDR(n), \
1006+
.i2c = I2C_DT_SPEC_INST_GET(n), \
10121007
.fdc2x14 = DT_INST_PROP(n, fdc2x14), \
10131008
.autoscan_en = DT_INST_PROP(n, autoscan), \
10141009
.rr_sequence = DT_INST_PROP(n, rr_sequence), \

drivers/sensor/fdc2x1x/fdc2x1x.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ struct fdc2x1x_chx_config {
181181
};
182182

183183
struct fdc2x1x_config {
184-
const struct device *bus;
185-
uint8_t i2c_addr;
184+
struct i2c_dt_spec i2c;
186185

187186
const struct device *sd_gpio;
188187
gpio_pin_t sd_pin;

0 commit comments

Comments
 (0)