diff options
author | Lorenzo Miori <memoryS60@gmail.com> | 2014-01-04 22:23:34 +0100 |
---|---|---|
committer | Gerrit Rockbox <gerrit@rockbox.org> | 2015-01-29 20:28:07 +0100 |
commit | 6879dec6ece3c0797c5df16c9dd494b3dc3a1329 (patch) | |
tree | 1d8cfd1905468d3b6a6d98b6aea3c00f4c26354c | |
parent | f65baf9b0f385bc479de9ab2eb92aab23167eba8 (diff) | |
download | rockbox-6879dec6ece3c0797c5df16c9dd494b3dc3a1329.tar.gz rockbox-6879dec6ece3c0797c5df16c9dd494b3dc3a1329.zip |
yp-r0: improve the charging code
Some people reported strange charging times and
strange battery life.
Charging by OF: 25 hours; RB: 18 hours
It has been found that there are at least two issues here:
1) the way of getting battery charging status wasn't
really accurate. This attempts to fix that issue.
This patch also simplifies some code (opening a
device is no more needed, for example).
To technically explain, battery charging implies first a constant
current mode (where the voltage increases) and then a constant
voltage mode (where, obviously, the voltage reads more or less
the same). The old way the End Of Charge was detected was based solely
on the voltage, while now it is based on chip's EOC interrupt,
which should be more accurate.
2) OF explicitly sets a constant current 350 mA, while we usually had
55 mA (by as3543 default).
This wasn't discovered before since there is a caching problem
("an accurate guess") in the Samsung power mgmt Linux module,
thus its debugging dumper wasn't really working, reporting a 55 mA current.
Strangely this option should have been set by the bootloader
but apparently it does not.
Some testing is still needed, but I confirm that with this patch
I could run a benchmark for 25 hours (vs. 18 hours), by charging
within Rockbox of course.
Change-Id: I3bd921e86b9018d1cc3c720d15cc46896e8490b3
-rw-r--r-- | firmware/export/config/samsungypr0.h | 8 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | 54 |
2 files changed, 44 insertions, 18 deletions
diff --git a/firmware/export/config/samsungypr0.h b/firmware/export/config/samsungypr0.h index b27a1fa2a6..212eaa8ec2 100644 --- a/firmware/export/config/samsungypr0.h +++ b/firmware/export/config/samsungypr0.h | |||
@@ -122,11 +122,6 @@ | |||
122 | 122 | ||
123 | #endif /* SIMULATOR */ | 123 | #endif /* SIMULATOR */ |
124 | 124 | ||
125 | /* FIXME | ||
126 | * Lot of people reports bad battery life and funny charging times. | ||
127 | * Check what's going on... | ||
128 | */ | ||
129 | |||
130 | #define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */ | 125 | #define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */ |
131 | #define BATTERY_CAPACITY_MIN 600 /* min. capacity selectable */ | 126 | #define BATTERY_CAPACITY_MIN 600 /* min. capacity selectable */ |
132 | #define BATTERY_CAPACITY_MAX 600 /* max. capacity selectable */ | 127 | #define BATTERY_CAPACITY_MAX 600 /* max. capacity selectable */ |
@@ -138,6 +133,9 @@ | |||
138 | /* Linux controlls charging, we can monitor */ | 133 | /* Linux controlls charging, we can monitor */ |
139 | #define CONFIG_CHARGING CHARGING_MONITOR | 134 | #define CONFIG_CHARGING CHARGING_MONITOR |
140 | 135 | ||
136 | /* We want to be able to reset the averaging filter */ | ||
137 | #define HAVE_RESET_BATTERY_FILTER | ||
138 | |||
141 | /* same dimensions as gigabeats */ | 139 | /* same dimensions as gigabeats */ |
142 | #define CONFIG_LCD LCD_YPR0 | 140 | #define CONFIG_LCD LCD_YPR0 |
143 | 141 | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c index 6e04d25f58..014a88db7c 100644 --- a/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c +++ b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | |||
@@ -16,14 +16,26 @@ | |||
16 | * | 16 | * |
17 | ****************************************************************************/ | 17 | ****************************************************************************/ |
18 | #include "config.h" | 18 | #include "config.h" |
19 | #include <sys/ioctl.h> | ||
20 | #include "kernel.h" | 19 | #include "kernel.h" |
21 | #include "powermgmt.h" | 20 | #include "powermgmt.h" |
22 | #include "power.h" | 21 | #include "power.h" |
23 | #include "file.h" | 22 | #include "file.h" |
24 | #include "adc.h" | 23 | #include "adc.h" |
25 | #include "sc900776.h" | ||
26 | #include "radio-ypr.h" | 24 | #include "radio-ypr.h" |
25 | #include "ascodec.h" | ||
26 | #include "stdbool.h" | ||
27 | |||
28 | enum | ||
29 | { | ||
30 | BATT_CHARGING, | ||
31 | BATT_NOT_CHARGING, | ||
32 | CHARGER_CONNECTED, | ||
33 | CHARGER_NOT_CONNECTED, | ||
34 | }; | ||
35 | |||
36 | static bool first_readout = true; | ||
37 | static int power_status = CHARGER_NOT_CONNECTED; | ||
38 | static int charging_status = BATT_NOT_CHARGING; | ||
27 | 39 | ||
28 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 40 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
29 | { | 41 | { |
@@ -49,17 +61,36 @@ const unsigned short const percent_to_volt_charge[11] = | |||
49 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 | 61 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 |
50 | }; | 62 | }; |
51 | 63 | ||
64 | static void read_charger(void) | ||
65 | { | ||
66 | charging_status = ascodec_endofch() ? BATT_NOT_CHARGING : BATT_CHARGING; | ||
67 | power_status = ascodec_chg_status() ? CHARGER_CONNECTED : CHARGER_NOT_CONNECTED; | ||
68 | /* Sync the filter due to new charging state */ | ||
69 | reset_battery_filter(_battery_voltage()); | ||
70 | } | ||
71 | |||
52 | unsigned int power_input_status(void) | 72 | unsigned int power_input_status(void) |
53 | { | 73 | { |
54 | unsigned status = POWER_INPUT_NONE; | 74 | if (first_readout) |
55 | int fd = open("/dev/minivet", O_RDONLY); | ||
56 | if (fd >= 0) | ||
57 | { | 75 | { |
58 | if (ioctl(fd, IOCTL_MINIVET_DET_VBUS, NULL) > 0) | 76 | /* 350mA, 4.20V */ |
59 | status = POWER_INPUT_MAIN_CHARGER; | 77 | ascodec_write_pmu(AS3543_CHARGER, 0x1, 0x5C); |
60 | close(fd); | 78 | /* Enable interrupt for charging detection */ |
79 | ascodec_write(AS3514_IRQ_ENRD0, CHG_CHANGED); | ||
80 | read_charger(); | ||
81 | first_readout = false; | ||
61 | } | 82 | } |
62 | return status; | 83 | |
84 | if (ascodec_read(AS3514_IRQ_ENRD0) & CHG_CHANGED) | ||
85 | { | ||
86 | /* Something has changed... */ | ||
87 | read_charger(); | ||
88 | } | ||
89 | |||
90 | if (power_status == CHARGER_CONNECTED) | ||
91 | return POWER_INPUT_MAIN_CHARGER; | ||
92 | else | ||
93 | return POWER_INPUT_NONE; | ||
63 | } | 94 | } |
64 | 95 | ||
65 | #endif /* CONFIG_CHARGING */ | 96 | #endif /* CONFIG_CHARGING */ |
@@ -74,10 +105,7 @@ int _battery_voltage(void) | |||
74 | 105 | ||
75 | bool charging_state(void) | 106 | bool charging_state(void) |
76 | { | 107 | { |
77 | const unsigned short charged_thres = 4170; | 108 | return (power_status == CHARGER_CONNECTED && charging_status == BATT_CHARGING); |
78 | bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER); | ||
79 | /* dont indicate for > ~95% */ | ||
80 | return ret && (_battery_voltage() <= charged_thres); | ||
81 | } | 109 | } |
82 | 110 | ||
83 | #if CONFIG_TUNER | 111 | #if CONFIG_TUNER |