copy license file
[apps/home/charging-animation.git] / src / chg_power.c
1 /*
2 Copyright 2012-2013  Samsung Electronics Co., Ltd
3
4 Licensed under the Flora License, Version 1.1 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://floralicense.org/license/
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 #include <string.h>
18 #include <sys/reboot.h>
19 #include <stdlib.h>
20 #include <sys/ioctl.h>
21 #include <device-node.h>
22 #include <devman.h>
23
24 #include "chg_common.h"
25 #include "chg_power.h"
26 #include "chg_misc.h"
27 #include "chg_env.h"
28 #include "chg_drmd.h"
29
30 static int s_lcd_bl_state = LCD_BL_ON;
31 static int s_lcd_br_state = LCD_BR_NORMAL;
32 static int s_sys_power_state = SYS_POWER_ON;
33
34 /*-----------------------------------------------------------------------------
35   fb_lcd_bl_on()
36  ----------------------------------------------------------------------------*/
37 static int fb_lcd_bl_on(st_fbdi *s_fbdi)
38 {
39         DEBUG_MSG("fb_lcd_bl_on() is called.\n");
40         ioctl(s_fbdi->fb_fd, FBIOBLANK, FB_BLANK_UNBLANK);
41         return 0;
42 }
43
44 /*-----------------------------------------------------------------------------
45   fb_lcd_bl_off()
46  ----------------------------------------------------------------------------*/
47 static int fb_lcd_bl_off(st_fbdi *s_fbdi)
48 {
49         DEBUG_MSG("fb_lcd_bl_off() is called.\n");
50         ioctl(s_fbdi->fb_fd, FBIOBLANK, FB_BLANK_POWERDOWN);
51         return 0;
52 }
53 /*-----------------------------------------------------------------------------
54   lcd_bl_on()
55  ----------------------------------------------------------------------------*/
56 int lcd_bl_on(FbInfo *fbi)
57 {
58         DEBUG_MSG("lcd_bl_on() is called.\n");
59         if (s_lcd_bl_state == LCD_BL_ON)
60                 return 0;
61
62         if (fbi->type == FB_DEV_FB) {
63                 if (fb_lcd_bl_on((st_fbdi*)fbi->dev) < 0)
64                         return -1;
65         } else if (fbi->type == FB_DEV_DRM) {
66                 if (drmd_lcd_on((st_drmdi*)fbi->dev) < 0)
67                         return -1;
68         } else
69                 return -1;
70
71         s_lcd_bl_state = LCD_BL_ON;
72         return 0;
73 }
74
75 /*-----------------------------------------------------------------------------
76   lcd_bl_off()
77  ----------------------------------------------------------------------------*/
78 int lcd_bl_off(FbInfo *fbi)
79 {
80         DEBUG_MSG("lcd_bl_off() is called.\n");
81         if (s_lcd_bl_state == LCD_BL_OFF)
82                 return 0;
83
84         if (fbi->type == FB_DEV_FB) {
85                 if (fb_lcd_bl_off((st_fbdi*)fbi->dev) < 0)
86                         return -1;
87         } else if (fbi->type == FB_DEV_DRM) {
88                 if (drmd_lcd_off((st_drmdi*)fbi->dev) < 0)
89                         return -1;
90         } else
91                 return -1;
92
93         s_lcd_bl_state = LCD_BL_OFF;
94         return 0;
95 }
96
97 /*-----------------------------------------------------------------------------
98   lcd_bl_state()
99  ----------------------------------------------------------------------------*/
100 int lcd_bl_state(void)
101 {
102         return s_lcd_bl_state;
103 }
104
105
106 /*-----------------------------------------------------------------------------
107   lcd_br_normal()
108  ----------------------------------------------------------------------------*/
109 int lcd_br_normal(void)
110 {
111         int ret = 0;
112         int brightness_max = 0;
113
114         brightness_max = device_get_max_brt(DEV_MAIN_DISPLAY);
115         ret = device_set_property(DEVICE_TYPE_DISPLAY,PROP_DISPLAY_BRIGHTNESS,(int)(brightness_max*0.6));
116
117         DEBUG_MSG("lcd_br_normal() is called. ret : %d \n",ret);
118
119         s_lcd_br_state = LCD_BR_NORMAL;
120         return 0;
121 }
122
123 /*-----------------------------------------------------------------------------
124   lcd_br_dimm()
125  ----------------------------------------------------------------------------*/
126 int lcd_br_dimm(void)
127 {
128         int ret = 0;
129
130         ret = device_set_property(DEVICE_TYPE_DISPLAY,PROP_DISPLAY_BRIGHTNESS, 0);
131
132         DEBUG_MSG("lcd_br_dimm() is called. ret : %d \n",ret);
133
134         s_lcd_br_state = LCD_BR_DIMM;
135         return 0;
136 }
137
138 /*-----------------------------------------------------------------------------
139   lcd_br_state()
140  ----------------------------------------------------------------------------*/
141 int lcd_br_state(void)
142 {
143         return s_lcd_br_state;
144 }
145
146 /*-----------------------------------------------------------------------------
147   sys_power_wakeup()
148  ----------------------------------------------------------------------------*/
149 int sys_power_wakeup(FbInfo *fbi)
150 {
151         DEBUG_MSG("sys_power_wakeup() is called.\n");
152
153         s_sys_power_state = SYS_POWER_ON;
154         lcd_bl_on(fbi);
155
156         return 0;
157 }
158  
159 /*-----------------------------------------------------------------------------
160   sys_power_sleep()
161  ----------------------------------------------------------------------------*/
162 int sys_power_sleep(FbInfo *fbi)
163 {
164         DEBUG_MSG("sys_power_sleep() is called.env :%s\n",
165                 chg_env_str[EN_ENV_NO_SLEEP]);
166
167         s_sys_power_state = SYS_POWER_OFF;
168
169         lcd_bl_off(fbi);
170
171         if (0 == (strcmp(chg_env_str[EN_ENV_NO_SLEEP], "1"))) {
172                 DEBUG_MSG("nosleep...\n");
173                 return 0;
174         }
175
176         system_cmd_nowait("echo mem > /sys/power/state");
177
178         return 0;
179 }
180
181 /*-----------------------------------------------------------------------------
182   sys_power_state()
183  ----------------------------------------------------------------------------*/
184 int sys_power_state(void)
185 {
186         return s_sys_power_state;
187 }
188
189 /*-----------------------------------------------------------------------------
190   sys_power_reboot()
191  ----------------------------------------------------------------------------*/
192 void sys_power_reboot(void)
193 {
194         DEBUG_MSG("sys_power_reboot() is called.\n");
195         reboot(RB_AUTOBOOT);
196 }
197
198 /*-----------------------------------------------------------------------------
199   sys_power_off()
200  ----------------------------------------------------------------------------*/
201 void sys_power_off(void)
202 {
203         DEBUG_MSG("sys_power_off() is called.\n");
204         reboot(RB_POWER_OFF);
205 }
206