display: Add display implementation 72/37572/1 submit/tizen/20150423.020639 submit/tizen_mobile/20150428.072824
authorJiyoung Yun <jy910.yun@samsung.com>
Tue, 31 Mar 2015 07:52:38 +0000 (16:52 +0900)
committerJiyoung Yun <jy910.yun@samsung.com>
Tue, 31 Mar 2015 07:53:14 +0000 (16:53 +0900)
Detail info:
https://wiki.tizen.org/wiki/HAL_upgrade_for_Tizen_3.0

Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
Change-Id: I841d00ccefcbde88773558929cb887916bcf0e50

CMakeLists.txt
hw/backlight.c [deleted file]
hw/display/CMakeLists.txt [new file with mode: 0644]
hw/display/display.c [new file with mode: 0644]
hw/led.c [deleted file]
hw/led/CMakeLists.txt [new file with mode: 0644]
hw/led/led.c [new file with mode: 0644]
hw/shared.h
packaging/device-manager-plugin-exynos5433.spec

index 4a501fad7a100367e3b1ae5090d5300e66add3fd..9175ff102df28bb14193ff5f11b831542cd148fc 100644 (file)
@@ -3,16 +3,5 @@ PROJECT(device-manager-exynos5433 C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
-INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED dlog hwcommon)
-
-FOREACH(flag ${pkgs_CFLAGS})
-       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-ADD_LIBRARY(led MODULE hw/led.c hw/shared.c)
-SET_TARGET_PROPERTIES(led PROPERTIES PREFIX "")
-INSTALL(TARGETS led DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
+ADD_SUBDIRECTORY(hw/display)
+ADD_SUBDIRECTORY(hw/led)
diff --git a/hw/backlight.c b/hw/backlight.c
deleted file mode 100644 (file)
index 6411813..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * device-node
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <linux/limits.h>
-
-#include <hw/backlight.h>
-#include "shared.h"
-
-#ifndef BACKLIGHT_PATH
-#define BACKLIGHT_PATH "/sys/class/backlight/s6e8aa0-bl"
-#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 backlight_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 : %s", strerror(r));
-               return r;
-       }
-
-       *brightness = v;
-       return 0;
-}
-
-static int backlight_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 : %s", strerror(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 backlight_get_mode(enum backlight_mode *mode)
-{
-       if (!mode) {
-               _E("wrong parameter");
-               return -EINVAL;
-       }
-
-       *mode = BACKLIGHT_MANUAL;
-       return 0;
-}
-
-static int backlight_set_mode(enum backlight_mode mode)
-{
-       if (mode == BACKLIGHT_SENSOR) {
-               _E("not supported option");
-               return -ENOTSUP;
-       }
-
-       return 0;
-}
-
-static int backlight_open(struct hw_info *info,
-               const char *id, struct hw_common **common)
-{
-       struct backlight_device *backlight_dev;
-
-       if (!info || !common)
-               return -EINVAL;
-
-       backlight_dev = calloc(1, sizeof(struct backlight_device));
-       if (!backlight_dev)
-               return -ENOMEM;
-
-       backlight_dev->common.info = info;
-       backlight_dev->get_brightness = backlight_get_brightness;
-       backlight_dev->set_brightness = backlight_set_brightness;
-       backlight_dev->get_mode = backlight_get_mode;
-       backlight_dev->set_mode = backlight_set_mode;
-
-       *common = (struct hw_common *)backlight_dev;
-       return 0;
-}
-
-static int backlight_close(struct hw_common *common)
-{
-       if (!common)
-               return -EINVAL;
-
-       free(common);
-       return 0;
-}
-
-HARDWARE_MODULE_STRUCTURE = {
-       .magic = HARDWARE_INFO_TAG,
-       .hal_version = HARDWARE_INFO_VERSION,
-       .device_version = BACKLIGHT_HARDWARE_DEVICE_VERSION,
-       .id = BACKLIGHT_HARDWARE_DEVICE_ID,
-       .name = "Default Backlight",
-       .author = "Jiyoung Yun <jy910.yun@samsung.com>",
-       .open = backlight_open,
-       .close = backlight_close,
-};
diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f1193e8
--- /dev/null
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(display C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(display_pkgs REQUIRED hwcommon dlog x11 xext)
+
+FOREACH(flag ${display_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE display.c ../shared.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${display_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/display/display.c b/hw/display/display.c
new file mode 100644 (file)
index 0000000..f956d51
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * device-node
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <linux/limits.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/dpms.h>
+
+#include <hw/display.h>
+#include "../shared.h"
+
+#ifndef BACKLIGHT_PATH
+#define BACKLIGHT_PATH  "/sys/class/backlight/s6e3ha2"
+#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 : %s", strerror(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 : %s", strerror(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_get_power_state(enum display_state *state)
+{
+       Display *dpy;
+       int dummy;
+       CARD16 dpms_state = DPMSModeOff;
+       BOOL onoff;
+
+       dpy = XOpenDisplay(NULL);
+       if (dpy == NULL) {
+               _E("fail to open display");
+               return -EPERM;
+       }
+
+       if (DPMSQueryExtension(dpy, &dummy, &dummy)) {
+               if (DPMSCapable(dpy)) {
+                       DPMSInfo(dpy, &dpms_state, &onoff);
+               }
+       }
+
+       XCloseDisplay(dpy);
+
+       if (state)
+               *state = dpms_state;
+
+       return 0;
+}
+
+static int display_set_power_state(enum display_state state)
+{
+       int type;
+       Display *dpy;
+
+       if (state == DISPLAY_ON)
+               type = DPMSModeOn;
+       else if (state == DISPLAY_STANDBY)
+               type = DPMSModeStandby;
+       else if (state == DISPLAY_SUSPEND)
+               type = DPMSModeSuspend;
+       else if (state == DISPLAY_OFF)
+               type = DPMSModeOff;
+       else
+               return -EINVAL;
+
+       dpy = XOpenDisplay(NULL);
+       if (dpy == NULL) {
+               _E("fail to open display");
+               return -EPERM;
+       }
+
+       DPMSEnable(dpy);
+       DPMSForceLevel(dpy, type);
+
+       XCloseDisplay(dpy);
+
+       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;
+       display_dev->get_state = display_get_power_state;
+       display_dev->set_state = display_set_power_state;
+
+       *common = (struct hw_common *)display_dev;
+       return 0;
+}
+
+static int display_close(struct hw_common *common)
+{
+       if (!common)
+               return -EINVAL;
+
+       free(common);
+       return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+       .magic = HARDWARE_INFO_TAG,
+       .hal_version = HARDWARE_INFO_VERSION,
+       .device_version = DISPLAY_HARDWARE_DEVICE_VERSION,
+       .id = DISPLAY_HARDWARE_DEVICE_ID,
+       .name = "Display",
+       .open = display_open,
+       .close = display_close,
+};
diff --git a/hw/led.c b/hw/led.c
deleted file mode 100644 (file)
index 7486b79..0000000
--- a/hw/led.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * device-node
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <linux/limits.h>
-
-#include <hw/led.h>
-#include "shared.h"
-
-#ifndef CAMERA_BACK_PATH
-#define CAMERA_BACK_PATH       "/sys/class/leds/ktd2692"
-#endif
-
-static int camera_back_set_state(struct led_state *state)
-{
-       static int max = -1;
-       int brt, r;
-
-       if (!state) {
-               _E("wrong parameter");
-               return -EINVAL;
-       }
-
-       if (state->type == LED_TYPE_BLINK) {
-               _E("camera back led does not support LED_TYPE_BLINK mode");
-               return -ENOTSUP;
-       }
-
-       /* if there is a max brightness of led */
-       if (max < 0) {
-               r = sys_get_int(CAMERA_BACK_PATH"/max_brightness", &max);
-               if (r < 0) {
-                       _E("fail to get max brightness : %s", strerror(r));
-                       return r;
-               }
-       }
-
-       brt = (state->color >> 24) & 0xFF;
-       brt = brt / 255.f * max;
-
-       r = sys_set_int(CAMERA_BACK_PATH"/brightness", brt);
-       if (r < 0) {
-               _E("fail to set brightness : %s", strerror(r));
-               return r;
-       }
-
-       return 0;
-}
-
-static int led_open(struct hw_info *info,
-               const char *id, struct hw_common **common)
-{
-       struct led_device *led_dev;
-
-       if (!info || !id || !common)
-               return -EINVAL;
-
-       if (strcmp(id, LED_ID_CAMERA_BACK) != 0)
-               return -ENOTSUP;
-
-       led_dev = calloc(1, sizeof(struct led_device));
-       if (!led_dev)
-               return -ENOMEM;
-
-       led_dev->common.info = info;
-
-       if (!strcmp(id, LED_ID_CAMERA_BACK))
-               led_dev->set_state = camera_back_set_state;
-
-       *common = (struct hw_common *)led_dev;
-       return 0;
-}
-
-static int led_close(struct hw_common *common)
-{
-       if (!common)
-               return -EINVAL;
-
-       free(common);
-       return 0;
-}
-
-HARDWARE_MODULE_STRUCTURE = {
-       .magic = HARDWARE_INFO_TAG,
-       .hal_version = HARDWARE_INFO_VERSION,
-       .device_version = LED_HARDWARE_DEVICE_VERSION,
-       .id = LED_HARDWARE_DEVICE_ID,
-       .name = "Default LED",
-       .author = "Jiyoung Yun <jy910.yun@samsung.com>",
-       .open = led_open,
-       .close = led_close,
-};
diff --git a/hw/led/CMakeLists.txt b/hw/led/CMakeLists.txt
new file mode 100644 (file)
index 0000000..017ddc6
--- /dev/null
@@ -0,0 +1,16 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(led C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog hwcommon)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE led.c ../shared.c)
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/led/led.c b/hw/led/led.c
new file mode 100644 (file)
index 0000000..b7c3e4a
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * device-node
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <linux/limits.h>
+
+#include <hw/led.h>
+#include "../shared.h"
+
+#ifndef CAMERA_BACK_PATH
+#define CAMERA_BACK_PATH       "/sys/class/leds/ktd2692"
+#endif
+
+static int camera_back_set_state(struct led_state *state)
+{
+       static int max = -1;
+       int brt, r;
+
+       if (!state) {
+               _E("wrong parameter");
+               return -EINVAL;
+       }
+
+       if (state->type == LED_TYPE_BLINK) {
+               _E("camera back led does not support LED_TYPE_BLINK mode");
+               return -ENOTSUP;
+       }
+
+       /* if there is a max brightness of led */
+       if (max < 0) {
+               r = sys_get_int(CAMERA_BACK_PATH"/max_brightness", &max);
+               if (r < 0) {
+                       _E("fail to get max brightness : %s", strerror(r));
+                       return r;
+               }
+       }
+
+       brt = (state->color >> 24) & 0xFF;
+       brt = brt / 255.f * max;
+
+       r = sys_set_int(CAMERA_BACK_PATH"/brightness", brt);
+       if (r < 0) {
+               _E("fail to set brightness : %s", strerror(r));
+               return r;
+       }
+
+       return 0;
+}
+
+static int led_open(struct hw_info *info,
+               const char *id, struct hw_common **common)
+{
+       struct led_device *led_dev;
+
+       if (!info || !id || !common)
+               return -EINVAL;
+
+       if (strcmp(id, LED_ID_CAMERA_BACK) != 0)
+               return -ENOTSUP;
+
+       led_dev = calloc(1, sizeof(struct led_device));
+       if (!led_dev)
+               return -ENOMEM;
+
+       led_dev->common.info = info;
+
+       if (!strcmp(id, LED_ID_CAMERA_BACK))
+               led_dev->set_state = camera_back_set_state;
+
+       *common = (struct hw_common *)led_dev;
+       return 0;
+}
+
+static int led_close(struct hw_common *common)
+{
+       if (!common)
+               return -EINVAL;
+
+       free(common);
+       return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+       .magic = HARDWARE_INFO_TAG,
+       .hal_version = HARDWARE_INFO_VERSION,
+       .device_version = LED_HARDWARE_DEVICE_VERSION,
+       .id = LED_HARDWARE_DEVICE_ID,
+       .name = "Default LED",
+       .author = "Jiyoung Yun <jy910.yun@samsung.com>",
+       .open = led_open,
+       .close = led_close,
+};
index 8f7e64866e4e31b32ac3429a872c1e27e957afe6..da51ca48a76140bce44cae0d4c3f4770be9b945e 100644 (file)
@@ -21,7 +21,7 @@
 #define __HW_DEFAULT_SHARED_H__
 
 #define FEATURE_HARDWARE_DLOG
-#ifndef FEATURE_HARDWARE_DLOG
+#ifdef FEATURE_HARDWARE_DLOG
 #define LOG_TAG        "HARDWARE"
 #include <dlog.h>
 #define _I(fmt, args...)       SLOGI(fmt, ##args)
@@ -33,6 +33,8 @@
 #define _E(x, ...)                     do { } while (0)
 #endif
 
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+
 int sys_get_int(char *fname, int *val);
 int sys_get_str(char *fname, char *str, int len);
 int sys_set_int(char *fname, int val);
index 570d53e25dfd20d84669acdf8568d548b22319d4..da0c37269c768d83f2e58d1477a27f217a61a509 100644 (file)
@@ -11,6 +11,8 @@ Requires(postun): /sbin/ldconfig
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(hwcommon)
+BuildRequires:  pkgconfig(x11)
+BuildRequires:  pkgconfig(xext)
 
 %description
 Device manager plugin exynos 5433