summaryrefslogtreecommitdiff
path: root/src/display/core.h
blob: 00c3e273f3673c42308968b8a90b1f1a9d5131d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * deviced
 *
 * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/**
 * @file	core.h
 * @brief	 Power manager main loop header file
 */
#ifndef __POWER_MANAGER_H__
#define __POWER_MANAGER_H__

#include "poll.h"
#include "device-interface.h"
#include "setting.h"

#define WITHOUT_STARTNOTI	0x1
#define MASK_BIT    0x7		/* 111 */
#define MASK_NORMAL 0x1		/* 001 */
#define MASK_DIM    0x2		/* 010 */
#define MASK_OFF    0x4		/* 100 */

#define VCALL_FLAG		0x00000001
#define LOWBT_FLAG		0x00000100
#define CHRGR_FLAG		0x00000200
#define PWRSV_FLAG		0x00000400
#define BRTCH_FLAG		0x00002000
#define PWROFF_FLAG		0x00004000
#define DIMSTAY_FLAG		0x00008000
#define DIM_FLAG		0x00010000
#define BATTERY_FLAG		0x00020000
#define COOLDOWN_FLAG	0x00040000

#define DEFAULT_NORMAL_TIMEOUT	30

#define DIM_MASK		0x000f0000
#define MASK32			0xffffffff

#define CHECK_OPS(d, op) (d != NULL && d->op != NULL)

#ifdef ENABLE_PM_LOG
#define MAX_LOG_COUNT 250

enum pm_log_type {
	PM_LOG_MIN = 0,
	PM_LOG_KEY_PRESS = PM_LOG_MIN,	/* key log */
	PM_LOG_KEY_LONG_PRESS,
	PM_LOG_KEY_RELEASE,
	PM_LOG_LCD_ON,			/* lcd log */
	PM_LOG_LCD_ON_COMPLETE,
	PM_LOG_LCD_ON_FAIL,
	PM_LOG_LCD_DIM,
	PM_LOG_LCD_DIM_FAIL,
	PM_LOG_LCD_OFF,
	PM_LOG_LCD_OFF_COMPLETE,
	PM_LOG_LCD_OFF_FAIL,
	PM_LOG_LCD_CONTROL_FAIL,
	PM_LOG_SLEEP,
	PM_LOG_MAX
};

void pm_history_save(enum pm_log_type, int);
#endif

/*
 * State enumeration
 */
enum state_t {
	S_START,
	S_NORMAL,		/*< normal state */
	S_LCDON = S_NORMAL, /*< LCD on == normal state*/
	S_LCDDIM,		/*< LCD dimming */
	S_LCDOFF,		/*< LCD off */
	S_STANDBY,		/*< Standby */
	S_SLEEP,		/*< system suspend */
	S_SUSPEND = S_SLEEP, /*< Suspend == Sleep state */
	S_POWEROFF,		/*< Power off */
	S_END
};

/*
 * @brief State structure
 */
struct state {
	enum state_t state;           /**< state number */
	const char *name;                   /**< state name (string) */
	int (*trans) (int evt);       /**< transition function pointer */
	int (*action) (int timeout);  /**< enter action */
	int (*check) (int curr, int next); /**< transition check function */
	GSourceFunc timeout_cb;
	int timeout;
};

struct state *state_st(enum state_t state);

/*
 * @brief Configuration structure
 */
struct display_config {
	double lock_wait_time;
	double longpress_interval;
	double lightsensor_interval;
	int lcdoff_timeout;
	const int pm_default_brightness;
	int brightness_change_step;
	int lcd_always_on;
	int dimming;
	int framerate_app[4];
	int control_display;
	int powerkey_doublepress;
	int alpm_on;
	int accel_sensor_on;
	int continuous_sampling;
	int lockcheck_timeout;

	/* Define pmlock checker.
	 * Return id of the lock checker.
	 *
	 * Returning 0 will use default lock checker */
	int (*pmlock_check) (void *data);

	int aod_enter_level;
	bool aod_tsp;
	bool timeout_enable;
	bool input_support;
	bool touch_wakeup;
	bool sleep_support;
};

/*
 * Global variables
 *   display_conf : configuration of display
 */
struct display_config* get_var_display_config();

/*
 * @brief Display Extension features
 */
struct display_function_info {
	void (*update_auto_brightness)(bool);
	int (*set_autobrightness_min)(int, char *);
	GBusNameAppearedCallback reset_autobrightness_min;
	int (*face_detection)(int, int, int);
	void (*set_brightness_level)(int);
};

extern struct display_function_info display_info;

struct display_keyfilter_ops {
	void (*init)(void);
	void (*exit)(void);
	int (*check)(void *, int);
	void (*set_powerkey_ignore)(int);
	int (*powerkey_lcdoff)(void);
	void (*backlight_enable)(bool);
};

extern const struct display_keyfilter_ops *keyfilter_ops;
extern dd_list *lcdon_ops;

/* If the bit in a condition variable is set,
 *  we cannot transit the state until clear this bit. */
int check_processes(enum state_t prohibit_state);
extern struct state state[S_END];
void reset_lcd_timeout(GDBusConnection *conn,
						const gchar *sender,
						const gchar *unique_name,
						gpointer data);

/* setting.c */
int get_lock_screen_bg_state(void);
int set_custom_lcdon_timeout(int timeout);
void set_lock_screen_state(int state);
void set_lock_screen_bg_state(bool state);

/* core.c */
void change_state_action(enum state_t state, int (*func)(int timeout));
void change_state_trans(enum state_t state, int (*func)(int evt));
void change_state_check(enum state_t state, int (*func)(int curr, int next));
void change_state_name(enum state_t state, const char *name);
void change_trans_table(enum state_t state, enum state_t next);
void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid));

int delete_condition(enum state_t state);
int custom_lcdoff(enum device_flags flag);
int display_on_by_reason(const char *reason, int timeout);
int display_off_by_reason(const char *reason);
void update_lcdoff_source(int source);
int low_battery_state(int val);
int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name);
void save_display_log(const char *path);
int custom_lcdon(int timeout);
void set_stay_touchscreen_off(int val);
void set_lcd_paneloff_mode(int val);
void lcd_on_direct(enum device_flags flags);
void lcd_on_procedure(int state, enum device_flags flag);
void lcd_off_procedure(enum device_flags flag);
void lcd_direct_control(enum dpms_state state, int flags);
bool touch_event_blocked(void);
void broadcast_lcd_off_late(enum device_flags flags);
void set_dim_state(bool on);
void reset_timeout(int timeout);

/* auto-brightness.c */
void set_brightness_changed_state(void);

/* poll.c */
int check_dimstay(int next_state, int flag);

/* display-dbus.c */
int init_pm_dbus(void);

/* slave-logging.c */
int save_pmlock(enum state_t state, bool on, pid_t pid);

/**
 * @}
 */

#endif