Skip to content

Commit e3f991b

Browse files
galakMaureenHelm
authored andcommitted
drivers: sensor: ams_iAQcore: Update driver to use i2c_dt_spec
Move driver to use i2c_dt_spec for I2C bus access. Signed-off-by: Kumar Gala <galak@kernel.org>
1 parent 6cff868 commit e3f991b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

drivers/sensor/ams_iAQcore/iAQcore.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static int iaqcore_sample_fetch(const struct device *dev,
2323
enum sensor_channel chan)
2424
{
2525
struct iaq_core_data *drv_data = dev->data;
26+
const struct iaq_core_config *config = dev->config;
2627
struct iaq_registers buf;
2728
struct i2c_msg msg;
2829
int ret, tries;
@@ -35,8 +36,7 @@ static int iaqcore_sample_fetch(const struct device *dev,
3536

3637
for (tries = 0; tries < CONFIG_IAQ_CORE_MAX_READ_RETRIES; tries++) {
3738

38-
ret = i2c_transfer(drv_data->i2c, &msg, 1,
39-
DT_INST_REG_ADDR(0));
39+
ret = i2c_transfer_dt(&config->i2c, &msg, 1);
4040
if (ret < 0) {
4141
LOG_ERR("Failed to read registers data [%d].", ret);
4242
return -EIO;
@@ -100,20 +100,22 @@ static const struct sensor_driver_api iaq_core_driver_api = {
100100

101101
static int iaq_core_init(const struct device *dev)
102102
{
103-
struct iaq_core_data *drv_data = dev->data;
103+
const struct iaq_core_config *config = dev->config;
104104

105-
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
106-
if (drv_data->i2c == NULL) {
107-
LOG_ERR("Failed to get pointer to %s device!",
108-
DT_INST_BUS_LABEL(0));
109-
return -EINVAL;
105+
if (!device_is_ready(config->i2c.bus)) {
106+
LOG_ERR("Bus device is not ready");
107+
return -ENODEV;
110108
}
111109

112110
return 0;
113111
}
114112

115113
static struct iaq_core_data iaq_core_driver;
116114

115+
static const struct iaq_core_config iaq_core_config = {
116+
.i2c = I2C_DT_SPEC_INST_GET(0),
117+
};
118+
117119
DEVICE_DT_INST_DEFINE(0, iaq_core_init, NULL,
118-
&iaq_core_driver, NULL, POST_KERNEL,
120+
&iaq_core_driver, &iaq_core_config, POST_KERNEL,
119121
CONFIG_SENSOR_INIT_PRIORITY, &iaq_core_driver_api);

drivers/sensor/ams_iAQcore/iAQcore.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ struct iaq_registers {
1717
uint16_t voc;
1818
} __packed;
1919

20+
struct iaq_core_config {
21+
struct i2c_dt_spec i2c;
22+
};
23+
2024
struct iaq_core_data {
21-
const struct device *i2c;
2225
uint16_t co2;
2326
uint16_t voc;
2427
uint8_t status;

0 commit comments

Comments
 (0)