summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/backlight.c1
-rw-r--r--firmware/export/powermgmt.h9
-rw-r--r--firmware/kernel/include/queue.h1
-rw-r--r--firmware/powermgmt.c38
4 files changed, 42 insertions, 7 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 1284db4659..9575ecdc22 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -668,6 +668,7 @@ void backlight_thread(void)
668#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ 668#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
669#endif /* HAVE_BUTTON_LIGHT */ 669#endif /* HAVE_BUTTON_LIGHT */
670 670
671 case SYS_REBOOT:
671 case SYS_POWEROFF: /* Lock backlight on poweroff so it doesn't */ 672 case SYS_POWEROFF: /* Lock backlight on poweroff so it doesn't */
672 locked = true; /* go off before power is actually cut. */ 673 locked = true; /* go off before power is actually cut. */
673#if !defined(BOOTLOADER) 674#if !defined(BOOTLOADER)
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 3095d2c97b..6ae5ccfd13 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -70,6 +70,12 @@ extern unsigned int power_thread_inputs;
70 70
71#endif /* CONFIG_CHARGING */ 71#endif /* CONFIG_CHARGING */
72 72
73enum shutdown_type
74{
75 SHUTDOWN_POWER_OFF,
76 SHUTDOWN_REBOOT,
77};
78
73#if CONFIG_CHARGING == CHARGING_TARGET 79#if CONFIG_CHARGING == CHARGING_TARGET
74/* Include target-specific definitions */ 80/* Include target-specific definitions */
75#include "powermgmt-target.h" 81#include "powermgmt-target.h"
@@ -164,8 +170,9 @@ void handle_auto_poweroff(void);
164void set_car_adapter_mode(bool setting); 170void set_car_adapter_mode(bool setting);
165void reset_poweroff_timer(void); 171void reset_poweroff_timer(void);
166void cancel_shutdown(void); 172void cancel_shutdown(void);
167void shutdown_hw(void); 173void shutdown_hw(enum shutdown_type sd_type);
168void sys_poweroff(void); 174void sys_poweroff(void);
175void sys_reboot(void);
169/* Returns true if the system should force shutdown for some reason - 176/* Returns true if the system should force shutdown for some reason -
170 * eg. low battery */ 177 * eg. low battery */
171bool query_force_shutdown(void); 178bool query_force_shutdown(void);
diff --git a/firmware/kernel/include/queue.h b/firmware/kernel/include/queue.h
index 515a7e43a8..6740b88760 100644
--- a/firmware/kernel/include/queue.h
+++ b/firmware/kernel/include/queue.h
@@ -58,6 +58,7 @@
58#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1) 58#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1)
59#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2) 59#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2)
60#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3) 60#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3)
61#define SYS_REBOOT MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 4)
61#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0) 62#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0)
62#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0) 63#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0)
63#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1) 64#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1)
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 2cafd4b759..c33ad387ae 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -823,7 +823,7 @@ void powermgmt_init(void)
823} 823}
824 824
825/* Various hardware housekeeping tasks relating to shutting down the player */ 825/* Various hardware housekeeping tasks relating to shutting down the player */
826void shutdown_hw(void) 826void shutdown_hw(enum shutdown_type sd_type)
827{ 827{
828 charging_algorithm_close(); 828 charging_algorithm_close();
829 audio_stop(); 829 audio_stop();
@@ -863,7 +863,17 @@ void shutdown_hw(void)
863 eeprom chips are quite slow and might be still writing the last 863 eeprom chips are quite slow and might be still writing the last
864 byte. */ 864 byte. */
865 sleep(HZ/4); 865 sleep(HZ/4);
866 power_off(); 866
867 switch (sd_type) {
868 case SHUTDOWN_POWER_OFF:
869 default:
870 power_off();
871 break;
872
873 case SHUTDOWN_REBOOT:
874 system_reboot();
875 break;
876 }
867} 877}
868 878
869void set_poweroff_timeout(int timeout) 879void set_poweroff_timeout(int timeout)
@@ -878,10 +888,9 @@ void reset_poweroff_timer(void)
878 set_sleep_timer(sleeptimer_duration); 888 set_sleep_timer(sleeptimer_duration);
879} 889}
880 890
881void sys_poweroff(void)
882{
883#ifndef BOOTLOADER 891#ifndef BOOTLOADER
884 logf("sys_poweroff()"); 892static void sys_shutdown_common(void)
893{
885 /* If the main thread fails to shut down the system, we will force a 894 /* If the main thread fails to shut down the system, we will force a
886 power off after an 20 second timeout - 28 seconds if recording */ 895 power off after an 20 second timeout - 28 seconds if recording */
887 if (shutdown_timeout == 0) { 896 if (shutdown_timeout == 0) {
@@ -899,9 +908,26 @@ void sys_poweroff(void)
899 shutdown_timeout += HZ*20; 908 shutdown_timeout += HZ*20;
900#endif 909#endif
901 } 910 }
911}
912#endif /* BOOTLOADER */
902 913
914void sys_poweroff(void)
915{
916#ifndef BOOTLOADER
917 logf("sys_poweroff()");
918 sys_shutdown_common();
903 queue_broadcast(SYS_POWEROFF, 0); 919 queue_broadcast(SYS_POWEROFF, 0);
904#endif /* BOOTLOADER */ 920#endif
921}
922
923/* not to be confused with system_reboot... :( */
924void sys_reboot(void)
925{
926#ifndef BOOTLOADER
927 logf("sys_reboot()");
928 sys_shutdown_common();
929 queue_broadcast(SYS_REBOOT, 0);
930#endif
905} 931}
906 932
907void cancel_shutdown(void) 933void cancel_shutdown(void)