display: add get/set brightness operations
authortaeyoung <ty317.kim@samsung.com>
Thu, 12 Nov 2015 08:32:56 +0000 (17:32 +0900)
committertaeyoung <ty317.kim@samsung.com>
Thu, 12 Nov 2015 08:33:58 +0000 (17:33 +0900)
- Brightness can be changed according to the sysfs interface.

Change-Id: I8be91c79e57ab58cdb328022995d158a597fb6d5
Signed-off-by: taeyoung <ty317.kim@samsung.com>
hw/display/display.c

index e144804..3d3f563 100644 (file)
 #include <hw/display.h>
 #include "../shared.h"
 
+#ifndef BACKLIGHT_PATH
+#define BACKLIGHT_PATH  "/sys/class/backlight/panel"
+#endif
+
+static int get_max_brightness(int *val)
+{
+       static int max = -1;
+       int r;
+
+       if (!val)
+               return -EINVAL;
+
+       if (max < 0) {
+               r = sys_get_int(BACKLIGHT_PATH"/max_brightness", &max);
+               if (r < 0)
+                       return r;
+       }
+
+       *val = max;
+       return 0;
+}
+
+static int display_get_brightness(int *brightness)
+{
+       int r, v;
+
+       if (!brightness) {
+               _E("wrong parameter");
+               return -EINVAL;
+       }
+
+       r = sys_get_int(BACKLIGHT_PATH"/brightness", &v);
+       if (r < 0) {
+               _E("fail to get brightness : %d", r);
+               return r;
+       }
+
+       *brightness = v;
+       return 0;
+}
+
+static int display_set_brightness(int brightness)
+{
+       int r, v, max;
+
+       if (brightness < 0 || brightness > 100) {
+               _E("wrong parameter");
+               return -EINVAL;
+       }
+
+       r = get_max_brightness(&max);
+       if (r < 0) {
+               _E("fail to get max brightness : %d", r);
+               return r;
+       }
+
+       v = brightness/100.f*max;
+       r = sys_set_int(BACKLIGHT_PATH"/brightness", v);
+       if (r < 0) {
+               _E("fail to set brightness : %s", strerror(r));
+               return r;
+       }
+
+       return 0;
+}
+
 static int display_open(struct hw_info *info,
                const char *id, struct hw_common **common)
 {
+       struct display_device *display_dev;
+
+       if (!info || !common)
+               return -EINVAL;
+
+       display_dev = calloc(1, sizeof(struct display_device));
+       if (!display_dev)
+               return -ENOMEM;
+
+       display_dev->common.info = info;
+       display_dev->get_brightness = display_get_brightness;
+       display_dev->set_brightness = display_set_brightness;
+
+       *common = (struct hw_common *)display_dev;
        return 0;
 }
 
 static int display_close(struct hw_common *common)
 {
+       if (!common)
+               return -EINVAL;
+
+       free(common);
        return 0;
 }