drivers: sensor: bq274xx: remove bq274xx prefixes

Shorten lines lengths.
Remove bq274xx prefixes from static function names.
Removes repetition of bq274xx in logging.

Signed-off-by: Oleh Lozynskyy <oleh.lozynskyy@gmail.com>
This commit is contained in:
Oleh Lozynskyy 2023-03-27 18:13:28 +02:00 committed by Carles Cufí
parent 765698e3a2
commit 0f37378a95
2 changed files with 68 additions and 68 deletions

View file

@ -26,9 +26,9 @@ LOG_MODULE_REGISTER(bq274xx, CONFIG_SENSOR_LOG_LEVEL);
/* Time it takes device to initialize before doing any configuration */
#define INIT_TIME 100U
static int bq274xx_gauge_configure(const struct device *dev);
static int gauge_configure(const struct device *dev);
static int bq274xx_command_reg_read(const struct device *dev, uint8_t reg_addr,
static int command_reg_read(const struct device *dev, uint8_t reg_addr,
int16_t *val)
{
const struct bq274xx_config *config = dev->config;
@ -47,7 +47,7 @@ static int bq274xx_command_reg_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int bq274xx_control_reg_write(const struct device *dev,
static int control_reg_write(const struct device *dev,
uint16_t subcommand)
{
const struct bq274xx_config *config = dev->config;
@ -79,7 +79,7 @@ static int bq274xx_control_reg_write(const struct device *dev,
return 0;
}
static int bq274xx_command_reg_write(const struct device *dev, uint8_t command,
static int command_reg_write(const struct device *dev, uint8_t command,
uint8_t data)
{
const struct bq274xx_config *config = dev->config;
@ -99,7 +99,7 @@ static int bq274xx_command_reg_write(const struct device *dev, uint8_t command,
return 0;
}
static int bq274xx_read_data_block(const struct device *dev, uint8_t offset,
static int read_data_block(const struct device *dev, uint8_t offset,
uint8_t *data, uint8_t bytes)
{
const struct bq274xx_config *config = dev->config;
@ -120,18 +120,18 @@ static int bq274xx_read_data_block(const struct device *dev, uint8_t offset,
return 0;
}
static int bq274xx_get_device_type(const struct device *dev, uint16_t *val)
static int get_device_type(const struct device *dev, uint16_t *val)
{
int ret;
ret =
bq274xx_control_reg_write(dev, BQ274XX_CONTROL_DEVICE_TYPE);
control_reg_write(dev, BQ274XX_CONTROL_DEVICE_TYPE);
if (ret < 0) {
LOG_ERR("Unable to write control register");
return -EIO;
}
ret = bq274xx_command_reg_read(dev, BQ274XX_COMMAND_CONTROL_LOW,
ret = command_reg_read(dev, BQ274XX_COMMAND_CONTROL_LOW,
val);
if (ret < 0) {
@ -147,7 +147,7 @@ static int bq274xx_get_device_type(const struct device *dev, uint16_t *val)
*
* @return -ENOTSUP for unsupported channels
*/
static int bq274xx_channel_get(const struct device *dev,
static int channel_get(const struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
{
@ -225,14 +225,14 @@ static int bq274xx_channel_get(const struct device *dev,
return 0;
}
static int bq274xx_sample_fetch(const struct device *dev,
static int sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
struct bq274xx_data *data = dev->data;
int ret = 0;
if (!data->configured) {
ret = bq274xx_gauge_configure(dev);
ret = gauge_configure(dev);
if (ret < 0) {
return ret;
@ -241,7 +241,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
switch (chan) {
case SENSOR_CHAN_GAUGE_VOLTAGE:
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_VOLTAGE, &data->voltage);
if (ret < 0) {
LOG_ERR("Failed to read voltage");
@ -250,7 +250,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_AVG_CURRENT:
ret = bq274xx_command_reg_read(dev,
ret = command_reg_read(dev,
BQ274XX_COMMAND_AVG_CURRENT,
&data->avg_current);
if (ret < 0) {
@ -260,7 +260,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_TEMP:
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_INT_TEMP,
&data->internal_temperature);
if (ret < 0) {
@ -270,7 +270,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_STDBY_CURRENT:
ret = bq274xx_command_reg_read(dev,
ret = command_reg_read(dev,
BQ274XX_COMMAND_STDBY_CURRENT,
&data->stdby_current);
if (ret < 0) {
@ -280,7 +280,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT:
ret = bq274xx_command_reg_read(dev,
ret = command_reg_read(dev,
BQ274XX_COMMAND_MAX_CURRENT,
&data->max_load_current);
if (ret < 0) {
@ -290,7 +290,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE:
ret = bq274xx_command_reg_read(dev, BQ274XX_COMMAND_SOC,
ret = command_reg_read(dev, BQ274XX_COMMAND_SOC,
&data->state_of_charge);
if (ret < 0) {
LOG_ERR("Failed to read state of charge");
@ -299,7 +299,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY:
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_FULL_CAPACITY,
&data->full_charge_capacity);
if (ret < 0) {
@ -309,7 +309,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY:
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_REM_CAPACITY,
&data->remaining_charge_capacity);
if (ret < 0) {
@ -319,7 +319,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY:
ret = bq274xx_command_reg_read(dev,
ret = command_reg_read(dev,
BQ274XX_COMMAND_NOM_CAPACITY,
&data->nom_avail_capacity);
if (ret < 0) {
@ -330,7 +330,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
case SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY:
ret =
bq274xx_command_reg_read(dev,
command_reg_read(dev,
BQ274XX_COMMAND_AVAIL_CAPACITY,
&data->full_avail_capacity);
if (ret < 0) {
@ -340,7 +340,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_AVG_POWER:
ret = bq274xx_command_reg_read(dev,
ret = command_reg_read(dev,
BQ274XX_COMMAND_AVG_POWER,
&data->avg_power);
if (ret < 0) {
@ -350,7 +350,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
break;
case SENSOR_CHAN_GAUGE_STATE_OF_HEALTH:
ret = bq274xx_command_reg_read(dev, BQ274XX_COMMAND_SOH,
ret = command_reg_read(dev, BQ274XX_COMMAND_SOH,
&data->state_of_health);
data->state_of_health = (data->state_of_health) & 0x00FF;
@ -373,7 +373,7 @@ static int bq274xx_sample_fetch(const struct device *dev,
*
* @return 0 for success
*/
static int bq274xx_gauge_init(const struct device *dev)
static int gauge_init(const struct device *dev)
{
const struct bq274xx_config *const config = dev->config;
int ret = 0;
@ -391,7 +391,7 @@ static int bq274xx_gauge_init(const struct device *dev)
}
#endif
ret = bq274xx_get_device_type(dev, &id);
ret = get_device_type(dev, &id);
if (ret < 0) {
LOG_ERR("Unable to get device ID");
return -EIO;
@ -411,13 +411,13 @@ static int bq274xx_gauge_init(const struct device *dev)
#endif
if (!config->lazy_loading) {
ret = bq274xx_gauge_configure(dev);
ret = gauge_configure(dev);
}
return ret;
}
static int bq274xx_gauge_configure(const struct device *dev)
static int gauge_configure(const struct device *dev)
{
const struct bq274xx_config *const config = dev->config;
struct bq274xx_data *data = dev->data;
@ -435,20 +435,20 @@ static int bq274xx_gauge_configure(const struct device *dev)
(uint16_t)config->design_capacity / (0.1 * config->taper_current);
/** Unseal the battery control register **/
ret = bq274xx_control_reg_write(dev, BQ274XX_UNSEAL_KEY);
ret = control_reg_write(dev, BQ274XX_UNSEAL_KEY);
if (ret < 0) {
LOG_ERR("Unable to unseal the battery");
return -EIO;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_UNSEAL_KEY);
ret = control_reg_write(dev, BQ274XX_UNSEAL_KEY);
if (ret < 0) {
LOG_ERR("Unable to unseal the battery");
return -EIO;
}
/* Send CFG_UPDATE */
ret = bq274xx_control_reg_write(dev,
ret = control_reg_write(dev,
BQ274XX_CONTROL_SET_CFGUPDATE);
if (ret < 0) {
LOG_ERR("Unable to set CFGUpdate");
@ -457,7 +457,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
/** Step to place the Gauge into CONFIG UPDATE Mode **/
do {
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_FLAGS, &flags);
if (ret < 0) {
LOG_ERR("Unable to read flags");
@ -470,7 +470,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
} while (!(flags & 0x0010));
ret = bq274xx_command_reg_write(dev,
ret = command_reg_write(dev,
BQ274XX_EXTENDED_DATA_CONTROL, 0x00);
if (ret < 0) {
LOG_ERR("Failed to enable block data memory");
@ -478,7 +478,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
}
/* Access State subclass */
ret = bq274xx_command_reg_write(dev, BQ274XX_EXTENDED_DATA_CLASS,
ret = command_reg_write(dev, BQ274XX_EXTENDED_DATA_CLASS,
0x52);
if (ret < 0) {
LOG_ERR("Failed to update state subclass");
@ -486,7 +486,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
}
/* Write the block offset */
ret = bq274xx_command_reg_write(dev, BQ274XX_EXTENDED_DATA_BLOCK,
ret = command_reg_write(dev, BQ274XX_EXTENDED_DATA_BLOCK,
0x00);
if (ret < 0) {
LOG_ERR("Failed to update block offset");
@ -497,7 +497,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
block[i] = 0;
}
ret = bq274xx_read_data_block(dev, 0x00, block, 32);
ret = read_data_block(dev, 0x00, block, 32);
if (ret < 0) {
LOG_ERR("Unable to read block data");
return -EIO;
@ -593,7 +593,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
block[i] = 0;
}
ret = bq274xx_read_data_block(dev, 0x00, block, 32);
ret = read_data_block(dev, 0x00, block, 32);
if (ret < 0) {
LOG_ERR("Unable to read block data");
return -EIO;
@ -605,7 +605,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
}
checksum_new = 255 - checksum_new;
ret = bq274xx_command_reg_write(dev, BQ274XX_EXTENDED_CHECKSUM,
ret = command_reg_write(dev, BQ274XX_EXTENDED_CHECKSUM,
checksum_new);
if (ret < 0) {
LOG_ERR("Failed to update new checksum");
@ -620,13 +620,13 @@ static int bq274xx_gauge_configure(const struct device *dev)
return -EIO;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_CONTROL_BAT_INSERT);
ret = control_reg_write(dev, BQ274XX_CONTROL_BAT_INSERT);
if (ret < 0) {
LOG_ERR("Unable to configure BAT Detect");
return -EIO;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_CONTROL_SOFT_RESET);
ret = control_reg_write(dev, BQ274XX_CONTROL_SOFT_RESET);
if (ret < 0) {
LOG_ERR("Failed to soft reset the gauge");
return -EIO;
@ -635,7 +635,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
flags = 0;
/* Poll Flags */
do {
ret = bq274xx_command_reg_read(
ret = command_reg_read(
dev, BQ274XX_COMMAND_FLAGS, &flags);
if (ret < 0) {
LOG_ERR("Unable to read flags");
@ -648,7 +648,7 @@ static int bq274xx_gauge_configure(const struct device *dev)
} while (flags & 0x0010);
/* Seal the gauge */
ret = bq274xx_control_reg_write(dev, BQ274XX_CONTROL_SEALED);
ret = control_reg_write(dev, BQ274XX_CONTROL_SEALED);
if (ret < 0) {
LOG_ERR("Failed to seal the gauge");
return -EIO;
@ -660,36 +660,36 @@ static int bq274xx_gauge_configure(const struct device *dev)
}
#ifdef CONFIG_BQ274XX_PM
static int bq274xx_enter_shutdown_mode(const struct device *dev)
static int enter_shutdown_mode(const struct device *dev)
{
int ret;
ret = bq274xx_control_reg_write(dev, BQ274XX_UNSEAL_KEY);
ret = control_reg_write(dev, BQ274XX_UNSEAL_KEY);
if (ret < 0) {
LOG_ERR("Unable to unseal the battery");
return ret;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_UNSEAL_KEY);
ret = control_reg_write(dev, BQ274XX_UNSEAL_KEY);
if (ret < 0) {
LOG_ERR("Unable to unseal the battery");
return ret;
}
ret = bq274xx_control_reg_write(dev,
ret = control_reg_write(dev,
BQ274XX_CONTROL_SHUTDOWN_ENABLE);
if (ret < 0) {
LOG_ERR("Unable to enable shutdown mode");
return ret;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_CONTROL_SHUTDOWN);
ret = control_reg_write(dev, BQ274XX_CONTROL_SHUTDOWN);
if (ret < 0) {
LOG_ERR("Unable to enter shutdown mode");
return ret;
}
ret = bq274xx_control_reg_write(dev, BQ274XX_CONTROL_SEALED);
ret = control_reg_write(dev, BQ274XX_CONTROL_SEALED);
if (ret < 0) {
LOG_ERR("Failed to seal the gauge");
return ret;
@ -698,7 +698,7 @@ static int bq274xx_enter_shutdown_mode(const struct device *dev)
return 0;
}
static int bq274xx_exit_shutdown_mode(const struct device *dev)
static int exit_shutdown_mode(const struct device *dev)
{
const struct bq274xx_config *const config = dev->config;
int ret = 0;
@ -727,7 +727,7 @@ static int bq274xx_exit_shutdown_mode(const struct device *dev)
if (!config->lazy_loading) {
k_msleep(INIT_TIME);
ret = bq274xx_gauge_configure(dev);
ret = gauge_configure(dev);
if (ret < 0) {
LOG_ERR("Unable to configure bq274xx gauge");
return ret;
@ -737,17 +737,17 @@ static int bq274xx_exit_shutdown_mode(const struct device *dev)
return 0;
}
static int bq274xx_pm_action(const struct device *dev,
static int pm_action(const struct device *dev,
enum pm_device_action action)
{
int ret;
switch (action) {
case PM_DEVICE_ACTION_TURN_OFF:
ret = bq274xx_enter_shutdown_mode(dev);
ret = enter_shutdown_mode(dev);
break;
case PM_DEVICE_ACTION_RESUME:
ret = bq274xx_exit_shutdown_mode(dev);
ret = exit_shutdown_mode(dev);
break;
default:
ret = -ENOTSUP;
@ -759,8 +759,8 @@ static int bq274xx_pm_action(const struct device *dev,
#endif /* CONFIG_BQ274XX_PM */
static const struct sensor_driver_api bq274xx_battery_driver_api = {
.sample_fetch = bq274xx_sample_fetch,
.channel_get = bq274xx_channel_get,
.sample_fetch = sample_fetch,
.channel_get = channel_get,
#ifdef CONFIG_BQ274XX_TRIGGER
.trigger_set = bq274xx_trigger_set,
#endif
@ -769,12 +769,12 @@ static const struct sensor_driver_api bq274xx_battery_driver_api = {
#if defined(CONFIG_BQ274XX_PM) || defined(CONFIG_BQ274XX_TRIGGER)
#define BQ274XX_INT_CFG(index) \
.int_gpios = GPIO_DT_SPEC_INST_GET(index, int_gpios),
#define PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action) \
PM_DEVICE_DT_INST_DEFINE(index, bq274xx_pm_action)
#define PM_BQ274XX_DT_INST_DEFINE(index, pm_action) \
PM_DEVICE_DT_INST_DEFINE(index, pm_action)
#define PM_BQ274XX_DT_INST_GET(index) PM_DEVICE_DT_INST_GET(index)
#else
#define BQ274XX_INT_CFG(index)
#define PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action)
#define PM_BQ274XX_DT_INST_DEFINE(index, pm_action)
#define PM_BQ274XX_DT_INST_GET(index) NULL
#endif
@ -791,9 +791,9 @@ static const struct sensor_driver_api bq274xx_battery_driver_api = {
.lazy_loading = DT_INST_PROP(index, zephyr_lazy_load), \
}; \
\
PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action); \
PM_BQ274XX_DT_INST_DEFINE(index, pm_action); \
\
SENSOR_DEVICE_DT_INST_DEFINE(index, &bq274xx_gauge_init, \
SENSOR_DEVICE_DT_INST_DEFINE(index, &gauge_init, \
PM_BQ274XX_DT_INST_GET(index), \
&bq274xx_driver_##index, \
&bq274xx_config_##index, POST_KERNEL, \

View file

@ -18,7 +18,7 @@
LOG_MODULE_DECLARE(bq274xx, CONFIG_SENSOR_LOG_LEVEL);
static void bq274xx_handle_interrupts(const struct device *dev)
static void handle_interrupts(const struct device *dev)
{
struct bq274xx_data *data = dev->data;
@ -31,25 +31,25 @@ static void bq274xx_handle_interrupts(const struct device *dev)
static K_KERNEL_STACK_DEFINE(bq274xx_thread_stack, CONFIG_BQ274XX_THREAD_STACK_SIZE);
static struct k_thread bq274xx_thread;
static void bq274xx_thread_main(struct bq274xx_data *data)
static void thread_main(struct bq274xx_data *data)
{
while (1) {
k_sem_take(&data->sem, K_FOREVER);
bq274xx_handle_interrupts(data->dev);
handle_interrupts(data->dev);
}
}
#endif
#ifdef CONFIG_BQ274XX_TRIGGER_GLOBAL_THREAD
static void bq274xx_work_handler(struct k_work *work)
static void work_handler(struct k_work *work)
{
struct bq274xx_data *data = CONTAINER_OF(work, struct bq274xx_data, work);
bq274xx_handle_interrupts(data->dev);
handle_interrupts(data->dev);
}
#endif
static void bq274xx_ready_callback_handler(const struct device *port,
static void ready_callback_handler(const struct device *port,
struct gpio_callback *cb,
gpio_port_pins_t pins)
{
@ -78,12 +78,12 @@ int bq274xx_trigger_mode_init(const struct device *dev)
k_thread_create(&bq274xx_thread, bq274xx_thread_stack,
CONFIG_BQ274XX_THREAD_STACK_SIZE,
(k_thread_entry_t)bq274xx_thread_main,
(k_thread_entry_t)thread_main,
data, NULL, NULL,
K_PRIO_COOP(CONFIG_BQ274XX_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_BQ274XX_TRIGGER_GLOBAL_THREAD)
k_work_init(&data->work, bq274xx_work_handler);
k_work_init(&data->work, work_handler);
#endif
ret = gpio_pin_configure_dt(&config->int_gpios, GPIO_INPUT);
@ -92,7 +92,7 @@ int bq274xx_trigger_mode_init(const struct device *dev)
return ret;
}
gpio_init_callback(&data->ready_callback,
bq274xx_ready_callback_handler,
ready_callback_handler,
BIT(config->int_gpios.pin));
return 0;