diff --git a/drivers/sensor/bq274xx/Kconfig b/drivers/sensor/bq274xx/Kconfig index 54764a5bdf7..a86eaece11b 100644 --- a/drivers/sensor/bq274xx/Kconfig +++ b/drivers/sensor/bq274xx/Kconfig @@ -2,19 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -menuconfig BQ274XX +config BQ274XX bool "BQ274xx Fuel Gauge" depends on I2C help Enable I2C-based driver for BQ274xx Fuel Gauge. - -if BQ274XX - -config BQ274XX_LAZY_CONFIGURE - bool "Configure on first usage instead of init" - help - Configuring the sensor can take a long time, which - we can delay till the first sample request and keep - the boot time as short as possible. - -endif # BQ274XX diff --git a/drivers/sensor/bq274xx/bq274xx.c b/drivers/sensor/bq274xx/bq274xx.c index 4c599aec172..e5ab21cc5ec 100644 --- a/drivers/sensor/bq274xx/bq274xx.c +++ b/drivers/sensor/bq274xx/bq274xx.c @@ -228,16 +228,13 @@ static int bq274xx_sample_fetch(const struct device *dev, struct bq274xx_data *bq274xx = dev->data; int status = 0; -#ifdef CONFIG_BQ274XX_LAZY_CONFIGURE - if (!bq274xx->lazy_loaded) { + if (!bq274xx->configured) { status = bq274xx_gauge_configure(dev); if (status < 0) { return status; } - bq274xx->lazy_loaded = true; } -#endif switch (chan) { case SENSOR_CHAN_GAUGE_VOLTAGE: @@ -402,11 +399,9 @@ static int bq274xx_gauge_init(const struct device *dev) return -EINVAL; } -#ifdef CONFIG_BQ274XX_LAZY_CONFIGURE - bq274xx->lazy_loaded = false; -#else - status = bq274xx_gauge_configure(dev); -#endif + if (!config->lazy_loading) { + status = bq274xx_gauge_configure(dev); + } return status; } @@ -414,6 +409,8 @@ static int bq274xx_gauge_init(const struct device *dev) static int bq274xx_gauge_configure(const struct device *dev) { const struct bq274xx_config *const config = dev->config; + struct bq274xx_data *data = dev->data; + int status = 0; uint8_t tmp_checksum = 0, checksum_old = 0, checksum_new = 0; uint16_t flags = 0, designenergy_mwh = 0, taperrate = 0; @@ -646,6 +643,8 @@ static int bq274xx_gauge_configure(const struct device *dev) return -EIO; } + data->configured = true; + return 0; } @@ -714,12 +713,14 @@ static int bq274xx_exit_shutdown_mode(const struct device *dev) return status; } - k_msleep(INIT_TIME); + if (!config->lazy_loading) { + k_msleep(INIT_TIME); - status = bq274xx_gauge_configure(dev); - if (status < 0) { - LOG_ERR("Unable to configure bq274xx gauge"); - return status; + status = bq274xx_gauge_configure(dev); + if (status < 0) { + LOG_ERR("Unable to configure bq274xx gauge"); + return status; + } } return 0; @@ -768,6 +769,7 @@ static const struct sensor_driver_api bq274xx_battery_driver_api = { .design_capacity = DT_INST_PROP(index, design_capacity), \ .taper_current = DT_INST_PROP(index, taper_current), \ .terminate_voltage = DT_INST_PROP(index, terminate_voltage), \ + .lazy_loading = DT_INST_PROP(index, zephyr_lazy_load), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(index, bq274xx_pm_action); \ diff --git a/drivers/sensor/bq274xx/bq274xx.h b/drivers/sensor/bq274xx/bq274xx.h index 61e67624083..4fbaaf9789b 100644 --- a/drivers/sensor/bq274xx/bq274xx.h +++ b/drivers/sensor/bq274xx/bq274xx.h @@ -81,9 +81,7 @@ LOG_MODULE_REGISTER(bq274xx, CONFIG_SENSOR_LOG_LEVEL); #define BQ274XX_DELAY 1000 struct bq274xx_data { -#ifdef CONFIG_BQ274XX_LAZY_CONFIGURE - bool lazy_loaded; -#endif + bool configured; uint16_t voltage; int16_t avg_current; int16_t stdby_current; @@ -107,6 +105,7 @@ struct bq274xx_config { #ifdef CONFIG_PM_DEVICE struct gpio_dt_spec int_gpios; #endif + bool lazy_loading; }; #endif diff --git a/dts/bindings/sensor/ti,bq274xx.yaml b/dts/bindings/sensor/ti,bq274xx.yaml index 5594f779969..8dc7b22b3cf 100644 --- a/dts/bindings/sensor/ti,bq274xx.yaml +++ b/dts/bindings/sensor/ti,bq274xx.yaml @@ -40,3 +40,9 @@ properties: specific events happening (e.g. change in State of Charge). While in shutdown mode it acts as an input and toggling it will make the sensor exit the mode. + + zephyr,lazy-load: + type: boolean + description: | + Configuring the sensor can take a long time, using lazy loading we can delay + until the first sample request and keep the boot time as short as possible.