From 4dd0b89bc564c642ed33268099a0a403dec1c723 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megous@megous.com>
Date: Mon, 28 Sep 2020 04:35:13 +0200
Subject: [PATCH 366/446] arm64: dts: sun50i-a64-pinephone: Add detailed OCV to
 capactiy conversion table

This ensures that discharging stops at 3V, and that charging current
limits are enforced. It also allows for more precise capacity reporting
(on my device at the very least, at room temperature).

Signed-off-by: Ondrej Jirman <megous@megous.com>
---
 .../dts/allwinner/sun50i-a64-pinephone.dtsi   | 151 ++++++++++++++++++
 1 file changed, 151 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
index fe8cc0a0b..10f2fba0a 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
@@ -26,6 +26,156 @@ backlight: backlight {
 		/* Backlight configuration differs per PinePhone revision. */
 	};
 
+        bat: battery {
+                compatible = "simple-battery";
+                voltage-min-design-microvolt = <3000000>;
+                voltage-max-design-microvolt = <4350000>;
+                energy-full-design-microwatt-hours = <12000000>;
+                charge-full-design-microamp-hours = <2750000>;
+                precharge-current-microamp = <130000>;
+                charge-term-current-microamp = <50000>;
+                constant-charge-current-max-microamp = <1300000>;
+                constant-charge-voltage-max-microvolt = <4350000>;
+                factory-internal-resistance-micro-ohms = <150000>;
+                resistance-temp-table = <20 150>;
+                ocv-capacity-celsius = <20>;
+                ocv-capacity-table-0 =
+                	<4334000 100>,
+			<4319700 99>,
+			<4304300 98>,
+			<4292200 97>,
+			<4280100 96>,
+			<4269100 95>,
+			<4253700 94>,
+			<4242700 93>,
+			<4232800 92>,
+			<4222900 91>,
+			<4211900 90>,
+			<4203100 89>,
+			<4192100 88>,
+			<4177800 87>,
+			<4167900 86>,
+			<4155800 85>,
+			<4147000 84>,
+			<4136000 83>,
+			<4126100 82>,
+			<4111800 81>,
+			<4102999 80>,
+			<4093100 79>,
+			<4084300 78>,
+			<4075500 77>,
+			<4064500 76>,
+			<4054600 75>,
+			<4042500 74>,
+			<4035900 73>,
+			<4029300 72>,
+			<4018300 71>,
+			<4006200 70>,
+			<3993000 69>,
+			<3974300 68>,
+			<3964400 67>,
+			<3956700 66>,
+			<3949000 65>,
+			<3943500 64>,
+			<3938000 63>,
+			<3931400 62>,
+			<3923700 61>,
+			<3917100 60>,
+			<3903900 59>,
+			<3895100 58>,
+			<3887400 57>,
+			<3878600 56>,
+			<3870900 55>,
+			<3863200 54>,
+			<3855500 53>,
+			<3848900 52>,
+			<3837900 51>,
+			<3830200 50>,
+			<3825800 49>,
+			<3821400 48>,
+			<3815900 47>,
+			<3810400 46>,
+			<3806000 45>,
+			<3801600 44>,
+			<3797200 43>,
+			<3792800 42>,
+			<3789500 41>,
+			<3786200 40>,
+			<3781800 39>,
+			<3778500 38>,
+			<3775200 37>,
+			<3770800 36>,
+			<3764200 35>,
+			<3760900 34>,
+			<3758700 33>,
+			<3755400 32>,
+			<3754300 31>,
+			<3752100 30>,
+			<3748800 29>,
+			<3749900 28>,
+			<3745500 27>,
+			<3742200 26>,
+			<3741100 25>,
+			<3737800 24>,
+			<3734500 23>,
+			<3731200 22>,
+			<3730100 21>,
+			<3724600 20>,
+			<3722400 19>,
+			<3718000 18>,
+			<3713600 17>,
+			<3708100 16>,
+			<3701500 15>,
+			<3689400 14>,
+			<3682800 13>,
+			<3674000 12>,
+			<3666300 11>,
+			<3659700 10>,
+			<3653100 9>,
+			<3647600 8>,
+			<3641000 7>,
+			<3625600 6>,
+			<3613500 5>,
+			<3591500 4>,
+			<3554100 3>,
+			<3489200 2>,
+			<3393500 1>,
+			<3256000 0>;
+                x-powers,ocv-capacity-table =
+                	<0xc0 0>,
+			<0xc1 1>,
+			<0xc2 1>,
+			<0xc3 2>,
+			<0xc4 2>,
+			<0xc5 4>,
+			<0xc6 4>,
+			<0xc7 5>,
+			<0xc8 6>,
+			<0xc9 8>,
+			<0xca 11>,
+			<0xcb 15>,
+			<0xcc 22>,
+			<0xcd 36>,
+			<0xce 44>,
+			<0xcf 48>,
+			<0xd0 51>,
+			<0xd1 53>,
+			<0xd2 56>,
+			<0xd3 60>,
+			<0xd4 64>,
+			<0xd5 69>,
+			<0xd6 71>,
+			<0xd7 75>,
+			<0xd8 78>,
+			<0xd9 82>,
+			<0xda 84>,
+			<0xdb 85>,
+			<0xdc 88>,
+			<0xdd 92>,
+			<0xde 95>,
+			<0xdf 98>;
+        };
+
 	bt_sco_codec: bt-sco-codec {
 		#sound-dai-cells = <1>;
 		compatible = "linux,bt-sco";
@@ -467,6 +617,7 @@ axp803: pmic@3a3 {
 
 &battery_power_supply {
 	status = "okay";
+	monitored-battery = <&bat>;
 };
 
 &reg_aldo1 {
-- 
2.31.1

