From: KwangCheol Lee Date: Wed, 13 Sep 2017 10:53:04 +0000 (+0900) Subject: touchscreen: control interface change to sysfs X-Git-Tag: submit/tizen/20210604.091051~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d6c367dfb31e3a1c16436b3acd6bdc0d4cd9d35;p=platform%2Fhal%2Fbackend%2Frpi%2Fdevice-rpi.git 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) --- 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