From ce8c7a4db57feffe888a1c7f23af34e66fdbe4f9 Mon Sep 17 00:00:00 2001 From: KwangCheol Lee Date: Tue, 27 Jun 2017 12:20:55 +0900 Subject: [PATCH 02/15] Add Display HAL and Touchscreen HAL - Removed unused files: battery, external_connection, usb_client and usb_gadget - Removed unnecessary lines. - Removed whitespaces. - Remove redundant lines in CMakeLists.txt file. - Remove unnecessary line in spec file. Change-Id: I2074a4b1916110480b3d0ae272077b2380053d74 --- CMakeLists.txt | 7 + LICENSE | 202 +++++++++++++++++ hw/display/CMakeLists.txt | 19 ++ hw/display/display.c | 132 ++++++++++++ hw/shared.c | 129 +++++++++++ hw/shared.h | 43 ++++ hw/touchscreen/CMakeLists.txt | 19 ++ hw/touchscreen/touchscreen.c | 226 +++++++++++++++++++ hw/udev.c | 298 ++++++++++++++++++++++++++ hw/udev.h | 43 ++++ packaging/device-manager-plugin-rpi3.manifest | 5 + packaging/device-manager-plugin-rpi3.spec | 41 ++++ 12 files changed, 1164 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 hw/display/CMakeLists.txt create mode 100644 hw/display/display.c create mode 100644 hw/shared.c create mode 100644 hw/shared.h create mode 100644 hw/touchscreen/CMakeLists.txt create mode 100644 hw/touchscreen/touchscreen.c create mode 100644 hw/udev.c create mode 100644 hw/udev.h create mode 100644 packaging/device-manager-plugin-rpi3.manifest create mode 100755 packaging/device-manager-plugin-rpi3.spec diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2c6ef89 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(device-manager-rpi3 C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +ADD_SUBDIRECTORY(hw/display) +ADD_SUBDIRECTORY(hw/touchscreen) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fef8c29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt new file mode 100644 index 0000000..ebccfbe --- /dev/null +++ b/hw/display/CMakeLists.txt @@ -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) + +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 index 0000000..4c93d25 --- /dev/null +++ b/hw/display/display.c @@ -0,0 +1,132 @@ +/* + * 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 +#include +#include +#include +#include + +#include +#include "../shared.h" + +#ifndef BACKLIGHT_PATH +#define BACKLIGHT_PATH "/sys/class/backlight/rpi_backlight" +#endif + +static int display_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 (errno:%d)", r); + return r; + } + + *brightness = v; + return 0; +} + +static int display_set_brightness(int brightness) +{ + int r, max; + + r = display_get_max_brightness(&max); + if (r < 0) { + _E("fail to get max brightness (errno:%d)", r); + return r; + } + + if (brightness < 0 || brightness > max) { + _E("wrong parameter"); + return -EINVAL; + } + + r = sys_set_int(BACKLIGHT_PATH"/brightness", brightness); + if (r < 0) { + _E("fail to set brightness (errno:%d)", 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_max_brightness = display_get_max_brightness; + 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; +} + +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/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 +#include +#include +#include +#include +#include +#include +#include + +#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..da51ca4 --- /dev/null +++ b/hw/shared.h @@ -0,0 +1,43 @@ +/* + * 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__ + +#define FEATURE_HARDWARE_DLOG +#ifdef FEATURE_HARDWARE_DLOG +#define LOG_TAG "HARDWARE" +#include +#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 + +#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); +int sys_set_str(char *fname, char *val); + +#endif diff --git a/hw/touchscreen/CMakeLists.txt b/hw/touchscreen/CMakeLists.txt new file mode 100644 index 0000000..b097615 --- /dev/null +++ b/hw/touchscreen/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(touchscreen C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(touchscreen_pkgs REQUIRED hwcommon dlog) + +FOREACH(flag ${touchscreen_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 touchscreen.c ../shared.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${touchscreen_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c new file mode 100644 index 0000000..3f25986 --- /dev/null +++ b/hw/touchscreen/touchscreen.c @@ -0,0 +1,226 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../shared.h" + +#define TURNON_TOUCHSCREEN 1 +#define TURNOFF_TOUCHSCREEN 0 + +#define MODULES_FILE_NAME "/proc/modules" +#define MODULE_KO_NAME "rpi-ft5406.ko" +#define MODULE_NAME "rpi_ft5406" + +#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) +#define delete_module(name, flags) syscall(__NR_delete_module, name, flags) + +static int find_module(char *name) +{ + FILE *fp = fopen(MODULES_FILE_NAME, "rt"); + if (fp == NULL) { + _E("Can not open file(%s).\n", MODULES_FILE_NAME); + return -ENOENT; + } + + int found = 0; + char mod_str[256]; + char mod_name[256]; + for (; fgets(mod_str, sizeof(mod_str), fp); ) { + sscanf(mod_str, "%s ", mod_name); + if (strcmp(mod_name, name) == 0) { + _E("[%s]\t%s", mod_name, mod_str); + found = 1; + break; + } + } + + fclose(fp); + + return found; +} + +static int get_module_path(char *name, char *path) +{ + struct utsname utsn; + + int ret = uname(&utsn); + if (ret != 0) + return ret; + + sprintf(path, "/lib/modules/%s/%s", utsn.release, name); + + return 0; +} + +static int ins_module(char *name) +{ + char path[512]; + + if (get_module_path(name, path) != 0) + return -EEXIST; + + int fd = open(path, O_RDONLY); + if (fd < 0) { + _E("Can not open module(%s).\n", path); + return -EEXIST; + } + + struct stat st; + int ret = fstat(fd, &st); + if (ret < 0) { + _E("Module fstat error(%s).\n", path); + close(fd); + return -EIO; + } + + size_t image_size = st.st_size; + void *image = malloc(image_size); + if (image == NULL) { + _E("Memory allocation errorr.\n"); + close(fd); + return -ENOMEM; + } + + ssize_t size = read(fd, image, image_size); + if (size != image_size) { + _E("Module file read error(%d).\n", size); + free(image); + close(fd); + return -EIO; + } + close(fd); + + ret = init_module(image, image_size, ""); + if (ret < 0) { + _E("init_module error(%d).\n", ret); + free(image); + return -EIO; + } + free(image); + + return 0; +} + +static int rm_module(char *name) +{ + int ret = delete_module(name, O_NONBLOCK); + if (ret != 0) { + _E("delete_module error(%d).\n", ret); + return -EIO; + } + + return 0; +} + + +static int touchscreen_get_state(enum touchscreen_state *state) +{ + int ret; + + if (!state) + return -EINVAL; + + ret = find_module(MODULE_NAME); + if (ret < 0) { + _E("Failed to get touchscreen state (%d)", ret); + return ret; + } + + switch (ret) { + case TURNOFF_TOUCHSCREEN: + *state = TOUCHSCREEN_OFF; + break; + case TURNON_TOUCHSCREEN: + *state = TOUCHSCREEN_ON; + break; + } + + return 0; +} + +static int touchscreen_set_state(enum touchscreen_state state) +{ + int ret = 0; + + switch (state) { + case TOUCHSCREEN_OFF: + ret = rm_module(MODULE_NAME); + break; + case TOUCHSCREEN_ON: + ret = ins_module(MODULE_KO_NAME); + break; + default: + _E("Invalid input (%d)", state); + return -EINVAL; + } + + return ret; +} + +static int touchscreen_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct touchscreen_device *touchscreen_dev; + + if (!info || !common) + return -EINVAL; + + touchscreen_dev = calloc(1, sizeof(struct touchscreen_device)); + if (!touchscreen_dev) + return -ENOMEM; + + touchscreen_dev->common.info = info; + touchscreen_dev->get_state = touchscreen_get_state; + touchscreen_dev->set_state = touchscreen_set_state; + + *common = (struct hw_common *)touchscreen_dev; + return 0; +} + +static int touchscreen_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 = TOUCHSCREEN_HARDWARE_DEVICE_VERSION, + .id = TOUCHSCREEN_HARDWARE_DEVICE_ID, + .name = "touchscreen", + .open = touchscreen_open, + .close = touchscreen_close, +}; diff --git a/hw/udev.c b/hw/udev.c new file mode 100644 index 0000000..562725b --- /dev/null +++ b/hw/udev.c @@ -0,0 +1,298 @@ +/* + * device-manager + * + * 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 +#include +#include +#include +#include +#include +#include "shared.h" +#include "udev.h" + +#define EVENT_KERNEL "kernel" +#define EVENT_UDEV "udev" + +#define UDEV_MONITOR_SIZE (10*1024) + +struct uevent_info { + struct udev_monitor *mon; + GIOChannel *ch; + guint eventid; + GList *event_list; +}; + + +/* Uevent */ +static struct udev *udev; +static struct uevent_info kevent; /* kernel */ +static struct uevent_info uevent; /* udev */ + +static gboolean uevent_control_cb(GIOChannel *channel, + GIOCondition cond, void *data) +{ + struct uevent_info *info = data; + struct udev_device *dev; + struct uevent_handler *l; + GList *elem; + const char *subsystem; + int len; + + if (!info) { + _E("data is invalid"); + return TRUE; + } + + dev = udev_monitor_receive_device(info->mon); + if (!dev) + return TRUE; + + subsystem = udev_device_get_subsystem(dev); + if (!subsystem) + goto out; + + len = strlen(subsystem); + + for (elem = info->event_list ; elem ; elem = g_list_next(elem)) { + l = elem->data; + if (!l) + continue; + if (!strncmp(l->subsystem, subsystem, len) && + l->uevent_func) + l->uevent_func(dev); + } + +out: + udev_device_unref(dev); + return TRUE; +} + +static int uevent_control_stop(struct uevent_info *info) +{ + struct udev_device *dev; + + if (!info) + return -EINVAL; + + if (info->eventid) { + g_source_remove(info->eventid); + info->eventid = 0; + } + if (info->ch) { + g_io_channel_unref(info->ch); + info->ch = NULL; + } + if (info->mon) { + dev = udev_monitor_receive_device(info->mon); + if (dev) + udev_device_unref(dev); + udev_monitor_unref(info->mon); + info->mon = NULL; + } + if (udev) + udev = udev_unref(udev); + return 0; +} + +static int uevent_control_start(const char *type, + struct uevent_info *info) +{ + struct uevent_handler *l; + GList *elem; + int fd; + int ret; + + if (!info) + return -EINVAL; + + if (info->mon) { + _E("%s uevent control routine is alreay started", type); + return -EINVAL; + } + + if (!udev) { + udev = udev_new(); + if (!udev) { + _E("error create udev"); + return -EINVAL; + } + } else + udev = udev_ref(udev); + + info->mon = udev_monitor_new_from_netlink(udev, type); + if (info->mon == NULL) { + _E("error udev_monitor create"); + goto stop; + } + + ret = udev_monitor_set_receive_buffer_size(info->mon, + UDEV_MONITOR_SIZE); + if (ret != 0) { + _E("fail to set receive buffer size"); + goto stop; + } + + for (elem = info->event_list ; elem ; elem = g_list_next(elem)) { + l = elem->data; + ret = udev_monitor_filter_add_match_subsystem_devtype( + info->mon, + l->subsystem, NULL); + if (ret < 0) { + _E("error apply subsystem filter"); + goto stop; + } + } + + ret = udev_monitor_filter_update(info->mon); + if (ret < 0) + _E("error udev_monitor_filter_update"); + + fd = udev_monitor_get_fd(info->mon); + if (fd == -1) { + _E("error udev_monitor_get_fd"); + goto stop; + } + + info->ch = g_io_channel_unix_new(fd); + info->eventid = g_io_add_watch(info->ch, + G_IO_IN, uevent_control_cb, info); + if (info->eventid == 0) { + _E("Failed to add channel watch"); + goto stop; + } + + if (udev_monitor_enable_receiving(info->mon) < 0) { + _E("error unable to subscribe to udev events"); + goto stop; + } + + return 0; +stop: + uevent_control_stop(info); + return -EINVAL; +} + +int uevent_control_kernel_start(void) +{ + return uevent_control_start(EVENT_KERNEL, &kevent); +} + +void uevent_control_kernel_stop(void) +{ + uevent_control_stop(&kevent); +} + +int uevent_control_udev_start(void) +{ + return uevent_control_start(EVENT_UDEV, &uevent); +} + +void uevent_control_udev_stop(void) +{ + uevent_control_stop(&uevent); +} + +static int register_uevent_control(struct uevent_info *info, + struct uevent_handler *uh) +{ + struct uevent_handler *l; + GList *elem; + int r; + bool matched = false; + int len; + + if (!info || !uh || !uh->subsystem) + return -EINVAL; + + /* if udev is not initialized, it just will be added list */ + if (!udev || !info->mon) + goto add_list; + + len = strlen(uh->subsystem); + /* check if the same subsystem is already added */ + for (elem = info->event_list; elem ; elem = g_list_next(elem)) { + l = elem->data; + if (!strncmp(l->subsystem, uh->subsystem, len)) { + matched = true; + break; + } + } + + /* the first request to add subsystem */ + if (!matched) { + r = udev_monitor_filter_add_match_subsystem_devtype(info->mon, + uh->subsystem, NULL); + if (r < 0) { + _E("fail to add %s subsystem : %d", uh->subsystem, r); + return -EPERM; + } + } + + r = udev_monitor_filter_update(info->mon); + if (r < 0) + _E("fail to update udev monitor filter : %d", r); + +add_list: + info->event_list = g_list_append(info->event_list, uh); + return 0; +} + +static int unregister_uevent_control(struct uevent_info *info, + const struct uevent_handler *uh) +{ + struct uevent_handler *l; + GList *n, *next; + int len; + + if (!info || !uh || !uh->subsystem) + return -EINVAL; + + len = strlen(uh->subsystem); + for (n = info->event_list, next = g_list_next(n) ; + n ; n = next, next = g_list_next(n)) { + l = n->data; + if (!strncmp(l->subsystem, uh->subsystem, len) && + l->uevent_func == uh->uevent_func) { + info->event_list = g_list_delete_link(info->event_list, n); + return 0; + } + } + + return -ENOENT; +} + +int register_kernel_event_control(struct uevent_handler *uh) +{ + return register_uevent_control(&kevent, uh); +} + +void unregister_kernel_event_control(struct uevent_handler *uh) +{ + unregister_uevent_control(&kevent, uh); +} + +int register_udev_event_control(struct uevent_handler *uh) +{ + return register_uevent_control(&uevent, uh); +} + +void unregister_udev_event_control(struct uevent_handler *uh) +{ + unregister_uevent_control(&uevent, uh); +} diff --git a/hw/udev.h b/hw/udev.h new file mode 100644 index 0000000..d2aeff1 --- /dev/null +++ b/hw/udev.h @@ -0,0 +1,43 @@ +/* + * device-manager + * + * 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 __UDEV_H__ +#define __UDEV_H__ + +#include + +struct uevent_handler { + const char *subsystem; + void (*uevent_func)(struct udev_device *dev); + void *data; +}; + +int uevent_control_kernel_start(void); +void uevent_control_kernel_stop(void); + +int uevent_control_udev_start(void); +void uevent_control_udev_stop(void); + +int register_kernel_event_control(struct uevent_handler *uh); +void unregister_kernel_event_control(struct uevent_handler *uh); + +int register_udev_event_control(struct uevent_handler *uh); +void unregister_udev_event_control(struct uevent_handler *uh); + +#endif /* __UDEV_H__ */ diff --git a/packaging/device-manager-plugin-rpi3.manifest b/packaging/device-manager-plugin-rpi3.manifest new file mode 100644 index 0000000..af9b883 --- /dev/null +++ b/packaging/device-manager-plugin-rpi3.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec new file mode 100755 index 0000000..0f9c9c5 --- /dev/null +++ b/packaging/device-manager-plugin-rpi3.spec @@ -0,0 +1,41 @@ +Name: device-manager-plugin-rpi3 +Summary: Device manager plugin rpi3 +Version: 0.0.1 +Release: 0 +Group: System/Hardware Adaptation +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(hwcommon) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(libudev) + +%description +Device manager plugin Raspberry Pi 3 + +%prep +%setup -q +cp %{SOURCE1} . + +%build +%cmake . + +make %{?jobs:-j%jobs} + +%install +%make_install + +%post +/sbin/ldconfig + +%postun +/sbin/ldconfig + +%files +%{_libdir}/hw/*.so +%manifest %{name}.manifest +%license LICENSE -- 2.7.4 From 3108c701b6cd662d170bc092e5ed51c1b09f9449 Mon Sep 17 00:00:00 2001 From: scott park Date: Wed, 19 Jul 2017 20:07:44 +0900 Subject: [PATCH 03/15] led: Add LED HAL interface for RPI3 blinkm led device This is the initial implementation of LED HAL using PIO interface. The implemeted API is set_state. Change-Id: Ie8438a3133498b9726130363c6491930dbefdf92 Signed-off-by: scott park --- CMakeLists.txt | 1 + hw/led/CMakeLists.txt | 20 ++ hw/led/led.c | 374 ++++++++++++++++++++++++++++++ packaging/device-manager-plugin-rpi3.spec | 1 + 4 files changed, 396 insertions(+) create mode 100644 hw/led/CMakeLists.txt create mode 100644 hw/led/led.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c6ef89..b7983c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,4 +4,5 @@ PROJECT(device-manager-rpi3 C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) ADD_SUBDIRECTORY(hw/display) +ADD_SUBDIRECTORY(hw/led) ADD_SUBDIRECTORY(hw/touchscreen) diff --git a/hw/led/CMakeLists.txt b/hw/led/CMakeLists.txt new file mode 100644 index 0000000..6acfd7b --- /dev/null +++ b/hw/led/CMakeLists.txt @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(led C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(led_pkgs REQUIRED hwcommon dlog glib-2.0 capi-system-peripheral-io) + +FOREACH(flag ${led_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) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${led_pkgs_LDFLAGS}) +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 index 0000000..971316f --- /dev/null +++ b/hw/led/led.c @@ -0,0 +1,374 @@ +/* + * device-manager-plugin-rpi3 + * + * Copyright (c) 2017 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 +#include +#include + +#include +#include "../shared.h" + +#include + +#define GET_BRIGHTNESS(val) (((val) >> 24) & 0xFF) + +#define GET_TYPE(a) (((a) >> 24) & 0xFF) +#define GET_RED_ONLY(a) ((a) & 0xFF0000) +#define GET_GREEN_ONLY(a) ((a) & 0x00FF00) +#define GET_BLUE_ONLY(a) ((a) & 0x0000FF) +#define GET_RED_BRT(a) (uint8_t)(((a) >> 16) & 0xFF) +#define GET_GREEN_BRT(a) (uint8_t)(((a) >> 8) & 0xFF) +#define GET_BLUE_BRT(a) (uint8_t)((a) & 0xFF) + +/** + * GPIO Specific + */ +#define GPIO_I2C_BUS_INDEX 1 +#define BLINKM_DEFAULT_ADDR 0x09 + +/** + * LED operation command code + * Stop script: 0x6f('o') + * Set command: 0x6e('n') + * Change address command: 0x41('A') + */ +#define SET_CMD_CODE 0x6e +#define STOP_SCRIPT_CMD 0x6f +#define CHANGE_ADDR_CMD 0x41 + +typedef enum _led_rgb_type { + LED_RED, + LED_GREEN, + LED_BLUE, +} led_rgb_type_e; + +struct gpio_rgb_play_color_info { + unsigned int color; + int time; +}; + +struct gpio_rgb_play_info { + GList *play_list; + int nr_play; + int index; + guint timer; +} play_info; + +static uint8_t off_cmd[4] = { SET_CMD_CODE, 0x00, 0x00, 0x00 }; + +static void blinkm_led_stop_script(peripheral_i2c_h handle) +{ + peripheral_i2c_write_byte(handle, STOP_SCRIPT_CMD); +} + +/** + * LED set to black + */ +static void blinkm_led_off(peripheral_i2c_h handle) +{ + peripheral_i2c_write(handle, off_cmd, sizeof(off_cmd)); +} + +static void blinkm_led_init(peripheral_i2c_h handle) +{ + blinkm_led_stop_script(handle); + blinkm_led_off(handle); +} + +static void blinkm_led_set_color(peripheral_i2c_h handle, uint8_t *pkt_data, int len) +{ + peripheral_i2c_write(handle, pkt_data, len); +} + +static int gpio_led_open_device(int device_index, peripheral_i2c_h *device_handle) +{ + int ret; + + if ((ret = peripheral_i2c_open(device_index, BLINKM_DEFAULT_ADDR, device_handle)) < PERIPHERAL_ERROR_NONE) { + _E("Failed to open I2C"); + } + return ret; +} + +static int gpio_led_close_device(peripheral_i2c_h device_handle) +{ + int ret; + + if ((ret = peripheral_i2c_close(device_handle)) < PERIPHERAL_ERROR_NONE) { + _E("Failed to close I2C"); + } + return ret; +} + +static int gpio_rgb_set_brightness(struct led_state *state) +{ + uint8_t cmd_pkt[4] = { SET_CMD_CODE, }; + peripheral_i2c_h handle; + unsigned int color; + int ret; + + if (!state) + return -EINVAL; + + color = state->color; + + cmd_pkt[1] = GET_RED_BRT(color); + cmd_pkt[2] = GET_GREEN_BRT(color); + cmd_pkt[3] = GET_BLUE_BRT(color); + + _I("COLOR(%x) r(%x), g(%x), b(%x)", color, cmd_pkt[1], cmd_pkt[2], cmd_pkt[3]); + + if ((ret = gpio_led_open_device(GPIO_I2C_BUS_INDEX, &handle)) < PERIPHERAL_ERROR_NONE) + return -EIO; + + blinkm_led_set_color(handle, cmd_pkt, sizeof(cmd_pkt)); + + if ((ret = gpio_led_close_device(handle)) < PERIPHERAL_ERROR_NONE) + return -EIO; + + return 0; +} + +/* turn off led */ +static int gpio_rgb_turn_off(struct led_state *state) +{ + struct led_state st = { LED_TYPE_MANUAL, }; + return gpio_rgb_set_brightness(&st); +} + +/* release play list */ +static void free_func(gpointer data) +{ + struct gpio_rgb_play_color_info *color = data; + free(color); +} + +static void release_play_info(void) +{ + if (play_info.play_list) { + g_list_free_full(play_info.play_list, free_func); + play_info.play_list = NULL; + } + play_info.nr_play = 0; + play_info.index = 0; + if (play_info.timer) { + g_source_remove(play_info.timer); + play_info.timer = 0; + } + + gpio_rgb_turn_off(NULL); +} + +static int gpio_rgb_init_led() +{ + peripheral_i2c_h handle; + int ret; + + if ((ret = gpio_led_open_device(GPIO_I2C_BUS_INDEX, &handle)) < PERIPHERAL_ERROR_NONE) + return ret; + + blinkm_led_init(handle); + + if ((ret = gpio_led_close_device(handle)) < PERIPHERAL_ERROR_NONE) + return ret; + + return ret; +} + +/* timer callback to change colors which are stored in play_list */ +static gboolean gpio_rgb_timer_expired(gpointer data) +{ + struct gpio_rgb_play_color_info *color; + struct led_state state = {LED_TYPE_MANUAL, }; + int ret; + + if (play_info.timer) { + g_source_remove(play_info.timer); + play_info.timer = 0; + } + + color = g_list_nth_data(play_info.play_list, play_info.index); + if (!color) { + _E("Failed to get (%d)th item from the play list", play_info.index); + goto out; + } + + play_info.timer = g_timeout_add(color->time, gpio_rgb_timer_expired, data); + if (play_info.timer == 0) { + _E("Failed to add timeout for LED blinking"); + goto out; + } + + state.color = color->color; + + ret = gpio_rgb_set_brightness(&state); + if (ret < 0) { + _E("Failed to set brightness (%d)", ret); + goto out; + } + + play_info.index++; + if (play_info.index == play_info.nr_play) + play_info.index = 0; + + return G_SOURCE_CONTINUE; + +out: + release_play_info(); + + return G_SOURCE_REMOVE; +} + +/* insert color info to the play_list */ +static int gpio_rgb_insert_play_list(unsigned color, int on, int off) +{ + struct gpio_rgb_play_color_info *on_info, *off_info; + + if (color == 0) + return -EINVAL; + on_info = calloc(1, sizeof(struct gpio_rgb_play_color_info)); + if (!on_info) + return -ENOMEM; + off_info = calloc(1, sizeof(struct gpio_rgb_play_color_info)); + if (!off_info) { + free(on_info); + return -ENOMEM; + } + + on_info->color = color; + on_info->time = on; + play_info.play_list = g_list_append(play_info.play_list, on_info); + + off_info->color = 0; + off_info->time = off; + play_info.play_list = g_list_append(play_info.play_list, off_info); + + return 0; +} + +/* insert color info to the play list and start to play */ +static int gpio_rgb_set_brightness_blink(struct led_state *state) +{ + unsigned int val; + int ret; + + val = GET_RED_ONLY(state->color); + if (val) { + ret = gpio_rgb_insert_play_list(val, state->duty_on, state->duty_off); + if (ret < 0) + _E("Failed to insert color info to list (%d)", ret); + } + val = GET_GREEN_ONLY(state->color); + if (val) { + ret = gpio_rgb_insert_play_list(val, state->duty_on, state->duty_off); + if (ret < 0) + _E("Failed to insert color info to list (%d)", ret); + } + val = GET_BLUE_ONLY(state->color); + if (val) { + ret = gpio_rgb_insert_play_list(val, state->duty_on, state->duty_off); + if (ret < 0) + _E("Failed to insert color info to list (%d)", ret); + } + + play_info.nr_play = g_list_length(play_info.play_list); + play_info.index = 0; + + gpio_rgb_timer_expired(NULL); + return 0; +} + +static int gpio_rgb_turn_on(struct led_state *state) +{ + if (state->type == LED_TYPE_MANUAL) + return gpio_rgb_set_brightness(state); + + return gpio_rgb_set_brightness_blink(state); +} + +static int gpio_rgb_set_state(struct led_state *state) +{ + if (!state) + return -EINVAL; + + switch (state->type) { + case LED_TYPE_BLINK: + case LED_TYPE_MANUAL: + break; + default: + _E("Not suppoted type (%d)", state->type); + return -ENOTSUP; + } + release_play_info(); + + if (GET_TYPE(state->color) == 0) + return gpio_rgb_turn_off(state); + + return gpio_rgb_turn_on(state); +} + +static int led_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct led_device *led_dev; + size_t len; + + if (!info || !id || !common) + return -EINVAL; + + led_dev = calloc(1, sizeof(struct led_device)); + if (!led_dev) + return -ENOMEM; + + led_dev->common.info = info; + + len = strlen(id) + 1; + if (!strncmp(id, LED_ID_NOTIFICATION, len)) { + if (gpio_rgb_init_led()) { + free(led_dev); + return -EIO; + } else + led_dev->set_state = gpio_rgb_set_state; + + } else { + free(led_dev); + return -ENOTSUP; + } + + *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 = "I2C RGB LED", + .open = led_open, + .close = led_close, +}; diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec index 0f9c9c5..d56e803 100755 --- a/packaging/device-manager-plugin-rpi3.spec +++ b/packaging/device-manager-plugin-rpi3.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(hwcommon) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libudev) +BuildRequires: pkgconfig(capi-system-peripheral-io) %description Device manager plugin Raspberry Pi 3 -- 2.7.4 From 2d6c367dfb31e3a1c16436b3acd6bdc0d4cd9d35 Mon Sep 17 00:00:00 2001 From: KwangCheol Lee Date: Wed, 13 Sep 2017 19:53:04 +0900 Subject: [PATCH 04/15] touchscreen: control interface change to sysfs The control interface of touchscreen is changed from the kernel module loading/unloading to sysfs enable interface. Version changed to 0.0.2 Change-Id: Ifab000c27b17638ba1cf69583ab2fe79f49a1f4e Signed-off-by: KwangCheol Lee (cherry picked from commit 8d690c714b2544c11410ab7b41c10fe150a28821) --- hw/touchscreen/touchscreen.c | 159 ++++++------------------------ packaging/device-manager-plugin-rpi3.spec | 2 +- 2 files changed, 30 insertions(+), 131 deletions(-) mode change 100644 => 100755 hw/touchscreen/touchscreen.c diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c old mode 100644 new mode 100755 index 3f25986..8cae686 --- a/hw/touchscreen/touchscreen.c +++ b/hw/touchscreen/touchscreen.c @@ -23,145 +23,39 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include #include "../shared.h" +#define TOUCHSCREEN_CON_FILE "/sys/devices/platform/rpi_ft5406/enable" + #define TURNON_TOUCHSCREEN 1 #define TURNOFF_TOUCHSCREEN 0 -#define MODULES_FILE_NAME "/proc/modules" -#define MODULE_KO_NAME "rpi-ft5406.ko" -#define MODULE_NAME "rpi_ft5406" - -#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) -#define delete_module(name, flags) syscall(__NR_delete_module, name, flags) - -static int find_module(char *name) -{ - FILE *fp = fopen(MODULES_FILE_NAME, "rt"); - if (fp == NULL) { - _E("Can not open file(%s).\n", MODULES_FILE_NAME); - return -ENOENT; - } - - int found = 0; - char mod_str[256]; - char mod_name[256]; - for (; fgets(mod_str, sizeof(mod_str), fp); ) { - sscanf(mod_str, "%s ", mod_name); - if (strcmp(mod_name, name) == 0) { - _E("[%s]\t%s", mod_name, mod_str); - found = 1; - break; - } - } - - fclose(fp); - - return found; -} - -static int get_module_path(char *name, char *path) -{ - struct utsname utsn; - - int ret = uname(&utsn); - if (ret != 0) - return ret; - - sprintf(path, "/lib/modules/%s/%s", utsn.release, name); - - return 0; -} - -static int ins_module(char *name) -{ - char path[512]; - - if (get_module_path(name, path) != 0) - return -EEXIST; - - int fd = open(path, O_RDONLY); - if (fd < 0) { - _E("Can not open module(%s).\n", path); - return -EEXIST; - } - - struct stat st; - int ret = fstat(fd, &st); - if (ret < 0) { - _E("Module fstat error(%s).\n", path); - close(fd); - return -EIO; - } - - size_t image_size = st.st_size; - void *image = malloc(image_size); - if (image == NULL) { - _E("Memory allocation errorr.\n"); - close(fd); - return -ENOMEM; - } - - ssize_t size = read(fd, image, image_size); - if (size != image_size) { - _E("Module file read error(%d).\n", size); - free(image); - close(fd); - return -EIO; - } - close(fd); - - ret = init_module(image, image_size, ""); - if (ret < 0) { - _E("init_module error(%d).\n", ret); - free(image); - return -EIO; - } - free(image); - - return 0; -} - -static int rm_module(char *name) -{ - int ret = delete_module(name, O_NONBLOCK); - if (ret != 0) { - _E("delete_module error(%d).\n", ret); - return -EIO; - } - - return 0; -} - - static int touchscreen_get_state(enum touchscreen_state *state) { int ret; + int val; if (!state) return -EINVAL; - ret = find_module(MODULE_NAME); + ret = sys_get_int(TOUCHSCREEN_CON_FILE, &val); if (ret < 0) { _E("Failed to get touchscreen state (%d)", ret); return ret; } - switch (ret) { - case TURNOFF_TOUCHSCREEN: - *state = TOUCHSCREEN_OFF; - break; - case TURNON_TOUCHSCREEN: - *state = TOUCHSCREEN_ON; - break; + switch (val) { + case TURNOFF_TOUCHSCREEN: + *state = TOUCHSCREEN_OFF; + break; + case TURNON_TOUCHSCREEN: + *state = TOUCHSCREEN_ON; + break; + default: + _E("Failed to get touchscreen state (%d)", val); + return -EINVAL; } return 0; @@ -169,20 +63,25 @@ static int touchscreen_get_state(enum touchscreen_state *state) static int touchscreen_set_state(enum touchscreen_state state) { - int ret = 0; + int ret; + int val; switch (state) { - case TOUCHSCREEN_OFF: - ret = rm_module(MODULE_NAME); - break; - case TOUCHSCREEN_ON: - ret = ins_module(MODULE_KO_NAME); - break; - default: - _E("Invalid input (%d)", state); - return -EINVAL; + case TOUCHSCREEN_OFF: + val = TURNOFF_TOUCHSCREEN; + break; + case TOUCHSCREEN_ON: + val = TURNON_TOUCHSCREEN; + break; + default: + _E("Invalid input (%d)", state); + return -EINVAL; } + ret = sys_set_int(TOUCHSCREEN_CON_FILE, val); + if (ret < 0) + _E("Failed to change touchscreen state (%d)", ret); + return ret; } diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec index d56e803..840044d 100755 --- a/packaging/device-manager-plugin-rpi3.spec +++ b/packaging/device-manager-plugin-rpi3.spec @@ -1,6 +1,6 @@ Name: device-manager-plugin-rpi3 Summary: Device manager plugin rpi3 -Version: 0.0.1 +Version: 0.0.2 Release: 0 Group: System/Hardware Adaptation License: Apache-2.0 -- 2.7.4 From e0013ac168a3247f59805d093980edc4d2df484f Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Wed, 27 Sep 2017 14:13:06 +0900 Subject: [PATCH 05/15] udev: Increase udev monitor buffer size Signed-off-by: INSUN PYO Change-Id: I370ef29250c1b640af15fd2ef094eeef4a47fba3 --- hw/udev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/udev.c b/hw/udev.c index 562725b..a30204b 100644 --- a/hw/udev.c +++ b/hw/udev.c @@ -29,7 +29,7 @@ #define EVENT_KERNEL "kernel" #define EVENT_UDEV "udev" -#define UDEV_MONITOR_SIZE (10*1024) +#define UDEV_MONITOR_SIZE (128*1024) struct uevent_info { struct udev_monitor *mon; @@ -59,6 +59,7 @@ static gboolean uevent_control_cb(GIOChannel *channel, return TRUE; } + _I("Set udev monitor buffer size %d", UDEV_MONITOR_SIZE); dev = udev_monitor_receive_device(info->mon); if (!dev) return TRUE; -- 2.7.4 From d674319293b80d159f26a016716a30a206450f5e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 27 Jun 2018 11:30:36 +0900 Subject: [PATCH 06/15] Modify blinkm_led_stop_script peripherial_i2c_byte_write() was removed, So replaced it with peripherial_i2c_write(). Change-Id: If67f2b0fc03effbfd4e87d8c5a0737a581e1dfa6 Signed-off-by: lokilee73 --- hw/led/led.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) mode change 100644 => 100755 hw/led/led.c diff --git a/hw/led/led.c b/hw/led/led.c old mode 100644 new mode 100755 index 971316f..d7f0b39 --- a/hw/led/led.c +++ b/hw/led/led.c @@ -73,7 +73,10 @@ static uint8_t off_cmd[4] = { SET_CMD_CODE, 0x00, 0x00, 0x00 }; static void blinkm_led_stop_script(peripheral_i2c_h handle) { - peripheral_i2c_write_byte(handle, STOP_SCRIPT_CMD); + uint8_t data[1] = {STOP_SCRIPT_CMD}; + uint32_t length = 1; + + peripheral_i2c_write(handle, data, length); } /** -- 2.7.4 From 25bc6751cc9e9cb252ebb63601c4c06bba8cf645 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 10 Jul 2018 15:28:18 +0900 Subject: [PATCH 07/15] Move shared files to hwcommon package Change-Id: I6e14eb3b3b765ba7e66bd433a575a24df1f004e7 Signed-off-by: lokilee73 --- hw/display/CMakeLists.txt | 2 +- hw/display/display.c | 2 +- hw/led/CMakeLists.txt | 2 +- hw/led/led.c | 2 +- hw/shared.c | 129 ------------------------------------------ hw/shared.h | 43 -------------- hw/touchscreen/CMakeLists.txt | 2 +- hw/touchscreen/touchscreen.c | 2 +- hw/udev.c | 2 +- 9 files changed, 7 insertions(+), 179 deletions(-) mode change 100644 => 100755 hw/display/CMakeLists.txt mode change 100644 => 100755 hw/display/display.c mode change 100644 => 100755 hw/led/CMakeLists.txt delete mode 100644 hw/shared.c delete mode 100644 hw/shared.h mode change 100644 => 100755 hw/touchscreen/CMakeLists.txt mode change 100644 => 100755 hw/udev.c diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt old mode 100644 new mode 100755 index ebccfbe..08c293d --- a/hw/display/CMakeLists.txt +++ b/hw/display/CMakeLists.txt @@ -13,7 +13,7 @@ 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) +ADD_LIBRARY(${PROJECT_NAME} MODULE display.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 old mode 100644 new mode 100755 index 4c93d25..9eb4f89 --- a/hw/display/display.c +++ b/hw/display/display.c @@ -24,7 +24,7 @@ #include #include -#include "../shared.h" +#include #ifndef BACKLIGHT_PATH #define BACKLIGHT_PATH "/sys/class/backlight/rpi_backlight" diff --git a/hw/led/CMakeLists.txt b/hw/led/CMakeLists.txt old mode 100644 new mode 100755 index 6acfd7b..dfe38d5 --- a/hw/led/CMakeLists.txt +++ b/hw/led/CMakeLists.txt @@ -13,7 +13,7 @@ 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) +ADD_LIBRARY(${PROJECT_NAME} MODULE led.c) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${led_pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") diff --git a/hw/led/led.c b/hw/led/led.c index d7f0b39..bc8da82 100755 --- a/hw/led/led.c +++ b/hw/led/led.c @@ -21,7 +21,7 @@ #include #include -#include "../shared.h" +#include #include diff --git a/hw/shared.c b/hw/shared.c deleted file mode 100644 index b6401c1..0000000 --- a/hw/shared.c +++ /dev/null @@ -1,129 +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 -#include -#include -#include -#include -#include -#include -#include - -#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 deleted file mode 100644 index da51ca4..0000000 --- a/hw/shared.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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__ - -#define FEATURE_HARDWARE_DLOG -#ifdef FEATURE_HARDWARE_DLOG -#define LOG_TAG "HARDWARE" -#include -#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 - -#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); -int sys_set_str(char *fname, char *val); - -#endif diff --git a/hw/touchscreen/CMakeLists.txt b/hw/touchscreen/CMakeLists.txt old mode 100644 new mode 100755 index b097615..f364805 --- a/hw/touchscreen/CMakeLists.txt +++ b/hw/touchscreen/CMakeLists.txt @@ -13,7 +13,7 @@ ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -ADD_LIBRARY(${PROJECT_NAME} MODULE touchscreen.c ../shared.c) +ADD_LIBRARY(${PROJECT_NAME} MODULE touchscreen.c) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${touchscreen_pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c index 8cae686..afe6b57 100755 --- a/hw/touchscreen/touchscreen.c +++ b/hw/touchscreen/touchscreen.c @@ -25,7 +25,7 @@ #include #include -#include "../shared.h" +#include #define TOUCHSCREEN_CON_FILE "/sys/devices/platform/rpi_ft5406/enable" diff --git a/hw/udev.c b/hw/udev.c old mode 100644 new mode 100755 index a30204b..9067126 --- a/hw/udev.c +++ b/hw/udev.c @@ -23,7 +23,7 @@ #include #include #include -#include "shared.h" +#include #include "udev.h" #define EVENT_KERNEL "kernel" -- 2.7.4 From 7b7d875aa3557961d7180d075dc5f9dacfb2a51b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Dec 2018 11:25:28 +0900 Subject: [PATCH 08/15] Remove executable flag from non-executable files Change-Id: I1001d32a54715d05d4189d3c407c20aa2482454b Signed-off-by: lokilee73 --- hw/display/CMakeLists.txt | 0 hw/display/display.c | 0 hw/led/CMakeLists.txt | 0 hw/led/led.c | 0 hw/touchscreen/CMakeLists.txt | 0 hw/touchscreen/touchscreen.c | 0 hw/udev.c | 0 packaging/device-manager-plugin-rpi3.spec | 0 8 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 hw/display/CMakeLists.txt mode change 100755 => 100644 hw/display/display.c mode change 100755 => 100644 hw/led/CMakeLists.txt mode change 100755 => 100644 hw/led/led.c mode change 100755 => 100644 hw/touchscreen/CMakeLists.txt mode change 100755 => 100644 hw/touchscreen/touchscreen.c mode change 100755 => 100644 hw/udev.c mode change 100755 => 100644 packaging/device-manager-plugin-rpi3.spec diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/hw/display/display.c b/hw/display/display.c old mode 100755 new mode 100644 diff --git a/hw/led/CMakeLists.txt b/hw/led/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/hw/led/led.c b/hw/led/led.c old mode 100755 new mode 100644 diff --git a/hw/touchscreen/CMakeLists.txt b/hw/touchscreen/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/hw/touchscreen/touchscreen.c b/hw/touchscreen/touchscreen.c old mode 100755 new mode 100644 diff --git a/hw/udev.c b/hw/udev.c old mode 100755 new mode 100644 diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec old mode 100755 new mode 100644 -- 2.7.4 From 9ec62a330e2c6516f9e8feb0b107aa9fcff1648b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 11 Jan 2019 21:21:48 +0900 Subject: [PATCH 09/15] Add thermal module for device_thermal_get_temperature Change-Id: I575d6402d823ea1e53f738772b1ff3457603d54b Signed-off-by: lokilee73 --- CMakeLists.txt | 1 + hw/thermal/CMakeLists.txt | 19 ++++++ hw/thermal/thermal.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 hw/thermal/CMakeLists.txt create mode 100644 hw/thermal/thermal.c diff --git a/CMakeLists.txt b/CMakeLists.txt index b7983c5..7f1ff58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,3 +6,4 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) ADD_SUBDIRECTORY(hw/display) ADD_SUBDIRECTORY(hw/led) ADD_SUBDIRECTORY(hw/touchscreen) +ADD_SUBDIRECTORY(hw/thermal) \ No newline at end of file diff --git a/hw/thermal/CMakeLists.txt b/hw/thermal/CMakeLists.txt new file mode 100644 index 0000000..42bcc20 --- /dev/null +++ b/hw/thermal/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(thermal C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(thermal_pkgs REQUIRED hwcommon dlog glib-2.0 libudev) + +FOREACH(flag ${thermal_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 thermal.c ../udev.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${thermal_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/thermal/thermal.c b/hw/thermal/thermal.c new file mode 100644 index 0000000..10eaea4 --- /dev/null +++ b/hw/thermal/thermal.c @@ -0,0 +1,156 @@ +/* + * device-node + * + * Copyright (c) 2019 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 +#include +#include +#include +#include + +#include +#include + +#define AP_PATH "/sys/class/thermal/thermal_zone0/temp" + +static struct event_data { + ThermalUpdated updated_cb; + void *data; +} edata = { 0, }; + +static guint timer; + +static int thermal_get_info(device_thermal_e type, struct thermal_info *info) +{ + FILE *fp; + char buf[32]; + size_t len; + + if (!info) + return -EINVAL; + + fp = fopen(AP_PATH, "r"); + if (!fp) { + _E("Failed to open thermal path(%d)", errno); + return -errno; + } + + len = fread(buf, 1, sizeof(buf) - 1, fp); + fclose(fp); + if (len == 0) { + _E("Failed to read thermal value(%d)", errno); + return -errno; + } + buf[len] = '\0'; + info->temp = atoi(buf); + info->temp /= 1000; + info->adc = 0; + + _I("temp(%d) adc(%d)", info->temp, info->adc); + return 0; +} + +static gboolean thermal_timeout(gpointer data) +{ + struct thermal_info info; + int ret; + + ret = thermal_get_info(DEVICE_THERMAL_AP, &info); + if (ret < 0) { + _E("Failed to read thermal info (%d)", ret); + return G_SOURCE_CONTINUE; + } + + if (edata.updated_cb) + edata.updated_cb(&info, edata.data); + + return G_SOURCE_CONTINUE; +} + +static int thermal_register_changed_event(ThermalUpdated updated_cb, void *data) +{ + if (timer) + g_source_remove(timer); + + timer = g_timeout_add(10000, thermal_timeout, NULL); + if (timer == 0) { + _E("Failed to add timer for thermal"); + return -ENOENT; + } + + edata.updated_cb = updated_cb; + edata.data = data; + + return 0; +} + +static int thermal_unregister_changed_event(ThermalUpdated updated_cb) +{ + if (timer) { + g_source_remove(timer); + timer = 0; + } + + edata.updated_cb = NULL; + edata.data = NULL; + + return 0; +} + +static int thermal_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct thermal_device *thermal_dev; + + if (!info || !common) + return -EINVAL; + + thermal_dev = calloc(1, sizeof(struct thermal_device)); + if (!thermal_dev) + return -ENOMEM; + + thermal_dev->common.info = info; + thermal_dev->register_changed_event + = thermal_register_changed_event; + thermal_dev->unregister_changed_event + = thermal_unregister_changed_event; + thermal_dev->get_info + = thermal_get_info; + + *common = (struct hw_common *)thermal_dev; + return 0; +} + +static int thermal_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 = THERMAL_HARDWARE_DEVICE_VERSION, + .id = THERMAL_HARDWARE_DEVICE_ID, + .name = "thermal", + .open = thermal_open, + .close = thermal_close, +}; -- 2.7.4 From 5e451b31c74ee80db9426bbf33b3438ebb58db96 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 20 Nov 2019 14:51:27 +0900 Subject: [PATCH 10/15] Fix logging location Change-Id: I4646d7e6dd0706e90f68bfc6108a2159cf9ff36c Signed-off-by: Youngjae Cho --- hw/udev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/udev.c b/hw/udev.c index 9067126..e0c0d13 100644 --- a/hw/udev.c +++ b/hw/udev.c @@ -59,7 +59,6 @@ static gboolean uevent_control_cb(GIOChannel *channel, return TRUE; } - _I("Set udev monitor buffer size %d", UDEV_MONITOR_SIZE); dev = udev_monitor_receive_device(info->mon); if (!dev) return TRUE; @@ -142,6 +141,7 @@ static int uevent_control_start(const char *type, goto stop; } + _I("Set udev monitor buffer size %d", UDEV_MONITOR_SIZE); ret = udev_monitor_set_receive_buffer_size(info->mon, UDEV_MONITOR_SIZE); if (ret != 0) { -- 2.7.4 From 81c57d47fda09f53336023696fbd71098afa1d13 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 3 Feb 2020 14:29:58 +0900 Subject: [PATCH 11/15] Workaround for RPi4 bring-up Change-Id: Id772a00e3dee566643b2323143d2eb40e59a3488 Signed-off-by: Hyotaek Shim --- packaging/device-manager-plugin-rpi3.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec index 840044d..85ded59 100644 --- a/packaging/device-manager-plugin-rpi3.spec +++ b/packaging/device-manager-plugin-rpi3.spec @@ -32,6 +32,7 @@ make %{?jobs:-j%jobs} %post /sbin/ldconfig +rm -rf /etc/fstab # FIXME workaround %postun /sbin/ldconfig -- 2.7.4 From 2887216642134ad1f24d4aa87f78830c6d8fd0c2 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 5 Feb 2020 17:00:27 +0900 Subject: [PATCH 12/15] Add build option -Wall -Werror Change-Id: Ic4cfc6347d38e0e7a59c8eb5f7fc2f12fecdc7a4 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f1ff58..c10c059 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,9 @@ PROJECT(device-manager-rpi3 C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror") + ADD_SUBDIRECTORY(hw/display) ADD_SUBDIRECTORY(hw/led) ADD_SUBDIRECTORY(hw/touchscreen) -ADD_SUBDIRECTORY(hw/thermal) \ No newline at end of file +ADD_SUBDIRECTORY(hw/thermal) -- 2.7.4 From 3b8b7fc1206bd1ed14b6453f179d65422ed0257f Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 7 Feb 2020 10:25:18 +0000 Subject: [PATCH 13/15] Revert "Workaround for RPi4 bring-up" This reverts commit 81c57d47fda09f53336023696fbd71098afa1d13. Change-Id: If4e25f864efda2925d4c46b1d03369fdadcaef72 --- packaging/device-manager-plugin-rpi3.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/device-manager-plugin-rpi3.spec b/packaging/device-manager-plugin-rpi3.spec index 85ded59..840044d 100644 --- a/packaging/device-manager-plugin-rpi3.spec +++ b/packaging/device-manager-plugin-rpi3.spec @@ -32,7 +32,6 @@ make %{?jobs:-j%jobs} %post /sbin/ldconfig -rm -rf /etc/fstab # FIXME workaround %postun /sbin/ldconfig -- 2.7.4 From 2b4d1ac644f634687defc56636ca06ab57ee7259 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 6 Feb 2020 16:38:03 +0900 Subject: [PATCH 14/15] Enable USB gadget for RPI4 You can use this usb hal with both RPI3 and RPI4. //////////////////////////////////////////////////////////////////////////////////////////////////// RPI3 does not have /sys/kernel/config and usb initialization faiied. So, usb is not enabled in RPI3. Therefore, a single usb hal can be used in both RPI3 and RPI4. Deviced internal design for extcon providing incomplete functionality //////////////////////////////////////////////////////////////////////////////////////////////////// Excon does not work perfectly in RPI4 So I asked the kernel team to fix the extcon value to 1. If extcon is always 1, deviecd will not recognize when usb is disconnected, but it will work normally. Conclusion: For targets where extcon does not work perfectly, deviced do not support usb connect/disconnect. Change-Id: Iea3ae481b3120432197a849956fc5332748957ad Signed-off-by: INSUN PYO --- CMakeLists.txt | 2 ++ hw/usb_cfs_client/CMakeLists.txt | 19 +++++++++++++++++++ hw/usb_cfs_client/usb_cfs_client.c | 29 +++++++++++++++++++++++++++++ hw/usb_gadget/CMakeLists.txt | 19 +++++++++++++++++++ hw/usb_gadget/usb_gadget.c | 29 +++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 hw/usb_cfs_client/CMakeLists.txt create mode 100644 hw/usb_cfs_client/usb_cfs_client.c create mode 100644 hw/usb_gadget/CMakeLists.txt create mode 100644 hw/usb_gadget/usb_gadget.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c10c059..2633052 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,3 +9,5 @@ ADD_SUBDIRECTORY(hw/display) ADD_SUBDIRECTORY(hw/led) ADD_SUBDIRECTORY(hw/touchscreen) ADD_SUBDIRECTORY(hw/thermal) +ADD_SUBDIRECTORY(hw/usb_cfs_client) +ADD_SUBDIRECTORY(hw/usb_gadget) diff --git a/hw/usb_cfs_client/CMakeLists.txt b/hw/usb_cfs_client/CMakeLists.txt new file mode 100644 index 0000000..e3447fb --- /dev/null +++ b/hw/usb_cfs_client/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(usb_cfs_client C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(usb_cfs_client_pkgs REQUIRED hwcommon) + +FOREACH(flag ${usb_cfs_client_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 usb_cfs_client.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_cfs_client_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/usb_cfs_client/usb_cfs_client.c b/hw/usb_cfs_client/usb_cfs_client.c new file mode 100644 index 0000000..36da551 --- /dev/null +++ b/hw/usb_cfs_client/usb_cfs_client.c @@ -0,0 +1,29 @@ +/* + * device-node + * + * Copyright (c) 2016 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 + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = USB_CLIENT_HARDWARE_DEVICE_VERSION, + .id = USB_CFS_CLIENT_HARDWARE_DEVICE_ID, + .name = "cfs-gadget", + .open = hw_cfs_gadget_open, + .close = hw_cfs_gadget_close, +}; diff --git a/hw/usb_gadget/CMakeLists.txt b/hw/usb_gadget/CMakeLists.txt new file mode 100644 index 0000000..039baa4 --- /dev/null +++ b/hw/usb_gadget/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(usb_gadget C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon) + +FOREACH(flag ${usb_gadget_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 usb_gadget.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/usb_gadget/usb_gadget.c b/hw/usb_gadget/usb_gadget.c new file mode 100644 index 0000000..2bf9d96 --- /dev/null +++ b/hw/usb_gadget/usb_gadget.c @@ -0,0 +1,29 @@ +/* + * libdevice-node + * + * Copyright (c) 2016 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 + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = USB_GADGET_DEVICE_VERSION, + .id = USB_GADGET_DEVICE_ID, + .name = "simple_translator", + .open = simple_translator_open, + .close = simple_translator_close, +}; -- 2.7.4 From 96d1f6b556bef588752053eb0866b2a115c0191a Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 25 Feb 2020 11:45:35 +0900 Subject: [PATCH 15/15] Add board module Change-Id: I32465c971caf578d11e6de94a12c8d5601d839f9 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 1 + hw/board/CMakeLists.txt | 19 +++++++++++ hw/board/board.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 hw/board/CMakeLists.txt create mode 100644 hw/board/board.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2633052..5a00adc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror") +ADD_SUBDIRECTORY(hw/board) ADD_SUBDIRECTORY(hw/display) ADD_SUBDIRECTORY(hw/led) ADD_SUBDIRECTORY(hw/touchscreen) diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt new file mode 100644 index 0000000..5b8b5b4 --- /dev/null +++ b/hw/board/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(board C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon) + +FOREACH(flag ${usb_gadget_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 board.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/board/board.c b/hw/board/board.c new file mode 100644 index 0000000..3c6b42d --- /dev/null +++ b/hw/board/board.c @@ -0,0 +1,91 @@ +/* + * libdevice-node + * + * Copyright (c) 2016 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. + */ + +#define _GNU_SOURCE +#include + +#include +#include +#include +#include + +#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" +#define LINE_LEN 64 + +static int get_device_serial(char **out) +{ + FILE *fp; + char *line, *p; + + fp = fopen(SERIAL_FILE_PATH, "r"); + if (!fp) + return -1; + + line = malloc(LINE_LEN); + p = fgets(line, LINE_LEN, fp); + fclose(fp); + if (p == NULL) { + free(line); + return -1; + } + + *out = p; + return 0; +} + +static int board_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct hw_board *b; + + if (!info || !common) + return -EINVAL; + + b = calloc(1, sizeof(*b)); + if (!b) + return -ENOMEM; + + b->common.info = info; + b->get_device_serial = get_device_serial; + + *common = &b->common; + return 0; +} + +static int board_close(struct hw_common *common) +{ + struct hw_board *b; + + if (!common) + return -EINVAL; + + b = container_of(common, struct hw_board, common); + free(b); + + return 0; +} + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = BOARD_HARDWARE_DEVICE_VERSION, + .id = BOARD_HARDWARE_DEVICE_ID, + .name = "device", + .open = board_open, + .close = board_close, +}; -- 2.7.4