Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1701483 > unrolled thread

[RFC PATCH 0/5] Add formula for LiIon batteries to compute capacity

Started byMarek Belisko <marek.belisko@open-nandra.com>
First post2017-08-01 23:00 +0200
Last post2017-08-01 23:00 +0200
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [RFC PATCH 0/5] Add formula for LiIon batteries to compute capacity Marek Belisko <marek.belisko@open-nandra.com> - 2017-08-01 23:00 +0200
    [RFC PATCH 1/5] dt-bindings: power: Add battery types Marek Belisko <marek.belisko@open-nandra.com> - 2017-08-01 23:00 +0200
      Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types Pavel Machek <pavel@ucw.cz> - 2017-08-02 13:40 +0200
      Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types Belisko Marek <marek.belisko@gmail.com> - 2017-08-02 13:50 +0200
      Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types Pavel Machek <pavel@ucw.cz> - 2017-08-02 13:50 +0200
    [RFC PATCH 4/5] power: Add formula for computing LiIon State of Charge from Voltage Marek Belisko <marek.belisko@open-nandra.com> - 2017-08-01 23:00 +0200

#1701483 — [RFC PATCH 0/5] Add formula for LiIon batteries to compute capacity

FromMarek Belisko <marek.belisko@open-nandra.com>
Date2017-08-01 23:00 +0200
Subject[RFC PATCH 0/5] Add formula for LiIon batteries to compute capacity
Message-ID<u9MqK-nk-3@gated-at.bofh.it>
This patches sitting in my repo for long time and would like to get feedback first before
submitting final series. This patches adding devicetree to generic-adc-battery driver
(we reuse it for gta04 board then and drop twl4030_madc_battery). Also add formula
for computing capacity of LiIon battery. This patches was tested on gta04 and
works fine. Thanks for comments.

Marek Belisko (5):
  dt-bindings: power: Add battery types
  power: generic-adc-battery: Parse more properties from DT
  power/generic-adc-battery: Add support for temperature and add check
    for charge from iio current channel
  power: Add formula for computing LiIon State of Charge from Voltage
  power: generic-adc-battery: Add capacity handling

 drivers/power/supply/generic-adc-battery.c | 100 ++++++++++++++++++++++++++++-
 include/dt-bindings/power/power.h          |  11 ++++
 include/linux/power/generic-fuel-gauge.h   |  38 +++++++++++
 3 files changed, 146 insertions(+), 3 deletions(-)
 create mode 100644 include/dt-bindings/power/power.h
 create mode 100644 include/linux/power/generic-fuel-gauge.h

-- 
2.7.4

[toc] | [next] | [standalone]


#1701495 — [RFC PATCH 1/5] dt-bindings: power: Add battery types

FromMarek Belisko <marek.belisko@open-nandra.com>
Date2017-08-01 23:00 +0200
Subject[RFC PATCH 1/5] dt-bindings: power: Add battery types
Message-ID<u9MqN-nk-93@gated-at.bofh.it>
In reply to#1701483
From: Marek Belisko <marek.belisko@gmail.com>

Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
---
 include/dt-bindings/power/power.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 include/dt-bindings/power/power.h

diff --git a/include/dt-bindings/power/power.h b/include/dt-bindings/power/power.h
new file mode 100644
index 0000000..ea36d7f
--- /dev/null
+++ b/include/dt-bindings/power/power.h
@@ -0,0 +1,11 @@
+#ifndef _DT_BINDINGS_POWER_H
+#define _DT_BINDINGS_POWER_H
+
+#define POWER_SUPPLY_TECHNOLOGY_NiMH 1
+#define POWER_SUPPLY_TECHNOLOGY_LION 2
+#define POWER_SUPPLY_TECHNOLOGY_LIPO 3
+#define POWER_SUPPLY_TECHNOLOGY_LiFe 4
+#define POWER_SUPPLY_TECHNOLOGY_NiCd 5
+#define POWER_SUPPLY_TECHNOLOGY_LiMn 6
+
+#endif /* _DT_BINDINGS_POWER_H */
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1702029 — Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types

FromPavel Machek <pavel@ucw.cz>
Date2017-08-02 13:40 +0200
SubjectRe: [RFC PATCH 1/5] dt-bindings: power: Add battery types
Message-ID<ua0am-Og-19@gated-at.bofh.it>
In reply to#1701495

[Multipart message — attachments visible in raw view] — view raw

On Tue 2017-08-01 22:55:22, Marek Belisko wrote:
> From: Marek Belisko <marek.belisko@gmail.com>
> 
> Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
> ---
>  include/dt-bindings/power/power.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>  create mode 100644 include/dt-bindings/power/power.h
> 
> diff --git a/include/dt-bindings/power/power.h b/include/dt-bindings/power/power.h
> new file mode 100644
> index 0000000..ea36d7f
> --- /dev/null
> +++ b/include/dt-bindings/power/power.h
> @@ -0,0 +1,11 @@
> +#ifndef _DT_BINDINGS_POWER_H
> +#define _DT_BINDINGS_POWER_H
> +
> +#define POWER_SUPPLY_TECHNOLOGY_NiMH 1
> +#define POWER_SUPPLY_TECHNOLOGY_LION 2

Nice animal :-), but I guess this should be "LiION" or something.

> +#define POWER_SUPPLY_TECHNOLOGY_LIPO 3

Make it "LiPo" for consistency.

There's no differnce between Li-ion and Li-Po from the software side,
AFAICT, but I guess we can keep both..

> +#define POWER_SUPPLY_TECHNOLOGY_LiFe 4
> +#define POWER_SUPPLY_TECHNOLOGY_NiCd 5
> +#define POWER_SUPPLY_TECHNOLOGY_LiMn 6
> +
> +#endif /* _DT_BINDINGS_POWER_H */

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[toc] | [prev] | [next] | [standalone]


#1702033 — Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types

FromBelisko Marek <marek.belisko@gmail.com>
Date2017-08-02 13:50 +0200
SubjectRe: [RFC PATCH 1/5] dt-bindings: power: Add battery types
Message-ID<ua0k2-RL-11@gated-at.bofh.it>
In reply to#1701495
Hi Pavel,

On Wed, Aug 2, 2017 at 1:43 PM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
>> ---
>>  include/dt-bindings/power/power.h | 11 +++++++++++
>>  1 file changed, 11 insertions(+)
>>  create mode 100644 include/dt-bindings/power/power.h
>>
>> diff --git a/include/dt-bindings/power/power.h b/include/dt-bindings/power/power.h
>> new file mode 100644
>> index 0000000..ea36d7f
>> --- /dev/null
>> +++ b/include/dt-bindings/power/power.h
>> @@ -0,0 +1,11 @@
>> +#ifndef _DT_BINDINGS_POWER_H
>> +#define _DT_BINDINGS_POWER_H
>> +
>> +#define POWER_SUPPLY_TECHNOLOGY_NiMH 1
>> +#define POWER_SUPPLY_TECHNOLOGY_LION 2
>> +#define POWER_SUPPLY_TECHNOLOGY_LIPO 3
>> +#define POWER_SUPPLY_TECHNOLOGY_LiFe 4
>
> Actually I'd add comments here, such as "/* LiFePO4 */, because
> otherwise it is a bit ambiguous.

OK.
>
>> +#define POWER_SUPPLY_TECHNOLOGY_NiCd 5
>> +#define POWER_SUPPLY_TECHNOLOGY_LiMn 6
>> +
>> +#endif /* _DT_BINDINGS_POWER_H */
>
> The rest of series is ok, you can add
>
> Acked-by: Pavel Machek <pavel@ucw.cz>
>
> , but I guess someone would want a little more verbose changelogs.
Yes I'll post final series with updated commit messages. Thanks.
>
> BTW what hardware are you working with?
We have working it on gta04 board. Also after this will be merged we
can drop custom battery driver
for gta04 and use this generic (maybe also other drivers can reuse this one).
>                                                                         Pavel
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

BR,

marek


-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com

[toc] | [prev] | [next] | [standalone]


#1702037 — Re: [RFC PATCH 1/5] dt-bindings: power: Add battery types

FromPavel Machek <pavel@ucw.cz>
Date2017-08-02 13:50 +0200
SubjectRe: [RFC PATCH 1/5] dt-bindings: power: Add battery types
Message-ID<ua0k2-RL-13@gated-at.bofh.it>
In reply to#1701495

[Multipart message — attachments visible in raw view] — view raw

Hi!

> Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
> ---
>  include/dt-bindings/power/power.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>  create mode 100644 include/dt-bindings/power/power.h
> 
> diff --git a/include/dt-bindings/power/power.h b/include/dt-bindings/power/power.h
> new file mode 100644
> index 0000000..ea36d7f
> --- /dev/null
> +++ b/include/dt-bindings/power/power.h
> @@ -0,0 +1,11 @@
> +#ifndef _DT_BINDINGS_POWER_H
> +#define _DT_BINDINGS_POWER_H
> +
> +#define POWER_SUPPLY_TECHNOLOGY_NiMH 1
> +#define POWER_SUPPLY_TECHNOLOGY_LION 2
> +#define POWER_SUPPLY_TECHNOLOGY_LIPO 3
> +#define POWER_SUPPLY_TECHNOLOGY_LiFe 4

Actually I'd add comments here, such as "/* LiFePO4 */, because
otherwise it is a bit ambiguous.

> +#define POWER_SUPPLY_TECHNOLOGY_NiCd 5
> +#define POWER_SUPPLY_TECHNOLOGY_LiMn 6
> +
> +#endif /* _DT_BINDINGS_POWER_H */

The rest of series is ok, you can add

Acked-by: Pavel Machek <pavel@ucw.cz>

, but I guess someone would want a little more verbose changelogs.

BTW what hardware are you working with?
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[toc] | [prev] | [next] | [standalone]


#1701497 — [RFC PATCH 4/5] power: Add formula for computing LiIon State of Charge from Voltage

FromMarek Belisko <marek.belisko@open-nandra.com>
Date2017-08-01 23:00 +0200
Subject[RFC PATCH 4/5] power: Add formula for computing LiIon State of Charge from Voltage
Message-ID<u9MqO-nk-97@gated-at.bofh.it>
In reply to#1701483
From: Marek Belisko <marek.belisko@gmail.com>

The formula appears to be known in RC model communities.
We did find the first reference on the web in a a forum post
by "SilverFox" from 04-16-2008:

http://www.candlepowerforums.com/vb/showthread.php?115871-Li-Ion-State-of-Charge-and-Voltage-Measurements#post2440539

Some other posts attribute it to Sanyo.

The linear interpplation below 19.66% was suggested by Pavel Machek.

Signed-off-by: Marek Belisko <marek.belisko@gmail.com>
---
 include/linux/power/generic-fuel-gauge.h | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 include/linux/power/generic-fuel-gauge.h

diff --git a/include/linux/power/generic-fuel-gauge.h b/include/linux/power/generic-fuel-gauge.h
new file mode 100644
index 0000000..2da7825
--- /dev/null
+++ b/include/linux/power/generic-fuel-gauge.h
@@ -0,0 +1,38 @@
+#ifndef PWR_GENERIC_FUEL_GAUSE_H
+#define PWR_GENERIC_FUEL_GAUSE_H
+
+/* calculate remaining fuel level (in %) of a LiIon battery assuming
+ * a standard chemistry model
+ *    The first reference found on the web seems to be a forum post
+ *    by "SilverFox" from 04-16-2008. It appears to be attributed to Sanyo.
+ *    http://www.candlepowerforums.com/vb/showthread.php?115871-Li-Ion-State-of-Charge-and-Voltage-Measurements#post2440539
+ *    The linear interpplation below 19.66% was suggested by Pavel Machek.
+ *
+ * @mV: voltage measured outside the battery
+ * @mA: current flowing out of the battery
+ * @mOhm: assumed series resitance of the battery
+ *
+ * returns value between 0 and 100
+ */
+static inline int fuel_level_LiIon(int mV, int mA, int mOhm) {
+	int u;
+
+	/* internal battery voltage is higher than measured when discharging */
+	mV += (mOhm * mA) /1000;
+
+	if (mV == 0)
+		return 0;
+
+	/* apply first part of formula */
+	u = 3870000 - (14523 * (37835 - 10 * mV));
+
+	/* use linear approx. below 3.756V => 19.66% assuming 3.3V => 0% */
+	if (u < 0) {
+		return  max(((mV - 3300) * ((3756 - 3300) * 1966)) / 100000000, 0);
+	}
+
+	/* apply second part of formula */
+	return min((int)(1966 + int_sqrt(u))/100, 100);	
+}
+
+#endif /* PWR_GENERIC_FUEL_GAUSE_H */
-- 
2.7.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web