Add LT8491 driver
Subsystems (2)
v3 cover Add LT8491 driver
The LT8491 is a buck-boost switching regulator battery charger that implements a constant-current constant-voltage (CCCV) charging profile.
Changes since v2:
https://lore.kernel.org/all/[email protected]/
- dt-bindings: use unevaluatedProperties: false instead of
additionalProperties: false (Conor Dooley, sashiko-bot).
- driver: drop the <linux/mod_devicetable.h> include and use a named initializer for the i2c_device_id table (Uwe Kleine-König).
- driver: use an int for ret in lt8491_get_property() so readings
Quoted 1 line
=
0x8000are not treated as errors (sashiko-bot).
- driver: register the power supply with devm_power_supply_register() (sashiko-bot).
- driver: poll the telemetry-active bit after triggering a telemetry update (sashiko-bot).
- driver: bounds-check the temperature limits and the resistor configuration values before truncating them into registers (sashiko-bot).
- driver: write the 16-bit resistor configuration registers as two byte writes, as the device has no word-write transaction.
- driver: report current_now in microamps.
- driver: return -ENODATA for the temperature when the chip reports the not-measured-yet (0x7FFF) or thermistor-disconnected (0x7777) values.
- driver: minor cleanups.
Tested on a DC2703A-A-KIT evaluation board with a Raspberry Pi 4B (6.12-based vendor kernel) with no battery connected; charging was not tested, nor were the two special temperature values above. Build-tested against the power-supply for-next tree.
John Erasmus Mari Geronimo (2):
dt-bindings: power: supply: add adi,lt8491.yaml
power: supply: add LT8491 battery charger driver
.../bindings/power/supply/adi,lt8491.yaml | 92 ++++ MAINTAINERS | 7 + drivers/power/supply/Kconfig | 9 + drivers/power/supply/Makefile | 1 + drivers/power/supply/lt8491_charger.c | 428 ++++++++++++++++++ 5 files changed, 537 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml create mode 100644 drivers/power/supply/lt8491_charger.c
base-commit: f0f400459bf6a037e70768de623fff3f8920b8bb
Signature · 1 line
2.34.1
PATCH v3 1/2 dt-bindings: power: supply: add adi,lt8491.yaml
Add the devicetree binding for the Analog Devices LT8491, a high voltage buck-boost battery charge controller with an I2C interface. The values of the PCB resistors used by the chip's telemetry are described as properties.
--- .../bindings/power/supply/adi,lt8491.yaml | 92 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 98 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml
Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml new file +92 -0
@@ -0,0 +1,92 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/adi,lt8491.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology (Analog Devices) LT8491 Battery Charger + +maintainers: + - John Erasmus Mari Geronimo <[email protected]> + +description: | + The LT8491 is a buck-boost switching regulator battery charger that implements + a constant-current constant-voltage (CCCV) charging profile used for most + battery types, including sealed lead-acid (SLA), flooded, gel and lithium-ion. + + Specifications about the charger can be found at: + https://www.analog.com/en/products/lt8491.html + +allOf: + - $ref: power-supply.yaml# + +properties: + compatible: + enum: + - adi,lt8491 + + reg: + maxItems: 1 + + adi,rsense1-micro-ohms: + description: Resistance value of RSENSE1 in micro ohms. + + adi,rimon-out-ohms: + description: Resistance value of RIMON_OUT in ohms. + + adi,rsense2-micro-ohms: + description: Resistance value of RSENSE2 in micro ohms. + + adi,rdaco-ohms: + description: Resistance value of RDACO1 + RDACO2 in ohms. + + adi,rfbout1-ohms: + description: Resistance value of RFBOUT1 in ohms. + + adi,rfbout2-ohms: + description: Resistance value of RFBOUT2 in ohms. + + adi,rdaci-ohms: + description: Resistance value of RDACI1 + RDACI2 in ohms. + + adi,rfbin2-ohms: + description: Resistance value of RFBIN2 in ohms. + + adi,rfbin1-ohms: + description: Resistance value of RFBIN1 in ohms. + +required: + - compatible + - reg + - adi,rsense1-micro-ohms + - adi,rimon-out-ohms + - adi,rsense2-micro-ohms + - adi,rdaco-ohms + - adi,rfbout1-ohms + - adi,rfbout2-ohms + - adi,rdaci-ohms + - adi,rfbin2-ohms + - adi,rfbin1-ohms + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + battery-charger@10 { + compatible = "adi,lt8491"; + reg = <0x10>; + adi,rsense1-micro-ohms = <5000>; + adi,rimon-out-ohms = <124000>; + adi,rsense2-micro-ohms = <3000>; + adi,rdaco-ohms = <64900>; + adi,rfbout1-ohms = <113000>; + adi,rfbout2-ohms = <10000>; + adi,rdaci-ohms = <7000>; + adi,rfbin2-ohms = <3480>; + adi,rfbin1-ohms = <102000>; + }; + };
MAINTAINERS +6 -0
@@ -15466,6 +15466,12 @@ F: Documentation/devicetree/bindings/hwmon/pmbus/adi,lt3074.yaml F: Documentation/hwmon/lt3074.rst F: drivers/hwmon/pmbus/lt3074.c +LT8491 BATTERY CHARGER DRIVER +M: John Erasmus Mari Geronimo <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml + LTC1660 DAC DRIVER M: Marcus Folkesson <[email protected]> L: [email protected]
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] dt-bindings: power: supply: add adi,lt8491.yaml
Quoted 11 lines · John Erasmus Mari Geronimo
Add the devicetree binding for the Analog Devices LT8491, a high voltage buck-boost battery charge controller with an I2C interface. The values of the PCB resistors used by the chip's telemetry are described as properties.
Signed-off-by John Erasmus Mari Geronimo <[email protected]>--- .../bindings/power/supply/adi,lt8491.yaml | 92 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 98 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml
Best regards,
Krzysztof
PATCH v3 2/2 power: supply: add LT8491 battery charger driver
In reply to John Erasmus Mari GeronimoAdd support for the Analog Devices LT8491 buck-boost battery charge controller connected over I2C. The driver registers a power supply exposing the charging status, battery voltage, current, power and temperature, and the battery temperature limits. The PCB resistor values needed by the chip's telemetry are read from the devicetree and written to the chip at probe.
--- MAINTAINERS | 1 + drivers/power/supply/Kconfig | 9 + drivers/power/supply/Makefile | 1 + drivers/power/supply/lt8491_charger.c | 428 ++++++++++++++++++++++++++ 4 files changed, 439 insertions(+) create mode 100644 drivers/power/supply/lt8491_charger.c
MAINTAINERS +1 -0
@@ -15471,6 +15471,7 @@ M: John Erasmus Mari Geronimo <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/power/supply/adi,lt8491.yaml +F: drivers/power/supply/lt8491_charger.c LTC1660 DAC DRIVER M: Marcus Folkesson <[email protected]>
drivers/power/supply/Kconfig +9 -0
@@ -598,6 +598,15 @@ config CHARGER_LT3651 Say Y to include support for the Analog Devices (Linear Technology) LT3651 battery charger which reports its status via GPIO lines. +config CHARGER_LT8491 + tristate "Analog Devices LT8491 charger" + depends on I2C + help + Say Y to include support for the Analog Devices (Linear Technology) + LT8491 battery charge controller connected to I2C. The LT8491 is a + high voltage buck-boost switching regulator battery charger + controller. + config CHARGER_LTC4162L tristate "LTC4162-L charger" depends on I2C
drivers/power/supply/Makefile +1 -0
@@ -81,6 +81,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_LT3651) += lt3651-charger.o +obj-$(CONFIG_CHARGER_LT8491) += lt8491_charger.o obj-$(CONFIG_CHARGER_LTC4162L) += ltc4162-l-charger.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o
drivers/power/supply/lt8491_charger.c new file +428 -0
428 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v3 2/2] power: supply: add LT8491 battery charger driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] power: supply: lt8491: missing psy_cfg.fwnode init in lt8491_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] power: supply: lt8491: missing psy_cfg.fwnode init in lt8491_probe() --
commit 04ac7bfe3dd376e9c91848a21ebd5b60545acb14
Author: John Erasmus Mari Geronimo <[email protected]>
power: supply: add LT8491 battery charger driver
This commit adds a power supply driver for the Analog Devices LT8491 buck-boost battery charge controller over I2C, reading resistor configuration from the devicetree and exposing telemetry and temperature limit properties.
Quoted 5 lines
drivers/power/supply/lt8491_charger.c new file +0
-0
[ ... ]
Quoted 22 lines
drivers/power/supply/lt8491_charger.c new file +22
-0+static int lt8491_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct lt8491_info *info; +struct power_supply_config psy_cfg = {}; +int ret; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_BYTE_DATA | +I2C_FUNC_SMBUS_READ_WORD_DATA )) +return -EOPNOTSUPP ; + + info =devm_kzalloc (dev,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + info->client = client; + psy_cfg.drv_data = info; + + ret =devm_mutex_init (dev, &info->lock); +if (ret) +return ret; +
drivers/power/supply/lt8491_charger.c line 396
Quoted 10 lines
drivers/power/supply/lt8491_charger.c new file +10
-0+ ret =lt8491_read_serial_number (info); +if (ret) +return dev_err_probe (dev, ret, +"Can't read serial. Hardware error.\n" ); + + ret =lt8491_configure_telemetry (info); +if (ret) +return ret; + + info->psp =devm_power_supply_register (dev, <8491_desc, &psy_cfg);
[Severity: Medium]
Should lt8491_probe() also set psy_cfg.fwnode = dev_fwnode(dev) (or psy_cfg.of_node = dev->of_node) before calling devm_power_supply_register()?
In drivers/power/supply/power_supply_core.c, __power_supply_register() sets the power supply device's firmware node from cfg->fwnode:
if (cfg) {
device_set_node(dev, cfg->fwnode);
dev->groups = cfg->attr_grp;
psy->drv_data = cfg->drv_data;
psy->supplied_to = cfg->supplied_to;
psy->num_supplicants = cfg->num_supplicants;
}Leaving psy_cfg.fwnode unset leaves psy->dev.fwnode as NULL, which prevents power_supply_check_supplies() from parsing the power-supplies property and prevents __power_supply_find_supply_from_node() from matching this supply when referenced by phandle in the devicetree.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2