@@ -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
101101static 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
115113static 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+
117119DEVICE_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 );
0 commit comments