#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;
}