Project

General

Profile

DangerousBatteryChargerExperiments » History » Version 4

dl lud, 12/20/2019 04:42 AM

1 1 Denis 'GNUtoo' Carikli
h1. DangerousBatteryChargerExperiments
2
3
h2. Messing with batteries is dangerous
4
5
Messing with battery charging is very dangerous:
6
* Batteries regularly explode in laptops and smartphones. The press often talks about that.
7
* Exploding batteries can cause dangerous fires.
8
* Messing with charging values can really cause batteries to explode or take fire.
9
10
So really make sure you know what you're doing if you mess with that.
11
12
This is not the usual warning that is there just because of legal requirements, in order to prevent potential lawsuits, and that tells you that the documentation may eat your cat.
13
14
Batteries issues are real.
15
16 4 dl lud
Read the "Wikipedia page on the Galaxy Note 6":https://en.wikipedia.org/wiki/Galaxy_Note_6#Battery_faults for a famous examples of a battery issue.
17 1 Denis 'GNUtoo' Carikli
18
Here the cause was due to the fact that the battery was non-removable and that the case didn't have enough extra space for the battery.
19
20 2 Denis 'GNUtoo' Carikli
It's also a well known fact that messing with the battery charging values can make the battery explode or catch fire.
21
22 1 Denis 'GNUtoo' Carikli
h2. Other warnings
23
24
You could also break your phone or have other issues if you mess up with battery charging values, but given that battery can explode or take fire the other issues are probably usually very minor compared to that.
25
26
h2. Disabling the charge
27
28
The max77693 driver in the Replicant 6 kernel has a "function to enable and disable charge": https://git.replicant.us/replicant/kernel_samsung_smdk4412/tree/drivers/battery/max77693_charger.c#n403
29
30
As this driver is used on a Galaxy SIII we tried to disable the charge by setting the last bit of the MAX77693_CHG_REG_CHG_CNFG_00 to 0.
31
32
<pre>
33
 i2cget -f 17 0x66 0xB7                                                                                                  
34
i2cget: WARNING! This program can confuse your I2C bus
35
Continue? [y/N] y
36
0x05
37
</pre>
38
39
<pre>
40
# i2cset -f 17 0x66 0xB7 0x4                                                                                                                    
41
i2cset: WARNING! This program can confuse your I2C bus
42
Continue? [y/N] y
43
</pre>
44
45
This stopped the charge:
46
<pre>
47
# grep POWER_SUPPLY_STATUS /sys/class/power_supply/battery/uevent                                                       
48
POWER_SUPPLY_STATUS=Discharging
49
</pre>
50
51 3 dl lud
We did that while the driver is running, as it is necessary to disable the charger register protection.
52 1 Denis 'GNUtoo' Carikli
53
However we didn't check if the driver could also be accessing that register while we were trying the i2cset command.
54
55
If the driver also access and changes that register, we could have a race condition where we read a value (0x05) and then the kernel does some stuff and changes it to 0xf5 for instance and then userspace would change it back to 0x04 messing up things.
56
57
So really use with caution.
58
59 2 Denis 'GNUtoo' Carikli
We also didn't get any review of what we were doing here, and humans do mistakes.
60 1 Denis 'GNUtoo' Carikli
61 2 Denis 'GNUtoo' Carikli
Also note that we don't have a datasheet for either the battery or the battery charger chip.
62
63 1 Denis 'GNUtoo' Carikli
h2. How to properly disable charging
64
65
In order to minimize the risk it would be best to have the upstream kernel review process involved.
66
67 2 Denis 'GNUtoo' Carikli
To do that, first you need your device to be ported to Replicant 9. The Galaxy SIII already boots under Replicant 9 and uses a kernel that is very closely based on upstream. So we can even test under GNU/Linux with Replicant 9 kernel.
68 1 Denis 'GNUtoo' Carikli
69
You can then take advantage of the Linux review process to be extra sure that you didn't mess up. You can send a patch that disable charging in the max77693_charger driver, enabling to disable charging through a sysfs node.
70
71 2 Denis 'GNUtoo' Carikli
This way, once it's done and merged upstream, userspace could easily stop the charging process with way less risks.
72 1 Denis 'GNUtoo' Carikli
73
Note that upstream still requires you to test (and probably understand) the code you are writing, so you still need to know what you are doing.
74
75
If you don't know what you are doing, try instead to find someone who does and who is willing to do it for you.