summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/export/config/fiiom3klinux.h4
-rw-r--r--firmware/export/config/hibylinux.h4
-rw-r--r--firmware/export/config/ibassodx50.h4
-rw-r--r--firmware/export/config/ibassodx90.h4
-rw-r--r--firmware/target/hosted/agptek/power-agptek.c22
-rw-r--r--firmware/target/hosted/agptek/power-agptek.h3
-rw-r--r--firmware/target/hosted/agptek/powermgmt-agptek.c11
-rw-r--r--firmware/target/hosted/aigo/power-erosq.c22
-rw-r--r--firmware/target/hosted/aigo/power-erosq.h3
-rw-r--r--firmware/target/hosted/aigo/powermgmt-erosq.c11
-rw-r--r--firmware/target/hosted/fiio/power-fiio.c24
-rw-r--r--firmware/target/hosted/fiio/power-fiio.h3
-rw-r--r--firmware/target/hosted/fiio/powermgmt-fiio.c11
-rw-r--r--firmware/target/hosted/ibasso/power-ibasso.c41
-rw-r--r--firmware/target/hosted/power-linux.c62
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.c22
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.h3
-rw-r--r--firmware/target/hosted/xduoo/powermgmt-xduoo.c11
19 files changed, 80 insertions, 187 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 36a125783c..430eb4119b 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -127,6 +127,7 @@ target/hosted/sysfs.c
127target/hosted/backlight-unix.c 127target/hosted/backlight-unix.c
128target/hosted/system-hosted.c 128target/hosted/system-hosted.c
129target/hosted/lcd-linuxfb.c 129target/hosted/lcd-linuxfb.c
130target/hosted/power-linux.c
130#endif 131#endif
131 132
132#if defined(AGPTEK_ROCKER) && !defined(SIMULATOR) 133#if defined(AGPTEK_ROCKER) && !defined(SIMULATOR)
@@ -1919,6 +1920,7 @@ target/hosted/lc-unix.c
1919target/hosted/ibasso/audiohw-ibasso.c 1920target/hosted/ibasso/audiohw-ibasso.c
1920target/hosted/ibasso/backlight-ibasso.c 1921target/hosted/ibasso/backlight-ibasso.c
1921target/hosted/ibasso/button-ibasso.c 1922target/hosted/ibasso/button-ibasso.c
1923target/hosted/power-linux.c
1922#ifdef DEBUG 1924#ifdef DEBUG
1923target/hosted/ibasso/debug-ibasso.c 1925target/hosted/ibasso/debug-ibasso.c
1924#endif 1926#endif
diff --git a/firmware/export/config/fiiom3klinux.h b/firmware/export/config/fiiom3klinux.h
index 51d2a222e6..0ce58be46f 100644
--- a/firmware/export/config/fiiom3klinux.h
+++ b/firmware/export/config/fiiom3klinux.h
@@ -128,3 +128,7 @@
128#define BOOTFILE_EXT "m3k" 128#define BOOTFILE_EXT "m3k"
129#define BOOTFILE "rockbox." BOOTFILE_EXT 129#define BOOTFILE "rockbox." BOOTFILE_EXT
130#define BOOTDIR "/.rockbox" 130#define BOOTDIR "/.rockbox"
131
132/* More stuff */
133#define BATTERY_DEV_NAME "battery"
134#define POWER_DEV_NAME "ac"
diff --git a/firmware/export/config/hibylinux.h b/firmware/export/config/hibylinux.h
index e73faa7608..f1e52917ba 100644
--- a/firmware/export/config/hibylinux.h
+++ b/firmware/export/config/hibylinux.h
@@ -84,3 +84,7 @@
84#define MULTIDRIVE_DIR "/mnt/usb" 84#define MULTIDRIVE_DIR "/mnt/usb"
85#define MULTIDRIVE_DEV "/sys/block/sda" 85#define MULTIDRIVE_DEV "/sys/block/sda"
86#define ROOTDRIVE_DEV "/sys/block/mmcblk0" 86#define ROOTDRIVE_DEV "/sys/block/mmcblk0"
87
88/* More common stuff */
89#define BATTERY_DEV_NAME "battery"
90#define POWER_DEV_NAME "usb"
diff --git a/firmware/export/config/ibassodx50.h b/firmware/export/config/ibassodx50.h
index 0a7c04a739..6bebf5a278 100644
--- a/firmware/export/config/ibassodx50.h
+++ b/firmware/export/config/ibassodx50.h
@@ -143,3 +143,7 @@
143/* No special storage */ 143/* No special storage */
144#define CONFIG_STORAGE STORAGE_HOSTFS 144#define CONFIG_STORAGE STORAGE_HOSTFS
145#define HAVE_STORAGE_FLUSH 145#define HAVE_STORAGE_FLUSH
146
147/* More common stuff */
148#define BATTERY_DEV_NAME "battery"
149#define POWER_DEV_NAME "usb"
diff --git a/firmware/export/config/ibassodx90.h b/firmware/export/config/ibassodx90.h
index 7071f50959..0b33665eb4 100644
--- a/firmware/export/config/ibassodx90.h
+++ b/firmware/export/config/ibassodx90.h
@@ -140,3 +140,7 @@
140/* No special storage */ 140/* No special storage */
141#define CONFIG_STORAGE STORAGE_HOSTFS 141#define CONFIG_STORAGE STORAGE_HOSTFS
142#define HAVE_STORAGE_FLUSH 142#define HAVE_STORAGE_FLUSH
143
144/* More common stuff */
145#define BATTERY_DEV_NAME "battery"
146#define POWER_DEV_NAME "usb"
diff --git a/firmware/target/hosted/agptek/power-agptek.c b/firmware/target/hosted/agptek/power-agptek.c
index 023d3888b9..a327ba6d06 100644
--- a/firmware/target/hosted/agptek/power-agptek.c
+++ b/firmware/target/hosted/agptek/power-agptek.c
@@ -32,28 +32,6 @@
32const char * const sysfs_bat_voltage = 32const char * const sysfs_bat_voltage =
33 "/sys/class/power_supply/battery/voltage_now"; 33 "/sys/class/power_supply/battery/voltage_now";
34 34
35const char * const sysfs_bat_status =
36 "/sys/class/power_supply/battery/status";
37
38const char * const sysfs_pow_supply =
39 "/sys/class/power_supply/usb/present";
40
41unsigned int agptek_power_input_status(void)
42{
43 int present = 0;
44 sysfs_get_int(sysfs_pow_supply, &present);
45
46 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
47}
48
49bool agptek_power_charging_status(void)
50{
51 char buf[12] = {0};
52 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
53
54 return (strncmp(buf, "Charging", 8) == 0);
55}
56
57unsigned int agptek_power_get_battery_voltage(void) 35unsigned int agptek_power_get_battery_voltage(void)
58{ 36{
59 int battery_voltage; 37 int battery_voltage;
diff --git a/firmware/target/hosted/agptek/power-agptek.h b/firmware/target/hosted/agptek/power-agptek.h
index 1ae2ff43d6..c6ca1eb9c9 100644
--- a/firmware/target/hosted/agptek/power-agptek.h
+++ b/firmware/target/hosted/agptek/power-agptek.h
@@ -23,8 +23,5 @@
23#include <stdbool.h> 23#include <stdbool.h>
24#include "config.h" 24#include "config.h"
25 25
26unsigned int agptek_power_input_status(void);
27bool agptek_power_charging_status(void);
28unsigned int agptek_power_get_battery_voltage(void); 26unsigned int agptek_power_get_battery_voltage(void);
29#endif /* _POWER_AGPTEK_H_ */ 27#endif /* _POWER_AGPTEK_H_ */
30
diff --git a/firmware/target/hosted/agptek/powermgmt-agptek.c b/firmware/target/hosted/agptek/powermgmt-agptek.c
index bd7e4157d6..beb2dc14b8 100644
--- a/firmware/target/hosted/agptek/powermgmt-agptek.c
+++ b/firmware/target/hosted/agptek/powermgmt-agptek.c
@@ -44,18 +44,7 @@ const unsigned short const percent_to_volt_charge[11] =
44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
45}; 45};
46 46
47unsigned int power_input_status(void)
48{
49 /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
50 return agptek_power_input_status();
51}
52
53int _battery_voltage(void) 47int _battery_voltage(void)
54{ 48{
55 return agptek_power_get_battery_voltage(); 49 return agptek_power_get_battery_voltage();
56} 50}
57
58bool charging_state(void)
59{
60 return agptek_power_charging_status();
61}
diff --git a/firmware/target/hosted/aigo/power-erosq.c b/firmware/target/hosted/aigo/power-erosq.c
index 0a4f820337..73fa5fe972 100644
--- a/firmware/target/hosted/aigo/power-erosq.c
+++ b/firmware/target/hosted/aigo/power-erosq.c
@@ -35,28 +35,6 @@ const char * const sysfs_bat_voltage =
35const char * const sysfs_bat_capacity = 35const char * const sysfs_bat_capacity =
36 "/sys/class/power_supply/battery/capacity"; 36 "/sys/class/power_supply/battery/capacity";
37 37
38const char * const sysfs_bat_status =
39 "/sys/class/power_supply/battery/status";
40
41const char * const sysfs_pow_supply =
42 "/sys/class/power_supply/usb/present";
43
44unsigned int erosq_power_input_status(void)
45{
46 int present = 0;
47 sysfs_get_int(sysfs_pow_supply, &present);
48
49 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
50}
51
52bool erosq_power_charging_status(void)
53{
54 char buf[12] = {0};
55 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
56
57 return (strncmp(buf, "Charging", 8) == 0);
58}
59
60unsigned int erosq_power_get_battery_voltage(void) 38unsigned int erosq_power_get_battery_voltage(void)
61{ 39{
62 int battery_voltage; 40 int battery_voltage;
diff --git a/firmware/target/hosted/aigo/power-erosq.h b/firmware/target/hosted/aigo/power-erosq.h
index d06b956924..213d55faa6 100644
--- a/firmware/target/hosted/aigo/power-erosq.h
+++ b/firmware/target/hosted/aigo/power-erosq.h
@@ -23,9 +23,6 @@
23#include <stdbool.h> 23#include <stdbool.h>
24#include "config.h" 24#include "config.h"
25 25
26unsigned int erosq_power_input_status(void);
27bool erosq_power_charging_status(void);
28unsigned int erosq_power_get_battery_voltage(void); 26unsigned int erosq_power_get_battery_voltage(void);
29unsigned int erosq_power_get_battery_capacity(void); 27unsigned int erosq_power_get_battery_capacity(void);
30#endif /* _POWER_XDUOO_H_ */ 28#endif /* _POWER_XDUOO_H_ */
31
diff --git a/firmware/target/hosted/aigo/powermgmt-erosq.c b/firmware/target/hosted/aigo/powermgmt-erosq.c
index e02dbc6244..5067c66426 100644
--- a/firmware/target/hosted/aigo/powermgmt-erosq.c
+++ b/firmware/target/hosted/aigo/powermgmt-erosq.c
@@ -45,18 +45,7 @@ const unsigned short const percent_to_volt_charge[11] =
45 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 45 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
46}; 46};
47 47
48unsigned int power_input_status(void)
49{
50 /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
51 return erosq_power_input_status();
52}
53
54int _battery_voltage(void) 48int _battery_voltage(void)
55{ 49{
56 return erosq_power_get_battery_voltage(); 50 return erosq_power_get_battery_voltage();
57} 51}
58
59bool charging_state(void)
60{
61 return erosq_power_charging_status();
62}
diff --git a/firmware/target/hosted/fiio/power-fiio.c b/firmware/target/hosted/fiio/power-fiio.c
index a2b19ce550..086c3bc9cb 100644
--- a/firmware/target/hosted/fiio/power-fiio.c
+++ b/firmware/target/hosted/fiio/power-fiio.c
@@ -37,30 +37,6 @@ const char * const sysfs_bat_voltage =
37const char * const sysfs_bat_capacity = 37const char * const sysfs_bat_capacity =
38 "/sys/class/power_supply/battery/capacity"; 38 "/sys/class/power_supply/battery/capacity";
39 39
40const char * const sysfs_bat_status =
41 "/sys/class/power_supply/battery/status";
42
43const char * const sysfs_pow_supply =
44 "/sys/class/power_supply/ac/online";
45
46unsigned int fiio_power_input_status(void)
47{
48 int present = 0;
49 sysfs_get_int(sysfs_pow_supply, &present);
50
51 usb_enable(present ? true : false);
52
53 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
54}
55
56bool fiio_power_charging_status(void)
57{
58 char buf[12] = {0};
59 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
60
61 return (strncmp(buf, "Charging", 8) == 0);
62}
63
64unsigned int fiio_power_get_battery_voltage(void) 40unsigned int fiio_power_get_battery_voltage(void)
65{ 41{
66 int battery_voltage; 42 int battery_voltage;
diff --git a/firmware/target/hosted/fiio/power-fiio.h b/firmware/target/hosted/fiio/power-fiio.h
index c3085e9569..47143a3f67 100644
--- a/firmware/target/hosted/fiio/power-fiio.h
+++ b/firmware/target/hosted/fiio/power-fiio.h
@@ -23,9 +23,6 @@
23#include <stdbool.h> 23#include <stdbool.h>
24#include "config.h" 24#include "config.h"
25 25
26unsigned int fiio_power_input_status(void);
27bool fiio_power_charging_status(void);
28unsigned int fiio_power_get_battery_voltage(void); 26unsigned int fiio_power_get_battery_voltage(void);
29unsigned int fiio_power_get_battery_capacity(void); 27unsigned int fiio_power_get_battery_capacity(void);
30#endif /* _POWER_FIIO_H_ */ 28#endif /* _POWER_FIIO_H_ */
31
diff --git a/firmware/target/hosted/fiio/powermgmt-fiio.c b/firmware/target/hosted/fiio/powermgmt-fiio.c
index b7c1b5fde2..da6305d9c4 100644
--- a/firmware/target/hosted/fiio/powermgmt-fiio.c
+++ b/firmware/target/hosted/fiio/powermgmt-fiio.c
@@ -44,12 +44,6 @@ const unsigned short const percent_to_volt_charge[11] =
44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
45}; 45};
46 46
47unsigned int power_input_status(void)
48{
49 /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
50 return fiio_power_input_status();
51}
52
53int _battery_voltage(void) 47int _battery_voltage(void)
54{ 48{
55 return fiio_power_get_battery_voltage(); 49 return fiio_power_get_battery_voltage();
@@ -61,8 +55,3 @@ int _battery_level(void)
61 return fiio_power_get_battery_capacity(); 55 return fiio_power_get_battery_capacity();
62} 56}
63#endif 57#endif
64
65bool charging_state(void)
66{
67 return fiio_power_charging_status();
68}
diff --git a/firmware/target/hosted/ibasso/power-ibasso.c b/firmware/target/hosted/ibasso/power-ibasso.c
index 8257de5f33..7d37913c7b 100644
--- a/firmware/target/hosted/ibasso/power-ibasso.c
+++ b/firmware/target/hosted/ibasso/power-ibasso.c
@@ -36,27 +36,6 @@
36#include "sysfs-ibasso.h" 36#include "sysfs-ibasso.h"
37#include "vold-ibasso.h" 37#include "vold-ibasso.h"
38 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) 39void power_off(void)
61{ 40{
62 TRACE; 41 TRACE;
@@ -75,23 +54,3 @@ void power_off(void)
75 54
76 reboot(RB_POWER_OFF); 55 reboot(RB_POWER_OFF);
77} 56}
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}
diff --git a/firmware/target/hosted/power-linux.c b/firmware/target/hosted/power-linux.c
new file mode 100644
index 0000000000..ea8d787ad5
--- /dev/null
+++ b/firmware/target/hosted/power-linux.c
@@ -0,0 +1,62 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2021 by Solomon Peachy
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include <sys/types.h>
21#include <fcntl.h>
22#include <string.h>
23#include <unistd.h>
24#include <stdio.h>
25
26#include "system.h"
27#include "power.h"
28#include "panic.h"
29#include "sysfs.h"
30
31#include "tick.h"
32
33#define BATTERY_STATUS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME "/status"
34#define POWER_STATUS_PATH "/sys/class/power_supply/" POWER_DEV_NAME "/online"
35
36/* We get called multiple times per tick, let's cut that back! */
37static long last_tick = 0;
38static bool last_power = false;
39
40bool charging_state(void)
41{
42 if ((current_tick - last_tick) > HZ/2 ) {
43 char buf[12] = {0};
44 sysfs_get_string(BATTERY_STATUS_PATH, buf, sizeof(buf));
45
46 last_tick = current_tick;
47 last_power = (strncmp(buf, "Charging", 8) == 0);
48 }
49 return last_power;
50}
51
52unsigned int power_input_status(void)
53{
54 int present = 0;
55 sysfs_get_int(POWER_STATUS_PATH, &present);
56
57#ifdef FIIO_M3K_LINUX
58 usb_enable(present ? true : false);
59#endif
60
61 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
62}
diff --git a/firmware/target/hosted/xduoo/power-xduoo.c b/firmware/target/hosted/xduoo/power-xduoo.c
index 97a8dd4779..0b1e2f816e 100644
--- a/firmware/target/hosted/xduoo/power-xduoo.c
+++ b/firmware/target/hosted/xduoo/power-xduoo.c
@@ -35,28 +35,6 @@ const char * const sysfs_bat_voltage =
35const char * const sysfs_bat_capacity = 35const char * const sysfs_bat_capacity =
36 "/sys/class/power_supply/battery/capacity"; 36 "/sys/class/power_supply/battery/capacity";
37 37
38const char * const sysfs_bat_status =
39 "/sys/class/power_supply/battery/status";
40
41const char * const sysfs_pow_supply =
42 "/sys/class/power_supply/usb/present";
43
44unsigned int xduoo_power_input_status(void)
45{
46 int present = 0;
47 sysfs_get_int(sysfs_pow_supply, &present);
48
49 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
50}
51
52bool xduoo_power_charging_status(void)
53{
54 char buf[12] = {0};
55 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
56
57 return (strncmp(buf, "Charging", 8) == 0);
58}
59
60unsigned int xduoo_power_get_battery_voltage(void) 38unsigned int xduoo_power_get_battery_voltage(void)
61{ 39{
62 int battery_voltage; 40 int battery_voltage;
diff --git a/firmware/target/hosted/xduoo/power-xduoo.h b/firmware/target/hosted/xduoo/power-xduoo.h
index d573865ed2..ee016bd60b 100644
--- a/firmware/target/hosted/xduoo/power-xduoo.h
+++ b/firmware/target/hosted/xduoo/power-xduoo.h
@@ -23,9 +23,6 @@
23#include <stdbool.h> 23#include <stdbool.h>
24#include "config.h" 24#include "config.h"
25 25
26unsigned int xduoo_power_input_status(void);
27bool xduoo_power_charging_status(void);
28unsigned int xduoo_power_get_battery_voltage(void); 26unsigned int xduoo_power_get_battery_voltage(void);
29unsigned int xduoo_power_get_battery_capacity(void); 27unsigned int xduoo_power_get_battery_capacity(void);
30#endif /* _POWER_XDUOO_H_ */ 28#endif /* _POWER_XDUOO_H_ */
31
diff --git a/firmware/target/hosted/xduoo/powermgmt-xduoo.c b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
index 35d9e45ffc..855072031e 100644
--- a/firmware/target/hosted/xduoo/powermgmt-xduoo.c
+++ b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
@@ -44,12 +44,6 @@ const unsigned short const percent_to_volt_charge[11] =
44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
45}; 45};
46 46
47unsigned int power_input_status(void)
48{
49 /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
50 return xduoo_power_input_status();
51}
52
53#if defined(XDUOO_X3II) 47#if defined(XDUOO_X3II)
54int _battery_voltage(void) 48int _battery_voltage(void)
55{ 49{
@@ -63,8 +57,3 @@ int _battery_level(void)
63 return xduoo_power_get_battery_capacity(); 57 return xduoo_power_get_battery_capacity();
64} 58}
65#endif 59#endif
66
67bool charging_state(void)
68{
69 return xduoo_power_charging_status();
70}