diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2015-01-28 19:22:32 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2015-01-28 19:25:56 +0900 |
commit | 779f83e70db8e0a98f3ff0a8a014abbedd04149f (patch) | |
tree | 2fa547e79c959441433de66e6408425d04b66076 | |
parent | 0088728977a4fe2bfb7c6c1304e7940549b5e086 (diff) | |
download | device-manager-plugin-exynos-779f83e70db8e0a98f3ff0a8a014abbedd04149f.tar.gz device-manager-plugin-exynos-779f83e70db8e0a98f3ff0a8a014abbedd04149f.tar.bz2 device-manager-plugin-exynos-779f83e70db8e0a98f3ff0a8a014abbedd04149f.zip |
It support to controll brightness and mode(manual, sensor)
Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
Change-Id: If17d807df3db67442bcb8792d74fdf1f8faaa5aa
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | hw/backlight.c | 157 | ||||
-rw-r--r-- | hw/shared.c | 129 | ||||
-rw-r--r-- | hw/shared.h | 45 | ||||
-rw-r--r-- | packaging/device-manager-plugin-exynos.spec | 2 |
5 files changed, 338 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c51d52f..f336110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_C_FLAGS_RELEASE "-O2") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED devman_plugin) +pkg_check_modules(pkgs REQUIRED devman_plugin hwcommon) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -31,3 +31,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) + +ADD_LIBRARY(backlight MODULE hw/backlight.c hw/shared.c) +SET_TARGET_PROPERTIES(backlight PROPERTIES PREFIX "") +INSTALL(TARGETS backlight DESTINATION lib/hw COMPONENT RuntimeLibraries) diff --git a/hw/backlight.c b/hw/backlight.c new file mode 100644 index 0000000..43763ed --- /dev/null +++ b/hw/backlight.c @@ -0,0 +1,157 @@ +/* + * 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; +} + +EXPORT +struct hw_info HARDWARE_INFO_SYM = { + .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/shared.c b/hw/shared.c new file mode 100644 index 0000000..b6401c1 --- /dev/null +++ b/hw/shared.c @@ -0,0 +1,129 @@ +/* + * 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 <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#define BUF_MAX 255 + +static int sys_read_buf(char *file, char *buf, int len) +{ + int fd, r; + + if (!file || !buf || len < 0) + return -EINVAL; + + fd = open(file, O_RDONLY); + if (fd == -1) + return -ENOENT; + + r = read(fd, buf, len); + close(fd); + if ((r >= 0) && (r < len)) + buf[r] = '\0'; + else + return -EIO; + + return 0; +} + +static int sys_write_buf(char *file, char *buf) +{ + int fd, r; + + if (!file || !buf) + return -EINVAL; + + fd = open(file, O_WRONLY); + if (fd == -1) + return -EPERM; + + r = write(fd, buf, strlen(buf)); + close(fd); + if (r < 0) + return -EIO; + + return 0; +} + +int sys_get_int(char *fname, int *val) +{ + char buf[BUF_MAX]; + int r; + + if (!fname || !val) + return -EINVAL; + + r = sys_read_buf(fname, buf, sizeof(buf)); + if (r < 0) + return r; + + *val = atoi(buf); + return 0; +} + +int sys_get_str(char *fname, char *str, int len) +{ + int r; + + if (!fname || !str || len < 0) + return -EINVAL; + + r = sys_read_buf(fname, str, len); + if (r < 0) + return r; + + return 0; +} + +int sys_set_int(char *fname, int val) +{ + char buf[BUF_MAX]; + int r; + + if (!fname) + return -EINVAL; + + snprintf(buf, sizeof(buf), "%d", val); + r = sys_write_buf(fname, buf); + if (r < 0) + return r; + + return 0; +} + +int sys_set_str(char *fname, char *val) +{ + int r; + + if (!fname || !val) + return -EINVAL; + + r = sys_write_buf(fname, val); + if (r < 0) + return r; + + return 0; +} diff --git a/hw/shared.h b/hw/shared.h new file mode 100644 index 0000000..fdff1ec --- /dev/null +++ b/hw/shared.h @@ -0,0 +1,45 @@ +/* + * 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_DEFAULT_SHARED_H__ +#define __HW_DEFAULT_SHARED_H__ + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +#define FEATURE_HARDWARE_DLOG +#ifndef FEATURE_HARDWARE_DLOG +#define LOG_TAG "HARDWARE" +#include <dlog.h> +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _I(x, ...) do { } while (0) +#define _D(x, ...) do { } while (0) +#define _E(x, ...) do { } while (0) +#endif + +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); +int sys_set_str(char *fname, char *val); + +#endif diff --git a/packaging/device-manager-plugin-exynos.spec b/packaging/device-manager-plugin-exynos.spec index 5a5f797..9784b22 100644 --- a/packaging/device-manager-plugin-exynos.spec +++ b/packaging/device-manager-plugin-exynos.spec @@ -10,6 +10,7 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: cmake BuildRequires: pkgconfig(devman_plugin) +BuildRequires: pkgconfig(hwcommon) %description Device manager plugin exynos @@ -39,4 +40,5 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %files %manifest device-manager-plugin-exynos.manifest /usr/lib/libslp_devman_plugin.so +%{_libdir}/hw/*.so /usr/share/license/%{name} |