4 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <linux/limits.h>
26 #include <hw/display.h>
27 #include <hw/shared.h>
29 #ifndef BACKLIGHT_PATH
30 #define BACKLIGHT_PATH "/sys/class/backlight/panel"
34 #define LCD_PATH "/sys/class/lcd/panel"
37 static int display_get_max_brightness(int *val)
46 r = sys_get_int(BACKLIGHT_PATH"/max_brightness", &max);
55 static int display_get_brightness(int *brightness)
60 _E("wrong parameter");
64 r = sys_get_int(BACKLIGHT_PATH"/brightness", &v);
66 _E("fail to get brightness : %d", r);
74 static int display_set_brightness(int brightness)
78 r = display_get_max_brightness(&max);
80 _E("fail to get max brightness (errno:%d)", r);
84 if (brightness < 0 || brightness > max) {
85 _E("wrong parameter");
89 r = sys_set_int(BACKLIGHT_PATH"/brightness", brightness);
91 _E("fail to set brightness (errno:%d)", r);
98 static int display_get_state(enum display_state *state)
102 r = sys_get_int(LCD_PATH"/lcd_power", &v);
104 _E("fail to get state (errno:%d)", r);
114 *state = DISPLAY_OFF;
124 static int display_open(struct hw_info *info,
125 const char *id, struct hw_common **common)
127 struct display_device *display_dev;
129 if (!info || !common)
132 display_dev = calloc(1, sizeof(struct display_device));
136 display_dev->common.info = info;
137 display_dev->get_max_brightness = display_get_max_brightness;
138 display_dev->get_brightness = display_get_brightness;
139 display_dev->set_brightness = display_set_brightness;
140 display_dev->get_state = display_get_state;
142 *common = (struct hw_common *)display_dev;
146 static int display_close(struct hw_common *common)
155 HARDWARE_MODULE_STRUCTURE = {
156 .magic = HARDWARE_INFO_TAG,
157 .hal_version = HARDWARE_INFO_VERSION,
158 .device_version = DISPLAY_HARDWARE_DEVICE_VERSION,
159 .id = DISPLAY_HARDWARE_DEVICE_ID,
161 .open = display_open,
162 .close = display_close,