From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Zeynep Arslanbenzer <Zeynep.Arslanbenzer@analog.com>,
lee@kernel.org, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, sre@kernel.org,
lgirdwood@gmail.com, broonie@kernel.org
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-pm@vger.kernel.org,
Nurettin Bolucu <Nurettin.Bolucu@analog.com>
Subject: Re: [PATCH v3 5/7] power: supply: max77658: Add ADI MAX77658 Battery Support
Date: Mon, 8 May 2023 21:57:27 +0200 [thread overview]
Message-ID: <04e8e974-c09b-bfcd-85f7-07f9f3fc868c@linaro.org> (raw)
In-Reply-To: <20230508131045.9399-6-Zeynep.Arslanbenzer@analog.com>
On 08/05/2023 15:10, Zeynep Arslanbenzer wrote:
> Battery driver for ADI MAX77658.
>
> The MAX77658 is an ultra-low power fuel gauge which implements the Maxim ModelGauge m5 EZ algorithm.
>
> Signed-off-by: Nurettin Bolucu <Nurettin.Bolucu@analog.com>
> Signed-off-by: Zeynep Arslanbenzer <Zeynep.Arslanbenzer@analog.com>
> ---
> drivers/power/supply/Kconfig | 7 +
> drivers/power/supply/Makefile | 1 +
> drivers/power/supply/max77658-battery.c | 633 ++++++++++++++++++++++++
> 3 files changed, 641 insertions(+)
> create mode 100644 drivers/power/supply/max77658-battery.c
>
> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> index 4b68bbb1e2a8..f9556f4b9e35 100644
> --- a/drivers/power/supply/Kconfig
> +++ b/drivers/power/supply/Kconfig
> @@ -572,6 +572,13 @@ config CHARGER_MAX77658
> Say Y to enable support for the battery charger control of
> MAX77654/58/59 PMIC.
>
> +config BATTERY_MAX77658
> + tristate "Analog Devices MAX77658 battery driver"
> + depends on MFD_MAX77658
> + help
> + Say Y to enable support for the battery control of
> + MAX77658 PMIC.
> +
> config CHARGER_MAX77693
> tristate "Maxim MAX77693 battery charger driver"
> depends on MFD_MAX77693
> diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
> index af4bd6e5969f..e5a425d333a7 100644
> --- a/drivers/power/supply/Makefile
> +++ b/drivers/power/supply/Makefile
> @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o
> obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o
> obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o
> obj-$(CONFIG_CHARGER_MAX77658) += max77658-charger.o
> +obj-$(CONFIG_BATTERY_MAX77658) += max77658-battery.o
> obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o
> obj-$(CONFIG_CHARGER_MAX77976) += max77976_charger.o
> obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
> diff --git a/drivers/power/supply/max77658-battery.c b/drivers/power/supply/max77658-battery.c
> new file mode 100644
> index 000000000000..4948ef227db1
> --- /dev/null
> +++ b/drivers/power/supply/max77658-battery.c
> @@ -0,0 +1,633 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2023 Analog Devices, Inc.
> + * ADI battery driver for the MAX77658
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/delay.h>
> +#include <linux/mfd/max77658.h>
> +#include <linux/module.h>
> +#include <linux/of_irq.h>
> +#include <linux/platform_device.h>
> +#include <linux/power_supply.h>
> +#include <linux/regmap.h>
> +
> +/* Default value for SALRT min threshold, in percent */
> +#define MAX77658_SALRT_MIN_DEFAULT 1
> +/* Default value for SALRT max threshold, in percent */
> +#define MAX77658_SALRT_MAX_DEFAULT 99
> +
> +#define MAX77658_IALRTTH_RESOLUTION 8567
> +#define MAX77658_CURRENT_RESOLUTION 33487
> +#define MAX77658_VOLTAGE_RESOLUTION 78125
> +#define MAX77658_FG_DELAY 1000
> +#define MAX77658_BATTERY_FULL 100
> +#define MAX77658_BATTERY_LOW 40
> +#define MAX77658_BATTERY_CRITICAL 10
> +#define MAX77658_MAXMINVOLT_STEP 20000
> +#define MAX77658_VALRTTH_STEP 20000
> +#define MAX77658_VEMPTY_VE_STEP 10000
> +#define MAX77658_POWER_STEP 17100
> +
> +#define MAX77658_REG_STATUS 0x00
> +#define MAX77658_REG_VALRTTH 0x01
> +#define MAX77658_REG_TALRTTH 0x02
> +#define MAX77658_REG_SALRTTH 0x03
> +#define MAX77658_REG_CONFIG 0x1D
> +#define MAX77658_REG_DEVNAME 0x21
> +#define MAX77658_REG_VEMPTY 0x3A
> +#define MAX77658_REG_AVGPOWER 0xB3
> +#define MAX77658_REG_IALRTTH 0xB4
> +#define MAX77658_REG_CONFIG2 0xBB
> +#define MAX77658_REG_TEMP 0x08
> +#define MAX77658_REG_VCELL 0x09
> +#define MAX77658_REG_CURRENT 0x0A
> +#define MAX77658_REG_AVGCURRENT 0x0B
> +#define MAX77658_REG_AVGVCELL 0x19
> +#define MAX77658_REG_MAXMINTEMP 0x1A
> +#define MAX77658_REG_MAXMINVOLT 0x1B
> +#define MAX77658_REG_MAXMINCURR 0x1C
> +#define MAX77658_REG_REPSOC 0x06
> +#define MAX77658_REG_TTE 0x11
> +#define MAX77658_REG_TTF 0x20
> +
> +#define MAX77658_BIT_STATUS_BR BIT(15)
> +#define MAX77658_BIT_STATUS_SMX BIT(14)
> +#define MAX77658_BIT_STATUS_TMX BIT(13)
> +#define MAX77658_BIT_STATUS_VMX BIT(12)
> +#define MAX77658_BIT_STATUS_BI BIT(11)
> +#define MAX77658_BIT_STATUS_SMN BIT(10)
> +#define MAX77658_BIT_STATUS_TMN BIT(9)
> +#define MAX77658_BIT_STATUS_VMN BIT(8)
> +#define MAX77658_BIT_STATUS_POR BIT(2)
> +#define MAX77658_BIT_CONFIG_AEN BIT(2)
Odd indentation
(...)
> +}
> +
> +static void max77658_fg_parse_dt(struct max77658_fg *max77658_fg)
> +{
> + struct device *dev = max77658_fg->dev;
> + int ret;
> +
> + ret = device_property_read_u32(dev, "adi,valrt-min-microvolt",
> + &max77658_fg->volt_min_uv);
> + if (ret) {
> + dev_dbg(dev,
> + "Could not read adi,valrt-min-microvolt DT property\n");
> + max77658_fg->volt_min_uv = 0;
So you have defaults? DT binding is missing them
> + }
> +
> + ret = device_property_read_u32(dev, "adi,valrt-max-microvolt",
> + &max77658_fg->volt_max_uv);
> + if (ret) {
> + dev_dbg(dev,
> + "Could not read adi,valrt-max-microvolt DT property\n");
> + max77658_fg->volt_max_uv = 5100000;
Ditto
> + }
> +
> + ret = device_property_read_u32(dev, "adi,ialrt-min-microamp",
> + &max77658_fg->curr_min_ma);
> + if (ret) {
> + dev_dbg(dev,
> + "Could not read adi,ialrt-min-microamp DT property\n");
> + max77658_fg->curr_min_ma = MAX77658_IALRTTH_RESOLUTION * (-128);
Ditto
> + }
> +
> + ret = device_property_read_u32(dev, "adi,ialrt-max-microamp",
> + &max77658_fg->curr_max_ma);
> + if (ret) {
> + dev_dbg(dev,
> + "Could not read adi,ialrt-max-microamp DT property\n");
> + max77658_fg->curr_max_ma = MAX77658_IALRTTH_RESOLUTION * 127;
Ditto
> + }
> +}
> +
> +static int max77658_fg_probe(struct platform_device *pdev)
> +{
> + struct max77658_dev *max77658 = dev_get_drvdata(pdev->dev.parent);
> + struct power_supply_battery_info *info;
> + struct power_supply_config fg_cfg = {};
> + struct device *dev = &pdev->dev;
> + struct max77658_fg *fg;
> + int ret = 0;
> +
> + fg = devm_kzalloc(&pdev->dev, sizeof(*fg), GFP_KERNEL);
> + if (!fg)
> + return -ENOMEM;
> +
> + fg->dev = &pdev->dev;
> + fg->regmap = max77658->regmap_fg;
> +
> + fg->psy_batt_d.name = "max77658-battery";
> + fg->psy_batt_d.type = POWER_SUPPLY_TYPE_BATTERY;
> + fg->psy_batt_d.get_property = max77658_fg_get_property;
> + fg->psy_batt_d.set_property = max77658_fg_set_property;
> + fg->psy_batt_d.properties = max77658_fg_battery_props;
> + fg->psy_batt_d.property_is_writeable = max77658_property_is_writeable;
> + fg->psy_batt_d.num_properties = ARRAY_SIZE(max77658_fg_battery_props);
> + fg_cfg.drv_data = fg;
> +
> + INIT_DELAYED_WORK(&fg->work, max77658_fg_work);
> + ret = devm_add_action(&pdev->dev, max77658_stop_work, fg);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Error in setting delayed work\n");
> +
> + fg->battery = devm_power_supply_register(dev, &fg->psy_batt_d,
> + &fg_cfg);
> + if (IS_ERR(fg->battery))
> + return dev_err_probe(&pdev->dev, PTR_ERR(fg->battery),
> + "Failed to register battery\n");
> +
> + fg->battery->of_node = of_get_child_by_name(dev->parent->of_node,
> + "fuel-gauge");
> +
> + if (!fg->battery->of_node)
> + dev_err(dev,
> + "of_get_child_by_name\n");
Same problems a previous patch...
Best regards,
Krzysztof
next prev parent reply other threads:[~2023-05-08 19:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 13:10 [PATCH v3 0/7] Add MAX77643/MAX77654/MAX77658/MAX77659 PMIC Support Zeynep Arslanbenzer
2023-05-08 13:10 ` [PATCH v3 1/7] regulator: max77658: Add ADI MAX77643/54/58/59 Regulator Support Zeynep Arslanbenzer
2023-05-08 13:10 ` [PATCH v3 2/7] dt-bindings: power: supply: max77658: Add ADI MAX77654/58/59 Charger Zeynep Arslanbenzer
2023-05-08 14:32 ` Krzysztof Kozlowski
2023-05-08 14:36 ` Krzysztof Kozlowski
2023-05-08 19:45 ` Krzysztof Kozlowski
2023-05-08 19:55 ` Krzysztof Kozlowski
2023-05-08 13:10 ` [PATCH v3 3/7] power: supply: max77658: Add ADI MAX77654/58/59 Charger Support Zeynep Arslanbenzer
2023-05-08 19:51 ` Krzysztof Kozlowski
2023-05-08 20:22 ` Krzysztof Kozlowski
2023-06-16 10:39 ` Arslanbenzer, Zeynep
2023-05-08 13:10 ` [PATCH v3 4/7] dt-bindings: power: supply: max77658: Add ADI MAX77658 Battery Zeynep Arslanbenzer
2023-05-08 14:31 ` Krzysztof Kozlowski
2023-05-08 19:54 ` Krzysztof Kozlowski
2023-05-08 13:10 ` [PATCH v3 5/7] power: supply: max77658: Add ADI MAX77658 Battery Support Zeynep Arslanbenzer
2023-05-08 19:57 ` Krzysztof Kozlowski [this message]
2023-05-08 20:15 ` Krzysztof Kozlowski
2023-05-08 13:10 ` [PATCH v3 6/7] dt-bindings: mfd: max77658: Add ADI MAX77658 Zeynep Arslanbenzer
2023-05-08 14:31 ` Krzysztof Kozlowski
2023-05-08 20:02 ` Krzysztof Kozlowski
2023-05-08 13:10 ` [PATCH v3 7/7] mfd: max77658: Add ADI MAX77643/54/58/59 MFD Support Zeynep Arslanbenzer
2023-05-08 20:09 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=04e8e974-c09b-bfcd-85f7-07f9f3fc868c@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=Nurettin.Bolucu@analog.com \
--cc=Zeynep.Arslanbenzer@analog.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).