drivers: charger: Adds charge_enable handler

Adds a charge_enable handler to facilitate enabling and disabling
a charge cycle. This deprecates enabling and disable the charge
cycle via the CHARGER_PROP_STATUS property.

Signed-off-by: Ricardo Rivera-Matos <ricardo.rivera-matos@cirrus.com>
This commit is contained in:
Ricardo Rivera-Matos 2023-12-04 16:55:29 -06:00 committed by Maureen Helm
parent a451db4981
commit d4ed6bacf0
4 changed files with 43 additions and 1 deletions

View File

@ -8,6 +8,11 @@ The charger subsystem exposes an API to uniformly access battery charger devices
Basic Operation Basic Operation
*************** ***************
Initiating a Charge Cycle
=========================
A charge cycle is initiated or terminated using :c:func:`charger_charge_enable`.
Properties Properties
========== ==========

View File

@ -36,3 +36,12 @@ static inline int z_vrfy_charger_set_prop(const struct device *dev, const charge
} }
#include <syscalls/charger_set_prop_mrsh.c> #include <syscalls/charger_set_prop_mrsh.c>
static inline int z_vrfy_charger_charge_enable(const struct device *dev, const bool enable)
{
K_OOPS(K_SYSCALL_DRIVER_CHARGER(dev, charge_enable));
return z_impl_charger_charge_enable(dev, enable);
}
#include <syscalls/charger_charge_enable_mrsh.c>

View File

@ -220,6 +220,14 @@ typedef int (*charger_get_property_t)(const struct device *dev, const charger_pr
typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop, typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop,
const union charger_propval *val); const union charger_propval *val);
/**
* @typedef charger_charge_enable_t
* @brief Callback API enabling or disabling a charge cycle.
*
* See charger_charge_enable() for argument description
*/
typedef int (*charger_charge_enable_t)(const struct device *dev, const bool enable);
/** /**
* @brief Charging device API * @brief Charging device API
* *
@ -228,6 +236,7 @@ typedef int (*charger_set_property_t)(const struct device *dev, const charger_pr
__subsystem struct charger_driver_api { __subsystem struct charger_driver_api {
charger_get_property_t get_property; charger_get_property_t get_property;
charger_set_property_t set_property; charger_set_property_t set_property;
charger_charge_enable_t charge_enable;
}; };
/** /**
@ -272,6 +281,25 @@ static inline int z_impl_charger_set_prop(const struct device *dev, const charge
return api->set_property(dev, prop, val); return api->set_property(dev, prop, val);
} }
/**
* @brief Enable or disable a charge cycle
*
* @param dev Pointer to the battery charger device
* @param enable true enables a charge cycle, false disables a charge cycle
*
* @retval 0 if successful
* @retval -EIO if communication with the charger failed
* @retval -EINVAL if the conditions for initiating charging are invalid
*/
__syscall int charger_charge_enable(const struct device *dev, const bool enable);
static inline int z_impl_charger_charge_enable(const struct device *dev, const bool enable)
{
const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
return api->charge_enable(dev, enable);
}
/** /**
* @} * @}
*/ */

View File

@ -45,7 +45,7 @@ int main(void)
val.status = CHARGER_STATUS_CHARGING; val.status = CHARGER_STATUS_CHARGING;
ret = charger_set_prop(chgdev, CHARGER_PROP_STATUS, &val); ret = charger_charge_enable(chgdev, true);
if (ret == -ENOTSUP) { if (ret == -ENOTSUP) {
printk("Enabling charge not supported, assuming auto charge enable\n"); printk("Enabling charge not supported, assuming auto charge enable\n");
continue; continue;