diff options
author | Lorenzo Miori <memorys60@gmail.com> | 2013-02-23 16:59:49 +0100 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2013-03-06 00:21:22 +0100 |
commit | 60592165ca998875e4bc46c4396c5a123a7e9dbb (patch) | |
tree | 60b53e6b733fd49bef249761789e97a4bedbef03 /firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | |
parent | 3e4be68f8b596cf3467f993dc9a210a3d901ca1c (diff) | |
download | rockbox-60592165ca998875e4bc46c4396c5a123a7e9dbb.tar.gz rockbox-60592165ca998875e4bc46c4396c5a123a7e9dbb.zip |
Samsung YP-R0 hosted target code refactoring
As per title this patch aims at splitting common target
code and specific target code in a better way to
support future ports within the same environment
(e.g. Samsung YP-R1 where the Linux and the SoC
are the same, with differences in hardware devices
handling)
Change-Id: I67b4918c46403b184d3d8f42ab5aae7d01037fd0
Reviewed-on: http://gerrit.rockbox.org/409
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Tested-by: Thomas Martitz <kugel@rockbox.org>
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c')
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | 107 |
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 | |||
28 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
29 | { | ||
30 | 3470 | ||
31 | }; | ||
32 | |||
33 | /* the OF shuts down at this voltage */ | ||
34 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
35 | { | ||
36 | 3450 | ||
37 | }; | ||
38 | |||
39 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
40 | const 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 */ | ||
47 | const unsigned short const percent_to_volt_charge[11] = | ||
48 | { | ||
49 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 | ||
50 | }; | ||
51 | |||
52 | unsigned 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 */ | ||
70 | int _battery_voltage(void) | ||
71 | { | ||
72 | return adc_read(3) * 5; | ||
73 | } | ||
74 | |||
75 | bool 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 | ||
84 | static bool tuner_on = false; | ||
85 | |||
86 | bool 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 | |||
103 | bool tuner_powered(void) | ||
104 | { | ||
105 | return tuner_on; | ||
106 | } | ||
107 | #endif /* #if CONFIG_TUNER */ \ No newline at end of file | ||