2.0 alpha
[platform/core/system/devman.git] / devices / video.c
1 /*
2  *  devman
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: DongGi Jang <dg0402.jang@samsung.com>
7  * 
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20 */ 
21
22
23 #include "device_engine.h"
24 #include "device_plugin.h"
25 #include "vconf.h"
26
27 #define PROPERTY_MASK           0x0F
28 #define INDEX_SHIFT_CNT         4
29
30 static int get_video_prop(int prop, int *val)
31 {
32         int _prop = prop & PROPERTY_MASK;
33         int _index = prop >> 4;
34         int _max_disp_cnt = -1;
35         int power_saving_stat = -1;
36         int power_saving_display_stat = -1;
37
38         DBG("Property: %d, Index: %d", _prop, _index);
39         if (0 > plugin_intf->OEM_sys_get_display_count(&_max_disp_cnt)) {
40                 ERR("Get display count failed");
41                 return -1;
42         }
43
44         if (_index >= _max_disp_cnt) {
45                 ERR("Invalid Argument: display index > max display count");
46                 return -1;
47         }
48
49         switch (_prop) {
50         case DISPLAY_PROP_BRIGHTNESS:
51                 /* check power saving */
52                 vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &power_saving_stat);
53                 if (power_saving_stat == 1)
54                         vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, &power_saving_display_stat);
55                 if (power_saving_display_stat != 1)
56                         power_saving_display_stat = 0;
57                 return plugin_intf->OEM_sys_get_backlight_brightness(_index, val, power_saving_display_stat);
58         case DISPLAY_PROP_MIN_BRIGHTNESS:
59                 return plugin_intf->OEM_sys_get_backlight_min_brightness(_index, val);
60         case DISPLAY_PROP_MAX_BRIGHTNESS:
61                 return plugin_intf->OEM_sys_get_backlight_max_brightness(_index, val);
62         case DISPLAY_PROP_ONOFF:
63                 return plugin_intf->OEM_sys_get_lcd_power(_index, val);
64         case DISPLAY_PROP_GAMMA:
65                 /* TODO: not supported yet */
66                 DBG("Gamma is not supported");
67                 return 0;
68         case DISPLAY_PROP_DISPLAY_COUNT:
69                 *val = _max_disp_cnt;
70                 return 0;
71         case DISPLAY_PROP_ACL_CONTROL:
72                 return plugin_intf->OEM_sys_get_backlight_acl_control(_index, val);
73         case DISPLAY_PROP_IMAGE_ENHANCE_MODE:
74                 return plugin_intf->OEM_sys_get_image_enhance_mode(val);
75         case DISPLAY_PROP_IMAGE_ENHANCE_SCENARIO:
76                 return plugin_intf->OEM_sys_get_image_enhance_scenario(val);
77         case DISPLAY_PROP_IMAGE_ENHANCE_TONE:
78                 return plugin_intf->OEM_sys_get_image_enhance_tone(val);
79         case DISPLAY_PROP_IMAGE_ENHANCE_OUTDOOR:
80                 return plugin_intf->OEM_sys_get_image_enhance_outdoor(val);
81         case DISPLAY_PROP_IMAGE_ENHANCE_INFO:
82                 return plugin_intf->OEM_sys_image_enhance_info(val);
83         }
84
85         return -1;
86 }
87
88 static int set_video_prop(int prop, int val)
89 {
90         int _prop = prop & PROPERTY_MASK;
91         int _index = prop >> 4;
92         int _max_disp_cnt = -1;
93         int power_saving_stat = -1;
94         int power_saving_display_stat = -1;
95
96         DBG("Property: %d, Index: %d", _prop, _index);
97         if (0 > plugin_intf->OEM_sys_get_display_count(&_max_disp_cnt)) {
98                 ERR("Get display count failed");
99                 return -1;
100         }
101
102         if (_index >= _max_disp_cnt) {
103                 ERR("Invalid Argument: display index > max display count");
104                 return -1;
105         }
106
107         switch (_prop) {
108         case DISPLAY_PROP_BRIGHTNESS:
109                 /* check power saving */
110                 vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &power_saving_stat);
111                 if (power_saving_stat == 1)
112                         vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, &power_saving_display_stat);
113                 if (power_saving_display_stat != 1)
114                         power_saving_display_stat = 0;
115                 return plugin_intf->OEM_sys_set_backlight_brightness(_index, val, power_saving_display_stat);
116         case DISPLAY_PROP_ONOFF:
117                 return plugin_intf->OEM_sys_set_lcd_power(_index, val);
118         case DISPLAY_PROP_GAMMA:
119                 /* TODO:not supported yet */
120                 DBG("Gamma is not supported");
121                 return 0;
122         case DISPLAY_PROP_ACL_CONTROL:
123                 return plugin_intf->OEM_sys_set_backlight_acl_control(_index, val);
124         case DISPLAY_PROP_IMAGE_ENHANCE_MODE:
125                 return plugin_intf->OEM_sys_set_image_enhance_mode(val);
126         case DISPLAY_PROP_IMAGE_ENHANCE_SCENARIO:
127                 return plugin_intf->OEM_sys_set_image_enhance_scenario(val);
128         case DISPLAY_PROP_IMAGE_ENHANCE_TONE:
129                 return plugin_intf->OEM_sys_set_image_enhance_tone(val);
130         case DISPLAY_PROP_IMAGE_ENHANCE_OUTDOOR:
131                 return plugin_intf->OEM_sys_set_image_enhance_outdoor(val);
132         }
133
134         return -1;
135 }
136
137 static struct device video_prop = {
138         .devname = "video",
139         .set_int = set_video_prop,
140         .get_int = get_video_prop,
141         .devtype = DEVTYPE_DISPLAY0
142 };
143
144 static void __attribute__ ((constructor)) module_init()
145 {
146         add_dev(&video_prop);
147 }