summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ibasso/power-ibasso.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ibasso/power-ibasso.c')
-rw-r--r--firmware/target/hosted/ibasso/power-ibasso.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/firmware/target/hosted/ibasso/power-ibasso.c b/firmware/target/hosted/ibasso/power-ibasso.c
new file mode 100644
index 0000000000..8257de5f33
--- /dev/null
+++ b/firmware/target/hosted/ibasso/power-ibasso.c
@@ -0,0 +1,97 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
10 * Copyright (C) 2014 by Mario Basister: iBasso DX90 port
11 * Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
12 * Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24
25#include <stdbool.h>
26#include <stdlib.h>
27#include <sys/reboot.h>
28
29#include "config.h"
30#include "debug.h"
31#include "power.h"
32
33#include "button-ibasso.h"
34#include "debug-ibasso.h"
35#include "pcm-ibasso.h"
36#include "sysfs-ibasso.h"
37#include "vold-ibasso.h"
38
39
40unsigned int power_input_status(void)
41{
42 /*TRACE;*/
43
44 /*
45 /sys/class/power_supply/usb/present
46 0: No external power supply connected.
47 1: External power supply connected.
48 */
49 int val = 0;
50 if(! sysfs_get_int(SYSFS_USB_POWER_PRESENT, &val))
51 {
52 DEBUGF("ERROR %s: Can not get power supply status.", __func__);
53 return POWER_INPUT_NONE;
54 }
55
56 return val ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
57}
58
59
60void power_off(void)
61{
62 TRACE;
63
64 button_close_device();
65
66 if(vold_monitor_forced_close_imminent())
67 {
68 /*
69 We are here, because Android Vold is going to kill Rockbox. Instead of powering off,
70 we exit into the loader.
71 */
72 DEBUGF("DEBUG %s: Exit Rockbox.", __func__);
73 exit(42);
74 }
75
76 reboot(RB_POWER_OFF);
77}
78
79
80/* Returns true, if battery is charging, false else. */
81bool charging_state(void)
82{
83 /*TRACE;*/
84
85 /*
86 /sys/class/power_supply/battery/status
87 "Full", "Charging", "Discharging"
88 */
89 char state[9];
90 if(! sysfs_get_string(SYSFS_BATTERY_STATUS, state, 9))
91 {
92 DEBUGF("ERROR %s: Can not get battery charging state.", __func__);
93 return false;
94 }
95
96 return(strcmp(state, "Charging") == 0);;
97}