summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c')
-rw-r--r--firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c
new file mode 100644
index 0000000000..6e04d25f58
--- /dev/null
+++ b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c
@@ -0,0 +1,107 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18#include "config.h"
19#include <sys/ioctl.h>
20#include "kernel.h"
21#include "powermgmt.h"
22#include "power.h"
23#include "file.h"
24#include "adc.h"
25#include "sc900776.h"
26#include "radio-ypr.h"
27
28const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
29{
30 3470
31};
32
33/* the OF shuts down at this voltage */
34const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
35{
36 3450
37};
38
39/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
40const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
41{
42 { 3450, 3502, 3550, 3587, 3623, 3669, 3742, 3836, 3926, 4026, 4200 }
43};
44
45#if CONFIG_CHARGING
46/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
47const unsigned short const percent_to_volt_charge[11] =
48{
49 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200
50};
51
52unsigned int power_input_status(void)
53{
54 unsigned status = POWER_INPUT_NONE;
55 int fd = open("/dev/minivet", O_RDONLY);
56 if (fd >= 0)
57 {
58 if (ioctl(fd, IOCTL_MINIVET_DET_VBUS, NULL) > 0)
59 status = POWER_INPUT_MAIN_CHARGER;
60 close(fd);
61 }
62 return status;
63}
64
65#endif /* CONFIG_CHARGING */
66
67
68/* Returns battery voltage from ADC [millivolts],
69 * adc returns voltage in 5mV steps */
70int _battery_voltage(void)
71{
72 return adc_read(3) * 5;
73}
74
75bool charging_state(void)
76{
77 const unsigned short charged_thres = 4170;
78 bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER);
79 /* dont indicate for > ~95% */
80 return ret && (_battery_voltage() <= charged_thres);
81}
82
83#if CONFIG_TUNER
84static bool tuner_on = false;
85
86bool tuner_power(bool status)
87{
88 if (status != tuner_on)
89 {
90 tuner_on = status;
91 status = !status;
92 if (tuner_on) {
93 radiodev_open();
94 }
95 else {
96 radiodev_close();
97 }
98 }
99
100 return status;
101}
102
103bool tuner_powered(void)
104{
105 return tuner_on;
106}
107#endif /* #if CONFIG_TUNER */ \ No newline at end of file