diff --git a/doc/releases/release-notes-3.7.rst b/doc/releases/release-notes-3.7.rst index aeb34b2077..2deafcffde 100644 --- a/doc/releases/release-notes-3.7.rst +++ b/doc/releases/release-notes-3.7.rst @@ -103,6 +103,7 @@ Drivers and Sensors * Added ``chgin-to-sys-current-limit-microamp`` property to ``maxim,max20335-charger``. * Added ``system-voltage-min-threshold-microvolt`` property to ``maxim,max20335-charger``. * Added ``re-charge-threshold-microvolt`` property to ``maxim,max20335-charger``. + * Added ``thermistor-monitoring-mode`` property to ``maxim,max20335-charger``. * Clock control diff --git a/drivers/charger/charger_max20335.c b/drivers/charger/charger_max20335.c index e9dfa65f73..a58da7e573 100644 --- a/drivers/charger/charger_max20335.c +++ b/drivers/charger/charger_max20335.c @@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(max20335_charger); #define MAX20335_REG_INTMASKB 0x08 #define MAX20335_REG_ILIMCNTL 0x09 #define MAX20335_REG_CHGCNTLA 0x0A +#define MAX20335_REG_THRMCFG 0x18 #define MAX20335_INTA_USBOK_MASK BIT(3) #define MAX20335_INTA_CHGSTAT_MASK BIT(6) @@ -36,6 +37,7 @@ LOG_MODULE_REGISTER(max20335_charger); #define MAX20335_CHGCNTLA_BATREG_MASK GENMASK(4, 1) #define MAX20335_CHGCNTLA_CHRGEN_MASK BIT(0) #define MAX20335_CHGCNTLA_CHRGEN BIT(0) +#define MAX20335_THRMCFG_THERMEN_MASK GENMASK(1, 0) #define MAX20335_REG_CVC_VREG_MIN_UV 4050000U #define MAX20335_REG_CVC_VREG_STEP_UV 50000U @@ -49,6 +51,14 @@ LOG_MODULE_REGISTER(max20335_charger); #define INT_ENABLE_DELAY K_MSEC(500) +enum charger_max20335_therm_mode { + MAX20335_THERM_MODE_DISABLED, + MAX20335_THERM_MODE_THERMISTOR, + MAX20335_THERM_MODE_JEITA_1, + MAX20335_THERM_MODE_JEITA_2, + MAX20335_THERM_MODE_UNKNOWN, +}; + struct charger_max20335_config { struct i2c_dt_spec bus; struct gpio_dt_spec int_gpio; @@ -56,6 +66,7 @@ struct charger_max20335_config { uint32_t max_ichgin_to_sys_ua; uint32_t min_vsys_uv; uint32_t recharge_threshold_uv; + char *therm_mon_mode; }; struct charger_max20335_data { @@ -264,6 +275,37 @@ static int max20335_set_sys_voltage_min_threshold(const struct device *dev, uint val); } +static int max20335_set_thermistor_mode(const struct device *dev, + enum charger_max20335_therm_mode mode) +{ + const struct charger_max20335_config *const config = dev->config; + uint8_t val; + + switch (mode) { + case MAX20335_THERM_MODE_DISABLED: + val = 0x00; + break; + case MAX20335_THERM_MODE_THERMISTOR: + val = 0x01; + break; + case MAX20335_THERM_MODE_JEITA_1: + val = 0x02; + break; + case MAX20335_THERM_MODE_JEITA_2: + val = 0x03; + break; + default: + return -ENOTSUP; + }; + + val = FIELD_PREP(MAX20335_THRMCFG_THERMEN_MASK, val); + + return i2c_reg_update_byte_dt(&config->bus, + MAX20335_REG_THRMCFG, + MAX20335_THRMCFG_THERMEN_MASK, + val); +} + static int max20335_set_enabled(const struct device *dev, bool enable) { struct charger_max20335_data *data = dev->data; @@ -341,10 +383,30 @@ static int max20335_init_properties(const struct device *dev) return 0; } +enum charger_max20335_therm_mode max20335_string_to_therm_mode(const char *mode_string) +{ + static const char * const modes[] = { + [MAX20335_THERM_MODE_DISABLED] = "disabled", + [MAX20335_THERM_MODE_THERMISTOR] = "thermistor", + [MAX20335_THERM_MODE_JEITA_1] = "JEITA-1", + [MAX20335_THERM_MODE_JEITA_2] = "JEITA-2", + }; + enum charger_max20335_therm_mode i; + + for (i = MAX20335_THERM_MODE_DISABLED; i < ARRAY_SIZE(modes); i++) { + if (strncmp(mode_string, modes[i], strlen(modes[i])) == 0) { + return i; + } + } + + return MAX20335_THERM_MODE_UNKNOWN; +} + static int max20335_update_properties(const struct device *dev) { struct charger_max20335_data *data = dev->data; const struct charger_max20335_config *config = dev->config; + enum charger_max20335_therm_mode therm_mode; int ret; ret = max20335_set_chgin_to_sys_current_limit(dev, config->max_ichgin_to_sys_ua); @@ -365,6 +427,13 @@ static int max20335_update_properties(const struct device *dev) return ret; } + therm_mode = max20335_string_to_therm_mode(config->therm_mon_mode); + ret = max20335_set_thermistor_mode(dev, therm_mode); + if (ret < 0) { + LOG_ERR("Failed to set thermistor mode: %d", ret); + return ret; + } + ret = max20335_set_constant_charge_voltage(dev, data->charge_voltage_uv); if (ret < 0) { LOG_ERR("Failed to set charge voltage: %d", ret); @@ -592,6 +661,7 @@ static const struct charger_driver_api max20335_driver_api = { .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), \ .recharge_threshold_uv = DT_INST_PROP(inst, re_charge_threshold_microvolt), \ + .therm_mon_mode = DT_INST_PROP(inst, thermistor_monitoring_mode), \ }; \ \ DEVICE_DT_INST_DEFINE(inst, &max20335_init, NULL, &charger_max20335_data_##inst, \ diff --git a/dts/bindings/charger/maxim,max20335-charger.yaml b/dts/bindings/charger/maxim,max20335-charger.yaml index a52c29a6a0..3fe44c9290 100644 --- a/dts/bindings/charger/maxim,max20335-charger.yaml +++ b/dts/bindings/charger/maxim,max20335-charger.yaml @@ -65,6 +65,18 @@ properties: Recharge threshold in relation to BatReg. Refer to ChgCntlA register description for details. + thermistor-monitoring-mode: + type: string + required: true + enum: + - "disabled" + - "thermistor" + - "JEITA-1" + - "JEITA-2" + description: | + Thermistor monitoring mode. + Refer to ThrmCfg register description and Table 2 for details. + int-gpios: type: phandle-array required: true diff --git a/tests/drivers/build_all/charger/i2c.dtsi b/tests/drivers/build_all/charger/i2c.dtsi index 2f68f1d403..29187ccd37 100644 --- a/tests/drivers/build_all/charger/i2c.dtsi +++ b/tests/drivers/build_all/charger/i2c.dtsi @@ -28,6 +28,7 @@ max20335@1 { constant-charge-voltage-max-microvolt = <4050000>; system-voltage-min-threshold-microvolt = <3600000>; re-charge-threshold-microvolt = <170000>; + thermistor-monitoring-mode = "JEITA-2"; int-gpios = <&test_gpio 0 0>; }; };