summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt21
-rw-r--r--hw/backlight.h59
-rw-r--r--hw/common.c82
-rw-r--r--hw/common.h78
-rw-r--r--hwcommon.pc.in11
-rw-r--r--packaging/libdevice-node.spec1
6 files changed, 251 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 677c5e6..6cfcdaf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}")
SET(VERSION 0.1)
SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR})
INCLUDE(FindPkgConfig)
@@ -25,18 +26,29 @@ SET(HEADERS
include/device-node.h
include/devman_plugin_intf.h)
+SET(HW_HEADERS
+ hw/common.h
+ hw/backlight.h)
+
INCLUDE(devices/CMakeLists.txt)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g")
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror -Wno-unused-variable -Wno-unused-function")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"")
+
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS} "-ldl")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+ADD_LIBRARY(hwcommon SHARED hw/common.c)
+TARGET_LINK_LIBRARIES(hwcommon ${rpkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(hwcommon PROPERTIES SOVERSION ${VERSION})
+INSTALL(TARGETS hwcommon DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+
CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
@@ -47,3 +59,10 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/devman_plugin.pc DESTINATION ${LIB_INS
FOREACH(hfile ${HEADERS})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME})
ENDFOREACH(hfile)
+
+FOREACH(hfile ${HW_HEADERS})
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/hw)
+ENDFOREACH(hfile)
+
+CONFIGURE_FILE(hwcommon.pc.in hwcommon.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hwcommon.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/hw/backlight.h b/hw/backlight.h
new file mode 100644
index 0000000..c795343
--- /dev/null
+++ b/hw/backlight.h
@@ -0,0 +1,59 @@
+/*
+ * libdevice-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.
+ */
+
+
+#ifndef __HW_BACKLIGHT_H__
+#define __HW_BACKLIGHT_H__
+
+#include <hw/common.h>
+
+/**
+ * The id of this device
+ */
+#define BACKLIGHT_HARDWARE_DEVICE_ID "backlight"
+
+/**
+ * The version of this device
+ */
+#define BACKLIGHT_HARDWARE_DEVICE_VERSION MAKE_VERSION(1,0)
+
+/**
+ * The mode of backlight
+ */
+enum backlight_mode {
+ BACKLIGHT_MANUAL, /* Manual setting */
+ BACKLIGHT_SENSOR, /* Worked by sensor */
+};
+
+struct backlight_device {
+ struct hw_common common;
+
+ /**
+ * The brightness value is 0 to 100.
+ */
+ int (*get_brightness)(int *brightness);
+ int (*set_brightness)(int brightness);
+
+ /**
+ * The backlight mode can be BACKLIGHT_MANUAL and BACKLIGHT_SENSOR.
+ */
+ int (*get_mode)(enum backlight_mode *mode);
+ int (*set_mode)(enum backlight_mode mode);
+};
+
+#endif
diff --git a/hw/common.c b/hw/common.c
new file mode 100644
index 0000000..3e2dc7a
--- /dev/null
+++ b/hw/common.c
@@ -0,0 +1,82 @@
+/*
+ * libdevice-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 <unistd.h>
+#include <errno.h>
+#include <dlfcn.h>
+#include <string.h>
+#include <errno.h>
+#include <linux/limits.h>
+
+#include <hw/common.h>
+#include "device-internal.h"
+
+#ifndef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+#endif
+
+#define MODULE_PATH LIBPATH"/hw"
+
+EXPORT
+int hw_get_info(const char *id, const struct hw_info **info)
+{
+ char path[PATH_MAX];
+ void *handle;
+ struct hw_info *it;
+
+ if (!*info || !id)
+ return -EINVAL;
+
+ /* Find matched module path */
+ snprintf(path, sizeof(path), "%s/%s.so", MODULE_PATH, id);
+ if (access(path, R_OK) != 0) {
+ _E("there is no %s device", id);
+ return -ENODEV;
+ }
+
+ /* Load module */
+ handle = dlopen(path, RTLD_NOW);
+ if (!handle) {
+ _E("fail to open module : %s", dlerror());
+ goto error;
+ }
+
+ /* Get the address of struct hw_common */
+ it = dlsym(handle, HARDWARE_INFO_SYM_AS_STR);
+ if (!it) {
+ _E("fail to find symbol : %s", dlerror());
+ goto error;
+ }
+
+ /* Check id */
+ if (strncmp(id, it->id, strlen(id)) != 0) {
+ _E("fail to match id : id(%s), it->id(%s)", id, it->id);
+ goto error;
+ }
+
+ it->dso = handle;
+ *info = it;
+ return 0;
+
+error:
+ if (handle)
+ dlclose(handle);
+
+ return -ENOENT;
+}
diff --git a/hw/common.h b/hw/common.h
new file mode 100644
index 0000000..e14e705
--- /dev/null
+++ b/hw/common.h
@@ -0,0 +1,78 @@
+/*
+ * libdevice-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.
+ */
+
+
+#ifndef __HW_COMMON_H__
+#define __HW_COMMON_H__
+
+#include <stdint.h>
+
+#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
+#define HARDWARE_INFO_TAG MAKE_TAG_CONSTANT('T','H','I','T')
+
+struct hw_common;
+struct hw_info {
+ /* magic must be initialized to HARDWARE_INFO_TAG */
+ uint32_t magic;
+ /* HAL version */
+ uint16_t hal_version;
+ /* device version */
+ uint16_t device_version;
+ /* device id */
+ const char *id;
+ /* device name */
+ const char *name;
+ /* author name */
+ const char *author;
+ /* module's dso */
+ void *dso;
+ /* reserved for future use */
+ uint32_t reserved[8];
+ /* open device */
+ int (*open)(struct hw_info *info,
+ const char *id, struct hw_common **common);
+ /* close device */
+ int (*close)(struct hw_common *common);
+};
+
+struct hw_common {
+ /* indicate to this device information structure */
+ struct hw_info *info;
+};
+
+#define MAKE_VERSION(maj,min) \
+ ((((maj) & 0xff) << 8) | ((min) & 0xff))
+
+/**
+ * Version of the struct hw_info
+ */
+#define HARDWARE_INFO_VERSION MAKE_VERSION(1,0)
+
+/**
+ * Name of the hardware info symbolic (Tizen Hardware Info)
+ */
+#define HARDWARE_INFO_SYM TizenHwInfo
+
+/**
+ * Name of the hardware info symbolic as a string
+ */
+#define HARDWARE_INFO_SYM_AS_STR "TizenHwInfo"
+
+int hw_get_info(const char *id, const struct hw_info **info);
+
+#endif
diff --git a/hwcommon.pc.in b/hwcommon.pc.in
new file mode 100644
index 0000000..b2c8512
--- /dev/null
+++ b/hwcommon.pc.in
@@ -0,0 +1,11 @@
+# Package Information for pkg-config
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=/usr/include
+
+Name: Tizen HAL Interface library
+Description: Tizen HAL Interface library
+Version: @VERSION@
+Libs: -L${libdir} -lhwcommon
+Cflags: -I${includedir}
diff --git a/packaging/libdevice-node.spec b/packaging/libdevice-node.spec
index 5bc68a7..8834ba8 100644
--- a/packaging/libdevice-node.spec
+++ b/packaging/libdevice-node.spec
@@ -41,5 +41,6 @@ make %{?jobs:-j%jobs}
%files devel
%{_includedir}/device-node/*.h
+%{_includedir}/hw/*.h
%{_libdir}/*.so
%{_libdir}/pkgconfig/*.pc