summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-01-16 18:59:38 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2015-01-28 19:21:45 +0900
commit49382d9cf904c83fd14d423f5b440c366bd2daa4 (patch)
tree02863a2932b91e8e96f2b306141a044fc5ca0eaa /hw
parent04fd20f5a06355fc0afe110337ccb9dc7445ad1d (diff)
downloadlibdevice-node-49382d9cf904c83fd14d423f5b440c366bd2daa4.tar.gz
libdevice-node-49382d9cf904c83fd14d423f5b440c366bd2daa4.tar.bz2
libdevice-node-49382d9cf904c83fd14d423f5b440c366bd2daa4.zip
device-node: Add HAL common and backlight structures
Each device shuld be contained struct hw_info_t module as a first variable. It is a common interface among multiple device HAL structures. Backlight HAL structure is for controlling the brightness of backlight. You can set the birhgntess value using it and it also support to sensor mode. It makes backlight display to be changed by light sensor value. Developers can make their own HAL structure. The HAL library should be located in $LIB_INSTALL_DIR/hw/. There is an detail information in Tizen Wiki: https://wiki.tizen.org/wiki/HAL_upgrade_for_Tizen_3.0#Device Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com> Change-Id: Id73f5517e659a652a634cfa86c3137f5aca859c7
Diffstat (limited to 'hw')
-rw-r--r--hw/backlight.h59
-rw-r--r--hw/common.c82
-rw-r--r--hw/common.h78
3 files changed, 219 insertions, 0 deletions
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