drivers: sensor: bq274xx: convert lazy load Kconfig option to dts property

This change allows per-instance configuration of lazy loading and
fixes build issue.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
Pieter De Gendt 2022-07-07 14:47:54 +02:00 committed by Kumar Gala
commit d01934f9e9
4 changed files with 25 additions and 29 deletions

View file

@ -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

View file

@ -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); \

View file

@ -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

View file

@ -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.