drivers: charger: charger_max20335: handle minimum system voltage
Allow to configure minimum system voltage threshold parameter. Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
This commit is contained in:
parent
e43f6f5d2a
commit
f1b35a5c78
4 changed files with 59 additions and 0 deletions
|
@ -96,6 +96,7 @@ Drivers and Sensors
|
||||||
* Charger
|
* Charger
|
||||||
|
|
||||||
* Added ``chgin-to-sys-current-limit-microamp`` property to ``maxim,max20335-charger``.
|
* Added ``chgin-to-sys-current-limit-microamp`` property to ``maxim,max20335-charger``.
|
||||||
|
* Added ``system-voltage-min-threshold-microvolt`` property to ``maxim,max20335-charger``.
|
||||||
|
|
||||||
* Clock control
|
* Clock control
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(max20335_charger);
|
||||||
#define MAX20335_INTA_USBOK_MASK BIT(3)
|
#define MAX20335_INTA_USBOK_MASK BIT(3)
|
||||||
#define MAX20335_INTA_CHGSTAT_MASK BIT(6)
|
#define MAX20335_INTA_CHGSTAT_MASK BIT(6)
|
||||||
#define MAX20335_ILIMCNTL_ILIMCNTL_MASK GENMASK(1, 0)
|
#define MAX20335_ILIMCNTL_ILIMCNTL_MASK GENMASK(1, 0)
|
||||||
|
#define MAX20335_ILIMCNTL_SYSMIN_MASK GENMASK(7, 5)
|
||||||
#define MAX20335_STATUSA_CHGSTAT_MASK GENMASK(2, 0)
|
#define MAX20335_STATUSA_CHGSTAT_MASK GENMASK(2, 0)
|
||||||
#define MAX20335_STATUSB_USBOK_MASK BIT(3)
|
#define MAX20335_STATUSB_USBOK_MASK BIT(3)
|
||||||
#define MAX20335_CHGCNTLA_BATREG_MASK GENMASK(4, 1)
|
#define MAX20335_CHGCNTLA_BATREG_MASK GENMASK(4, 1)
|
||||||
|
@ -40,6 +41,11 @@ LOG_MODULE_REGISTER(max20335_charger);
|
||||||
#define MAX20335_REG_CVC_VREG_MIN_IDX 0x0U
|
#define MAX20335_REG_CVC_VREG_MIN_IDX 0x0U
|
||||||
#define MAX20335_REG_CVC_VREG_MAX_IDX 0x0BU
|
#define MAX20335_REG_CVC_VREG_MAX_IDX 0x0BU
|
||||||
|
|
||||||
|
#define MAX20335_ILIMCNTL_SYSMIN_MIN_UV 3600000U
|
||||||
|
#define MAX20335_ILIMCNTL_SYSMIN_STEP_UV 100000U
|
||||||
|
#define MAX20335_ILIMCNTL_SYSMIN_MIN_IDX 0x0U
|
||||||
|
#define MAX20335_ILIMCNTL_SYSMIN_MAX_IDX 0x7U
|
||||||
|
|
||||||
#define INT_ENABLE_DELAY K_MSEC(500)
|
#define INT_ENABLE_DELAY K_MSEC(500)
|
||||||
|
|
||||||
struct charger_max20335_config {
|
struct charger_max20335_config {
|
||||||
|
@ -47,6 +53,7 @@ struct charger_max20335_config {
|
||||||
struct gpio_dt_spec int_gpio;
|
struct gpio_dt_spec int_gpio;
|
||||||
uint32_t max_vreg_uv;
|
uint32_t max_vreg_uv;
|
||||||
uint32_t max_ichgin_to_sys_ua;
|
uint32_t max_ichgin_to_sys_ua;
|
||||||
|
uint32_t min_vsys_uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct charger_max20335_data {
|
struct charger_max20335_data {
|
||||||
|
@ -68,6 +75,12 @@ static const struct linear_range charger_uv_range =
|
||||||
MAX20335_REG_CVC_VREG_MIN_IDX,
|
MAX20335_REG_CVC_VREG_MIN_IDX,
|
||||||
MAX20335_REG_CVC_VREG_MAX_IDX);
|
MAX20335_REG_CVC_VREG_MAX_IDX);
|
||||||
|
|
||||||
|
static const struct linear_range system_uv_range =
|
||||||
|
LINEAR_RANGE_INIT(MAX20335_ILIMCNTL_SYSMIN_MIN_UV,
|
||||||
|
MAX20335_ILIMCNTL_SYSMIN_STEP_UV,
|
||||||
|
MAX20335_ILIMCNTL_SYSMIN_MIN_IDX,
|
||||||
|
MAX20335_ILIMCNTL_SYSMIN_MAX_IDX);
|
||||||
|
|
||||||
static int max20335_get_charger_status(const struct device *dev, enum charger_status *status)
|
static int max20335_get_charger_status(const struct device *dev, enum charger_status *status)
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
|
@ -199,6 +212,26 @@ static int max20335_set_chgin_to_sys_current_limit(const struct device *dev, uin
|
||||||
val);
|
val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int max20335_set_sys_voltage_min_threshold(const struct device *dev, uint32_t voltage_uv)
|
||||||
|
{
|
||||||
|
const struct charger_max20335_config *const config = dev->config;
|
||||||
|
uint16_t idx;
|
||||||
|
uint8_t val;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = linear_range_get_index(&system_uv_range, voltage_uv, &idx);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = FIELD_PREP(MAX20335_ILIMCNTL_SYSMIN_MASK, idx);
|
||||||
|
|
||||||
|
return i2c_reg_update_byte_dt(&config->bus,
|
||||||
|
MAX20335_REG_ILIMCNTL,
|
||||||
|
MAX20335_ILIMCNTL_SYSMIN_MASK,
|
||||||
|
val);
|
||||||
|
}
|
||||||
|
|
||||||
static int max20335_set_enabled(const struct device *dev, bool enable)
|
static int max20335_set_enabled(const struct device *dev, bool enable)
|
||||||
{
|
{
|
||||||
struct charger_max20335_data *data = dev->data;
|
struct charger_max20335_data *data = dev->data;
|
||||||
|
@ -288,6 +321,12 @@ static int max20335_update_properties(const struct device *dev)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = max20335_set_sys_voltage_min_threshold(dev, config->min_vsys_uv);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_ERR("Failed to set minimum system voltage threshold: %d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ret = max20335_set_constant_charge_voltage(dev, data->charge_voltage_uv);
|
ret = max20335_set_constant_charge_voltage(dev, data->charge_voltage_uv);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERR("Failed to set charge voltage: %d", ret);
|
LOG_ERR("Failed to set charge voltage: %d", ret);
|
||||||
|
@ -513,6 +552,7 @@ static const struct charger_driver_api max20335_driver_api = {
|
||||||
.int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
|
.int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
|
||||||
.max_vreg_uv = DT_INST_PROP(inst, constant_charge_voltage_max_microvolt), \
|
.max_vreg_uv = DT_INST_PROP(inst, constant_charge_voltage_max_microvolt), \
|
||||||
.max_ichgin_to_sys_ua = DT_INST_PROP(inst, chgin_to_sys_current_limit_microamp),\
|
.max_ichgin_to_sys_ua = DT_INST_PROP(inst, chgin_to_sys_current_limit_microamp),\
|
||||||
|
.min_vsys_uv = DT_INST_PROP(inst, system_voltage_min_threshold_microvolt), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
DEVICE_DT_INST_DEFINE(inst, &max20335_init, NULL, &charger_max20335_data_##inst, \
|
DEVICE_DT_INST_DEFINE(inst, &max20335_init, NULL, &charger_max20335_data_##inst, \
|
||||||
|
|
|
@ -36,6 +36,23 @@ properties:
|
||||||
CHGIN to SYS path current limitter configuration.
|
CHGIN to SYS path current limitter configuration.
|
||||||
Refer to ILimCntl register description for details.
|
Refer to ILimCntl register description for details.
|
||||||
|
|
||||||
|
system-voltage-min-threshold-microvolt:
|
||||||
|
type: int
|
||||||
|
required: true
|
||||||
|
enum:
|
||||||
|
- 3600000
|
||||||
|
- 3700000
|
||||||
|
- 3800000
|
||||||
|
- 3900000
|
||||||
|
- 4000000
|
||||||
|
- 4100000
|
||||||
|
- 4200000
|
||||||
|
- 4300000
|
||||||
|
description: |
|
||||||
|
System voltage minimum threshold. When SYS path
|
||||||
|
voltage drops to this level, the charger current
|
||||||
|
is reduced to prevent battery damage.
|
||||||
|
|
||||||
int-gpios:
|
int-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
required: true
|
required: true
|
||||||
|
|
|
@ -26,6 +26,7 @@ max20335@1 {
|
||||||
|
|
||||||
chgin-to-sys-current-limit-microamp = <100000>;
|
chgin-to-sys-current-limit-microamp = <100000>;
|
||||||
constant-charge-voltage-max-microvolt = <4050000>;
|
constant-charge-voltage-max-microvolt = <4050000>;
|
||||||
|
system-voltage-min-threshold-microvolt = <3600000>;
|
||||||
int-gpios = <&test_gpio 0 0>;
|
int-gpios = <&test_gpio 0 0>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue