Hi,
This series cleans up the generic ADC battery driver and adds
devicetree support. The plan is to use the driver to add upstream
support for a handheld thermal camera.
Instead of reading and exposing the monitored battery data manually
I started the series with an addition to the power-supply core,
which allows automatic handling of the static battery information.
It simplifies the generic-adc-battery driver a lot and should also
be useful for other battery drivers.
-- Sebastian
Sebastian Reichel (11):
dt-bindings: power: supply: adc-battery: add binding
power: supply: core: auto-exposure of simple-battery data
power: supply: generic-adc-battery: convert to managed resources
power: supply: generic-adc-battery: fix unit scaling
power: supply: generic-adc-battery: drop jitter delay support
power: supply: generic-adc-battery: drop charge now support
power: supply: generic-adc-battery: drop memory alloc error message
power: supply: generic-adc-battery: use simple-battery API
power: supply: generic-adc-battery: simplify read_channel logic
power: supply: generic-adc-battery: add DT support
power: supply: generic-adc-battery: update copyright info
.../bindings/power/supply/adc-battery.yaml | 67 ++++++
drivers/power/supply/generic-adc-battery.c | 221 +++++-------------
drivers/power/supply/power_supply_core.c | 153 ++++++++++--
drivers/power/supply/power_supply_sysfs.c | 16 ++
include/linux/power/generic-adc-battery.h | 23 --
include/linux/power_supply.h | 31 +++
6 files changed, 301 insertions(+), 210 deletions(-)
create mode 100644 Documentation/devicetree/bindings/power/supply/adc-battery.yaml
delete mode 100644 include/linux/power/generic-adc-battery.h
--
2.39.2
Use standard simple-battery API for constant battery
information like min and max voltage. This simplifies
the driver a lot and brings automatic support for DT.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 65 ++--------------------
include/linux/power/generic-adc-battery.h | 18 ------
2 files changed, 5 insertions(+), 78 deletions(-)
delete mode 100644 include/linux/power/generic-adc-battery.h
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 771e5cfc49c3..fc6fcfda1ef2 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -22,7 +22,6 @@
#include <linux/slab.h>
#include <linux/iio/consumer.h>
#include <linux/iio/types.h>
-#include <linux/power/generic-adc-battery.h>
#include <linux/devm-helpers.h>
#define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -48,9 +47,7 @@ struct gab {
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
- struct gab_platform_data *pdata;
struct delayed_work bat_work;
- int level;
int status;
bool cable_plugged;
struct gpio_desc *charge_finished;
@@ -70,14 +67,6 @@ static void gab_ext_power_changed(struct power_supply *psy)
static const enum power_supply_property gab_props[] = {
POWER_SUPPLY_PROP_STATUS,
- POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
- POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
- POWER_SUPPLY_PROP_VOLTAGE_NOW,
- POWER_SUPPLY_PROP_CURRENT_NOW,
- POWER_SUPPLY_PROP_TECHNOLOGY,
- POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
- POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
- POWER_SUPPLY_PROP_MODEL_NAME,
};
/*
@@ -97,17 +86,6 @@ static bool gab_charge_finished(struct gab *adc_bat)
return gpiod_get_value(adc_bat->charge_finished);
}
-static int gab_get_status(struct gab *adc_bat)
-{
- struct gab_platform_data *pdata = adc_bat->pdata;
- struct power_supply_info *bat_info;
-
- bat_info = &pdata->battery_info;
- if (adc_bat->level == bat_info->charge_full_design)
- return POWER_SUPPLY_STATUS_FULL;
- return adc_bat->status;
-}
-
static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
{
switch (psp) {
@@ -144,27 +122,12 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
static int gab_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
- struct gab *adc_bat;
- struct gab_platform_data *pdata;
- struct power_supply_info *bat_info;
- int result = 0;
- int ret = 0;
-
- adc_bat = to_generic_bat(psy);
- if (!adc_bat) {
- dev_err(&psy->dev, "no battery infos ?!\n");
- return -EINVAL;
- }
- pdata = adc_bat->pdata;
- bat_info = &pdata->battery_info;
+ struct gab *adc_bat = to_generic_bat(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
- val->intval = gab_get_status(adc_bat);
- break;
- case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
- val->intval = 0;
- break;
+ val->intval = adc_bat->status;
+ return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_POWER_NOW:
@@ -173,26 +136,9 @@ static int gab_get_property(struct power_supply *psy,
goto err;
val->intval = result;
break;
- case POWER_SUPPLY_PROP_TECHNOLOGY:
- val->intval = bat_info->technology;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
- val->intval = bat_info->voltage_min_design;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
- val->intval = bat_info->voltage_max_design;
- break;
- case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
- val->intval = bat_info->charge_full_design;
- break;
- case POWER_SUPPLY_PROP_MODEL_NAME:
- val->strval = bat_info->name;
- break;
default:
return -EINVAL;
}
-err:
- return ret;
}
static void gab_work(struct work_struct *work)
@@ -235,7 +181,6 @@ static int gab_probe(struct platform_device *pdev)
struct gab *adc_bat;
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
- struct gab_platform_data *pdata = pdev->dev.platform_data;
enum power_supply_property *properties;
int ret = 0;
int chan;
@@ -248,7 +193,7 @@ static int gab_probe(struct platform_device *pdev)
psy_cfg.drv_data = adc_bat;
psy_desc = &adc_bat->psy_desc;
- psy_desc->name = pdata->battery_info.name;
+ psy_desc->name = dev_name(&pdev->dev);
/* bootup default values for the battery */
adc_bat->cable_plugged = false;
@@ -256,7 +201,6 @@ static int gab_probe(struct platform_device *pdev)
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->get_property = gab_get_property;
psy_desc->external_power_changed = gab_ext_power_changed;
- adc_bat->pdata = pdata;
/*
* copying the static properties and allocating extra memory for holding
@@ -309,6 +253,7 @@ static int gab_probe(struct platform_device *pdev)
*/
psy_desc->properties = properties;
psy_desc->num_properties = index;
+ psy_desc->expose_battery_info = true;
adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
if (IS_ERR(adc_bat->psy))
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
deleted file mode 100644
index 54434e4304d3..000000000000
--- a/include/linux/power/generic-adc-battery.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2012, Anish Kumar <[email protected]>
- */
-
-#ifndef GENERIC_ADC_BATTERY_H
-#define GENERIC_ADC_BATTERY_H
-
-/**
- * struct gab_platform_data - platform_data for generic adc iio battery driver.
- * @battery_info: recommended structure to specify static power supply
- * parameters
- */
-struct gab_platform_data {
- struct power_supply_info battery_info;
-};
-
-#endif /* GENERIC_ADC_BATTERY_H */
--
2.39.2
Drop CHARGE_NOW support, which requires a platform specific
calculation method.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 4 ----
include/linux/power/generic-adc-battery.h | 2 --
2 files changed, 6 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index e20894460d7f..d07eeb7d46d3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -72,7 +72,6 @@ static const enum power_supply_property gab_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
- POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -166,9 +165,6 @@ static int gab_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
val->intval = 0;
break;
- case POWER_SUPPLY_PROP_CHARGE_NOW:
- val->intval = pdata->cal_charge(result);
- break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_POWER_NOW:
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index 50eb4bf28286..54434e4304d3 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -10,11 +10,9 @@
* struct gab_platform_data - platform_data for generic adc iio battery driver.
* @battery_info: recommended structure to specify static power supply
* parameters
- * @cal_charge: calculate charge level.
*/
struct gab_platform_data {
struct power_supply_info battery_info;
- int (*cal_charge)(long value);
};
#endif /* GENERIC_ADC_BATTERY_H */
--
2.39.2
Drop support for configuring IRQ jitter delay by using big
enough fixed value.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 13 ++++---------
include/linux/power/generic-adc-battery.h | 3 ---
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 535972a332b3..e20894460d7f 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -227,12 +227,10 @@ static void gab_work(struct work_struct *work)
static irqreturn_t gab_charged(int irq, void *dev_id)
{
struct gab *adc_bat = dev_id;
- struct gab_platform_data *pdata = adc_bat->pdata;
- int delay;
- delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
schedule_delayed_work(&adc_bat->bat_work,
- msecs_to_jiffies(delay));
+ msecs_to_jiffies(JITTER_DEFAULT));
+
return IRQ_HANDLED;
}
@@ -358,14 +356,11 @@ static int __maybe_unused gab_suspend(struct device *dev)
static int __maybe_unused gab_resume(struct device *dev)
{
struct gab *adc_bat = dev_get_drvdata(dev);
- struct gab_platform_data *pdata = adc_bat->pdata;
- int delay;
-
- delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT;
/* Schedule timer to check current status */
schedule_delayed_work(&adc_bat->bat_work,
- msecs_to_jiffies(delay));
+ msecs_to_jiffies(JITTER_DEFAULT));
+
return 0;
}
diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h
index c68cbf34cd34..50eb4bf28286 100644
--- a/include/linux/power/generic-adc-battery.h
+++ b/include/linux/power/generic-adc-battery.h
@@ -11,13 +11,10 @@
* @battery_info: recommended structure to specify static power supply
* parameters
* @cal_charge: calculate charge level.
- * @jitter_delay: delay required after the interrupt to check battery
- * status.Default set is 10ms.
*/
struct gab_platform_data {
struct power_supply_info battery_info;
int (*cal_charge)(long value);
- int jitter_delay;
};
#endif /* GENERIC_ADC_BATTERY_H */
--
2.39.2
Drop mostly useless gab_prop_to_chan() function by directly
supplying the correct enum value to read_channel().
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 31 ++++------------------
1 file changed, 5 insertions(+), 26 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index fc6fcfda1ef2..7bc54566664f 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat)
return gpiod_get_value(adc_bat->charge_finished);
}
-static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
-{
- switch (psp) {
- case POWER_SUPPLY_PROP_POWER_NOW:
- return GAB_POWER;
- case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- return GAB_VOLTAGE;
- case POWER_SUPPLY_PROP_CURRENT_NOW:
- return GAB_CURRENT;
- default:
- WARN_ON(1);
- break;
- }
- return GAB_POWER;
-}
-
-static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
+static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
int *result)
{
int ret;
- int chan_index;
- chan_index = gab_prop_to_chan(psp);
- ret = iio_read_channel_processed(adc_bat->channel[chan_index],
- result);
+ ret = iio_read_channel_processed(adc_bat->channel[channel], result);
if (ret < 0)
pr_err("read channel error\n");
else
@@ -129,13 +110,11 @@ static int gab_get_property(struct power_supply *psy,
val->intval = adc_bat->status;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+ return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
+ return read_channel(adc_bat, GAB_CURRENT, &val->intval);
case POWER_SUPPLY_PROP_POWER_NOW:
- ret = read_channel(adc_bat, psp, &result);
- if (ret < 0)
- goto err;
- val->intval = result;
- break;
+ return read_channel(adc_bat, GAB_POWER, &val->intval);
default:
return -EINVAL;
}
--
2.39.2
jz4740-battery.c and s3c_adc_battery.c have been removed
from the tree and after all of my restructuring the driver
is basically no longer based on them.
Thus update the copyright information and switch to SPDX
license identifier while being at it.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 436e75d226ed..ac72140dc136 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -1,13 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
/*
- * Generic battery driver code using IIO
+ * Generic battery driver using IIO
* Copyright (C) 2012, Anish Kumar <[email protected]>
- * based on jz4740-battery.c
- * based on s3c_adc_battery.c
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License. See the file COPYING in the main directory of this archive for
- * more details.
- *
+ * Copyright (c) 2023, Sebastian Reichel <[email protected]>
*/
#include <linux/interrupt.h>
#include <linux/platform_device.h>
--
2.39.2
Error printing happens automatically for memory allocation problems.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index d07eeb7d46d3..771e5cfc49c3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -243,10 +243,8 @@ static int gab_probe(struct platform_device *pdev)
bool any = false;
adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
- if (!adc_bat) {
- dev_err(&pdev->dev, "failed to allocate memory\n");
+ if (!adc_bat)
return -ENOMEM;
- }
psy_cfg.drv_data = adc_bat;
psy_desc = &adc_bat->psy_desc;
--
2.39.2
This adds full DT support to the driver. Because of the previous
changes just adding a compatible value is enough.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/power/supply/generic-adc-battery.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 7bc54566664f..436e75d226ed 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/iio/consumer.h>
#include <linux/iio/types.h>
+#include <linux/of.h>
#include <linux/devm-helpers.h>
#define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -170,6 +171,7 @@ static int gab_probe(struct platform_device *pdev)
if (!adc_bat)
return -ENOMEM;
+ psy_cfg.of_node = pdev->dev.of_node;
psy_cfg.drv_data = adc_bat;
psy_desc = &adc_bat->psy_desc;
psy_desc->name = dev_name(&pdev->dev);
@@ -284,10 +286,17 @@ static int __maybe_unused gab_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(gab_pm_ops, gab_suspend, gab_resume);
+static const struct of_device_id gab_match[] = {
+ { .compatible = "adc-battery" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, gab_match);
+
static struct platform_driver gab_driver = {
.driver = {
.name = "generic-adc-battery",
.pm = &gab_pm_ops,
+ .of_match_table = gab_match,
},
.probe = gab_probe,
};
--
2.39.2
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> Drop support for configuring IRQ jitter delay by using big
> enough fixed value.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> Drop CHARGE_NOW support, which requires a platform specific
> calculation method.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
I agree. If we want to support this, we should use the generic
methods with interpolation tables defined in DT as well, and it also
ideally requires load compensated resistance calculation to figure
out Ri so this can bring any kind of reasonable precision.
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> Error printing happens automatically for memory allocation problems.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> Use standard simple-battery API for constant battery
> information like min and max voltage. This simplifies
> the driver a lot and brings automatic support for DT.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
That's neat.
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> Drop mostly useless gab_prop_to_chan() function by directly
> supplying the correct enum value to read_channel().
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Looks correct.
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> This adds full DT support to the driver. Because of the previous
> changes just adding a compatible value is enough.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> jz4740-battery.c and s3c_adc_battery.c have been removed
> from the tree and after all of my restructuring the driver
> is basically no longer based on them.
>
> Thus update the copyright information and switch to SPDX
> license identifier while being at it.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
Hi dee Ho all,
On 3/10/23 10:29, Linus Walleij wrote:
> On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
>
>> Drop CHARGE_NOW support, which requires a platform specific
>> calculation method.
>>
>> Signed-off-by: Sebastian Reichel <[email protected]>
>
> I agree. If we want to support this, we should use the generic
> methods with interpolation tables defined in DT as well, and it also
> ideally requires load compensated resistance calculation to figure
> out Ri so this can bring any kind of reasonable precision.
I guess you have your reasons, besides you have far better insight to
things than I do - hence I am not really objecting this - just asking a
question ;)
Do we have generic facilities of computing this based on the DT tables /
Ri in place(?) I guess that we do need/see platform specific
implementations as long as there is no generic "de-facto" way of doing
this available...
Well, maybe this helps kicking things to that direction :)
Reviewed-by: Matti Vaittinen <[email protected]>
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
On 3/10/23 00:50, Sebastian Reichel wrote:
> Error printing happens automatically for memory allocation problems.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Matti Vaittinen <[email protected]>
> ---
> drivers/power/supply/generic-adc-battery.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index d07eeb7d46d3..771e5cfc49c3 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -243,10 +243,8 @@ static int gab_probe(struct platform_device *pdev)
> bool any = false;
>
> adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
> - if (!adc_bat) {
> - dev_err(&pdev->dev, "failed to allocate memory\n");
> + if (!adc_bat)
> return -ENOMEM;
> - }
>
> psy_cfg.drv_data = adc_bat;
> psy_desc = &adc_bat->psy_desc;
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
Hi,
Looks good to me.
On 3/10/23 00:50, Sebastian Reichel wrote:
> Drop mostly useless gab_prop_to_chan() function by directly
> supplying the correct enum value to read_channel().
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Matti Vaittinen <[email protected]>
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
On 3/10/23 00:50, Sebastian Reichel wrote:
> This adds full DT support to the driver. Because of the previous
> changes just adding a compatible value is enough.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Matti Vaittinen <[email protected]>
Best Regards,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
On 3/10/23 00:50, Sebastian Reichel wrote:
> jz4740-battery.c and s3c_adc_battery.c have been removed
> from the tree and after all of my restructuring the driver
> is basically no longer based on them.
>
> Thus update the copyright information and switch to SPDX
> license identifier while being at it.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Matti Vaittinen <[email protected]>
> ---
> drivers/power/supply/generic-adc-battery.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index 436e75d226ed..ac72140dc136 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -1,13 +1,8 @@
> +// SPDX-License-Identifier: GPL-2.0
> /*
> - * Generic battery driver code using IIO
> + * Generic battery driver using IIO
> * Copyright (C) 2012, Anish Kumar <[email protected]>
> - * based on jz4740-battery.c
> - * based on s3c_adc_battery.c
> - *
> - * This file is subject to the terms and conditions of the GNU General Public
> - * License. See the file COPYING in the main directory of this archive for
> - * more details.
> - *
> + * Copyright (c) 2023, Sebastian Reichel <[email protected]>
> */
> #include <linux/interrupt.h>
> #include <linux/platform_device.h>
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
On Mon, Mar 13, 2023 at 8:49 AM Matti Vaittinen
<[email protected]> wrote:
> On 3/10/23 10:29, Linus Walleij wrote:
> > On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <[email protected]> wrote:
> >
> >> Drop CHARGE_NOW support, which requires a platform specific
> >> calculation method.
> >>
> >> Signed-off-by: Sebastian Reichel <[email protected]>
> >
> > I agree. If we want to support this, we should use the generic
> > methods with interpolation tables defined in DT as well, and it also
> > ideally requires load compensated resistance calculation to figure
> > out Ri so this can bring any kind of reasonable precision.
>
> I guess you have your reasons, besides you have far better insight to
> things than I do - hence I am not really objecting this - just asking a
> question ;)
>
> Do we have generic facilities of computing this based on the DT tables /
> Ri in place(?)
Not yet, for the Samsung batteries I used a static look-up table
derived from the compatible string for calculating Ri from VBAT
and from that calculate the capacity from estimated open
circuit voltage, see
drivers/power/supply/samsung-sdi-battery.c
> I guess that we do need/see platform specific
> implementations as long as there is no generic "de-facto" way of doing
> this available...
The method I used with Samsung batteries is fine as long as all you
need to know to know everything about a battery is the compatible
string. Pretty much any Lion battery with a clearly defined product
name can be done this way.
The only reason to put the interpolation tables into the device
tree would be to support any random battery, such as one
that you do not know the model or this can change.
I am however mildly sceptic about adding that: if you know the
VBAT-to-Ri and OCV-to-capacity tables, you must have a
datasheet, and then you know the name of the battery product
and hence you know the right compatible string...
I think the right way to handle any capacity curves for any battery
would be to create static data like I did for the Samsung batteries.
Yours,
Linus Walleij