touchscreen: control interface change to sysfs 85/149885/1
authorKwangCheol Lee <kclee@dignsys.com>
Wed, 13 Sep 2017 10:53:04 +0000 (19:53 +0900)
committerKwangCheol Lee <kclee@dignsys.com>
Wed, 13 Sep 2017 11:00:34 +0000 (20:00 +0900)
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 <kclee@dignsys.com>
hw/touchscreen/touchscreen.c [changed mode: 0644->0755]
packaging/device-manager-plugin-rpi3.spec

old mode 100644 (file)
new mode 100755 (executable)
index 3f25986..8cae686
 #include <errno.h>
 #include <linux/limits.h>
 #include <dirent.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/utsname.h>
 
 #include <hw/touchscreen.h>
 #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;
 }
 
index 0f9c9c577a6ea7f4205e984f78548c71cdfe0240..10f3dc3e3f926daa71e83123434168c5e3e524e5 100755 (executable)
@@ -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