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 "../shared.h"
29 #ifndef BACKLIGHT_PATH
30 #define BACKLIGHT_PATH "/sys/class/backlight/rpi_backlight"
33 static int display_get_max_brightness(int *val)
42 r = sys_get_int(BACKLIGHT_PATH"/max_brightness", &max);
51 static int display_get_brightness(int *brightness)
56 _E("wrong parameter");
60 r = sys_get_int(BACKLIGHT_PATH"/brightness", &v);
62 _E("fail to get brightness (errno:%d)", r);
70 static int display_set_brightness(int brightness)
74 r = display_get_max_brightness(&max);
76 _E("fail to get max brightness (errno:%d)", r);
80 if (brightness < 0 || brightness > max) {
81 _E("wrong parameter");
85 r = sys_set_int(BACKLIGHT_PATH"/brightness", brightness);
87 _E("fail to set brightness (errno:%d)", r);
94 static int display_open(struct hw_info *info,
95 const char *id, struct hw_common **common)
97 struct display_device *display_dev;
102 display_dev = calloc(1, sizeof(struct display_device));
106 display_dev->common.info = info;
107 display_dev->get_max_brightness = display_get_max_brightness;
108 display_dev->get_brightness = display_get_brightness;
109 display_dev->set_brightness = display_set_brightness;
111 *common = (struct hw_common *)display_dev;
115 static int display_close(struct hw_common *common)
124 HARDWARE_MODULE_STRUCTURE = {
125 .magic = HARDWARE_INFO_TAG,
126 .hal_version = HARDWARE_INFO_VERSION,
127 .device_version = DISPLAY_HARDWARE_DEVICE_VERSION,
128 .id = DISPLAY_HARDWARE_DEVICE_ID,
130 .open = display_open,
131 .close = display_close,