@@ -28,11 +28,11 @@ LOG_MODULE_REGISTER(max17055, CONFIG_SENSOR_LOG_LEVEL);
2828static int max17055_reg_read (const struct device * dev , int reg_addr ,
2929 int16_t * valp )
3030{
31- struct max17055_data * priv = dev -> data ;
31+ const struct max17055_config * config = dev -> config ;
3232 uint8_t i2c_data [2 ];
3333 int rc ;
3434
35- rc = i2c_burst_read ( priv -> i2c , DT_INST_REG_ADDR ( 0 ) , reg_addr , i2c_data , 2 );
35+ rc = i2c_burst_read_dt ( & config -> i2c , reg_addr , i2c_data , 2 );
3636 if (rc < 0 ) {
3737 LOG_ERR ("Unable to read register" );
3838 return rc ;
@@ -45,13 +45,13 @@ static int max17055_reg_read(const struct device *dev, int reg_addr,
4545static int max17055_reg_write (const struct device * dev , int reg_addr ,
4646 uint16_t val )
4747{
48- struct max17055_data * priv = dev -> data ;
48+ const struct max17055_config * config = dev -> config ;
4949 uint8_t buf [3 ];
5050
5151 buf [0 ] = (uint8_t )reg_addr ;
5252 sys_put_le16 (val , & buf [1 ]);
5353
54- return i2c_write ( priv -> i2c , buf , sizeof (buf ), DT_INST_REG_ADDR ( 0 ));
54+ return i2c_write_dt ( & config -> i2c , buf , sizeof (buf ));
5555}
5656
5757/**
@@ -347,13 +347,11 @@ static int max17055_init_config(const struct device *dev)
347347static int max17055_gauge_init (const struct device * dev )
348348{
349349 int16_t tmp ;
350- struct max17055_data * priv = dev -> data ;
351350 const struct max17055_config * const config = dev -> config ;
352351
353- priv -> i2c = device_get_binding (config -> bus_name );
354- if (!priv -> i2c ) {
355- LOG_ERR ("Could not get pointer to %s device" , config -> bus_name );
356- return - EINVAL ;
352+ if (!device_is_ready (config -> i2c .bus )) {
353+ LOG_ERR ("Bus device is not ready" );
354+ return - ENODEV ;
357355 }
358356
359357 if (max17055_reg_read (dev , STATUS , & tmp )) {
@@ -393,7 +391,7 @@ static const struct sensor_driver_api max17055_battery_driver_api = {
393391 static struct max17055_data max17055_driver_##index; \
394392 \
395393 static const struct max17055_config max17055_config_##index = { \
396- .bus_name = DT_INST_BUS_LABEL (index), \
394+ .i2c = I2C_DT_SPEC_INST_GET (index), \
397395 .design_capacity = DT_INST_PROP(index, design_capacity), \
398396 .design_voltage = DT_INST_PROP(index, design_voltage), \
399397 .desired_charging_current = DT_INST_PROP(index, desired_charging_current), \
0 commit comments