gitscraper: Provide way to get timestamps for files.
[maemo-rb.git] / firmware / export / powermgmt.h
blob14d0078c3160f5458ae45e834d66788b6a9c6908
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _POWERMGMT_H_
22 #define _POWERMGMT_H_
24 #include <stdbool.h>
25 #include "config.h"
27 #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
29 enum charge_state_type
31 /* sorted by increasing charging current (do not change!) */
32 #if CONFIG_CHARGING >= CHARGING_MONITOR
33 CHARGE_STATE_DISABLED = -2, /* Disable charger use (safety measure) */
34 CHARGE_STATE_ERROR = -1, /* Some error occurred that should not allow
35 turning on the charger again by software
36 without user intervention (ie. replug) */
37 #endif
38 DISCHARGING = 0,
39 #if CONFIG_CHARGING >= CHARGING_MONITOR
40 TRICKLE, /* For NiCd, battery maintenence phase */
41 /* For LiIon, low-current precharge phase */
42 TOPOFF, /* For NiCd, waiting for dead zone */
43 /* For LiIon, constant voltage phase */
44 CHARGING, /* For NiCd, main charge phase */
45 /* For LiIon, constant current phase */
46 #endif
49 /* tells what the charger is doing */
50 extern enum charge_state_type charge_state;
52 #ifdef CONFIG_CHARGING
54 * Flag that the charger has been plugged in/removed: this is set for exactly
55 * one time through the power loop when the charger has been plugged in.
57 enum charger_input_state_type
59 NO_CHARGER = 0, /* No charger is present */
60 CHARGER_UNPLUGGED, /* Transitional state during CHARGER=>NO_CHARGER */
61 CHARGER_PLUGGED, /* Transitional state during NO_CHARGER=>CHARGER */
62 CHARGER /* Charger is present */
65 /* tells the state of the charge input */
66 extern enum charger_input_state_type charger_input_state;
68 /* Power input status saved on the power thread each loop */
69 extern unsigned int power_thread_inputs;
71 #endif /* CONFIG_CHARGING */
73 #if CONFIG_CHARGING == CHARGING_TARGET
74 /* Include target-specific definitions */
75 #include "powermgmt-target.h"
76 #endif
78 /* Start up power management thread */
79 void powermgmt_init(void) INIT_ATTR;
81 /* Generic current values that are intentionally meaningless - config header
82 * should define proper numbers.*/
85 #ifndef CURRENT_BACKLIGHT
86 #define CURRENT_BACKLIGHT 5 /* additional current when backlight always on */
87 #endif
89 #if defined(HAVE_RECORDING) && !defined(CURRENT_RECORD)
90 #define CURRENT_RECORD 2 /* additional recording current */
91 #endif /* HAVE_RECORDING && !CURRENT_RECORD*/
93 #ifndef CURRENT_USB
94 #define CURRENT_USB 2 /* usual current in mA in USB mode */
95 #endif
97 #if defined(HAVE_REMOTE_LCD) && !defined(CURRENT_REMOTE)
98 #define CURRENT_REMOTE 2 /* additional current when remote connected */
99 #endif /* CURRENT_REMOTE && !HAVE_REMOTE_LCD */
101 #if CONFIG_CHARGING
102 #ifndef CURRENT_MAX_CHG
103 #define CURRENT_MAX_CHG 350 /* maximum charging current */
104 #endif
105 #endif /* CONFIG_CHARGING */
107 #ifdef CHARGING_DEBUG_FILE
108 #define POWERMGMT_DEBUG_STACK ((0x1000)/sizeof(long))
109 #else
110 #define POWERMGMT_DEBUG_STACK 0
111 #endif
113 #ifndef BATT_AVE_SAMPLES
114 /* slw filter constant unless otherwise specified */
115 #define BATT_AVE_SAMPLES 128
116 #endif
118 #ifndef POWER_THREAD_STEP_TICKS
119 /* 2HZ sample rate unless otherwise specified */
120 #define POWER_THREAD_STEP_TICKS (HZ/2)
121 #endif
123 extern unsigned short power_history[POWER_HISTORY_LEN];
124 extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT];
125 extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT];
126 extern const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
127 #if CONFIG_CHARGING
128 extern const unsigned short percent_to_volt_charge[11];
129 #endif
131 /* Returns battery status, filtered for runtime estimation */
132 int battery_level(void); /* percent */
133 int battery_time(void); /* minutes */
134 int battery_voltage(void); /* filtered batt. voltage in millivolts */
136 /* Implemented by the target, unfiltered */
137 int _battery_level(void); /* percent */
138 int _battery_time(void); /* minutes */
139 int _battery_voltage(void); /* voltage in millivolts */
140 #if CONFIG_CHARGING >= CHARGING_TARGET
141 void powermgmt_init_target(void);
142 void charging_algorithm_close(void);
143 void charging_algorithm_step(void);
144 #endif
146 #ifdef HAVE_BATTERY_SWITCH
147 unsigned int input_millivolts(void); /* voltage that device is running from */
148 #endif /* HAVE_BATTERY_SWITCH */
150 #if defined(HAVE_BATTERY_SWITCH) || defined(HAVE_RESET_BATTERY_FILTER)
151 /* Set the filtered battery voltage (to adjust it before beginning a charge
152 * cycle for instance where old, loaded readings will likely be invalid).
153 * Also readjust when battery switch is opened or closed.
155 void reset_battery_filter(int millivolts);
156 #endif /* HAVE_BATTERY_SWITCH || HAVE_RESET_BATTERY_FILTER */
159 /* read unfiltered battery info */
160 void battery_read_info(int *voltage, int *level);
162 /* Tells if the battery level is safe for disk writes */
163 bool battery_level_safe(void);
165 void set_poweroff_timeout(int timeout);
166 void set_battery_capacity(int capacity); /* set local battery capacity value */
167 int get_battery_capacity(void); /* get local battery capacity value */
168 void set_battery_type(int type); /* set local battery type */
170 void set_sleep_timer(int seconds);
171 int get_sleep_timer(void);
172 void set_keypress_restarts_sleep_timer(bool enable);
173 void handle_auto_poweroff(void);
174 void set_car_adapter_mode(bool setting);
175 void reset_poweroff_timer(void);
176 void cancel_shutdown(void);
177 void shutdown_hw(void);
178 void sys_poweroff(void);
179 /* Returns true if the system should force shutdown for some reason -
180 * eg. low battery */
181 bool query_force_shutdown(void);
182 #ifdef HAVE_ACCESSORY_SUPPLY
183 void accessory_supply_set(bool);
184 #endif
185 #ifdef HAVE_LINEOUT_POWEROFF
186 void lineout_set(bool);
187 #endif
189 #endif /* _POWERMGMT_H_ */