[PATCH 1/4] power: supply: add support for max77759 fuel gauge
Dimitri Fedrau
dima.fedrau at gmail.com
Mon Dec 2 23:35:56 PST 2024
Hi Antoine,
Am Mon, Dec 02, 2024 at 02:07:15PM +0100 schrieb Thomas Antoine via B4 Relay:
> From: Thomas Antoine <t.antoine at uclouvain.be>
>
> The Maxim max77759 fuel gauge has the same interface as the Maxim max1720x
> except for the non-volatile memory slave address which is not available.
> No slave is available at address 0xb of the i2c bus, which is coherent
> with the following driver from google: line 5836 disables non-volatile
> memory for m5 gauge.
>
> Link: https://android.googlesource.com/kernel/google-modules/bms/+/1a68c36bef474573cc8629cc1d121eb6a81ab68c/max1720x_battery.c
>
> Add support for the max77759 by allowing to use the non-volatile
> memory or not based on the chip. Value for RSense comes from the following
> stock devicetree:
>
> Link: https://android.googlesource.com/kernel/devices/google/gs101/+/33eca36d43da6c2b6a546806eb3e7411bbe6d60d/dts/gs101-raviole-battery.dtsi
>
> Signed-off-by: Thomas Antoine <t.antoine at uclouvain.be>
> ---
> drivers/power/supply/max1720x_battery.c | 71 +++++++++++++++++++++++++++------
> 1 file changed, 59 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/power/supply/max1720x_battery.c b/drivers/power/supply/max1720x_battery.c
> index 33105419e2427bb37963bda9948b647c239f8faa..faf336938dd4306dd2ceeb0a84b90ca80ad41a9f 100644
> --- a/drivers/power/supply/max1720x_battery.c
> +++ b/drivers/power/supply/max1720x_battery.c
> @@ -13,6 +13,7 @@
> #include <linux/nvmem-provider.h>
> #include <linux/power_supply.h>
> #include <linux/regmap.h>
> +#include <linux/types.h>
>
No need to include it, it is done by <linux/i2.c> which includes
<linux/device.h> which includes <linux/types.h>
> #include <linux/unaligned.h>
>
> @@ -39,6 +40,7 @@
> #define MAX172XX_DEV_NAME_TYPE_MASK GENMASK(3, 0)
> #define MAX172XX_DEV_NAME_TYPE_MAX17201 BIT(0)
> #define MAX172XX_DEV_NAME_TYPE_MAX17205 (BIT(0) | BIT(2))
> +#define MAX172XX_DEV_NAME_TYPE_MAX77759 0
> #define MAX172XX_QR_TABLE10 0x22
> #define MAX172XX_BATT 0xDA /* Battery voltage */
> #define MAX172XX_ATAVCAP 0xDF
> @@ -46,6 +48,7 @@
> static const char *const max1720x_manufacturer = "Maxim Integrated";
> static const char *const max17201_model = "MAX17201";
> static const char *const max17205_model = "MAX17205";
> +static const char *const max77759_model = "MAX77759";
>
> struct max1720x_device_info {
> struct regmap *regmap;
> @@ -54,6 +57,21 @@ struct max1720x_device_info {
> int rsense;
> };
>
> +struct chip_data {
> + u16 default_nrsense; /* in regs in 10^-5 */
> + u8 has_nvmem;
> +};
> +
> +static const struct chip_data max1720x_data = {
> + .default_nrsense = 1000,
> + .has_nvmem = 1,
> +};
> +
> +static const struct chip_data max77759_data = {
> + .default_nrsense = 500,
> + .has_nvmem = 0,
> +};
> +
You can get rid of chip_data by reading rsense from DT and moving
has_nvmem to max1720x_device_info. By doing so you don't have to rely on
default values. Either it is specified by DT or by rsense value in
nvmem.
Best regards,
Dimitri Fedrau
More information about the linux-arm-kernel
mailing list