diff options
-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 |