From 89f21aa60dc1b7732df8ada8a8649dd4f2da3598 Mon Sep 17 00:00:00 2001 From: lanshh Date: Fri, 9 Sep 2016 10:35:00 +0800 Subject: [PATCH] hid: rkvr: add remove sync process, add sync ioctl to sync with nanoc before trasmitting Change-Id: I46c8577b2a9c8dd9b66597fba3775966f030ecfd Signed-off-by: lanshh --- drivers/hid/hid-rkvr.c | 54 +++++++++++++++--------------------------- drivers/hid/hid-rkvr.h | 3 +-- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/drivers/hid/hid-rkvr.c b/drivers/hid/hid-rkvr.c index 1087d9020953..63d7fc00a53c 100644 --- a/drivers/hid/hid-rkvr.c +++ b/drivers/hid/hid-rkvr.c @@ -1062,6 +1062,25 @@ static long rkvr_hidraw_ioctl(struct file *file, unsigned int cmd, unsigned long break; } + if (_IOC_NR(cmd) == _IOC_NR(HIDRKVRHANDSHAKE(0))) { + int len = _IOC_SIZE(cmd); + char *buf; + + buf = kzalloc(len + 1, GFP_KERNEL); + if (!buf) { + ret = -ENOMEM; + break; + } + if (copy_from_user(buf, user_arg, len)) { + ret = -EFAULT; + kfree(buf); + break; + } + ret = hid_report_sync(&hid->dev, buf, len); + kfree(buf); + break; + } + /* Begin Read-only ioctls. */ if (_IOC_DIR(cmd) != _IOC_READ) { ret = -EINVAL; @@ -1120,41 +1139,6 @@ int rkvr_sensor_register_callback(int (*callback)(char *, size_t, void *), void } EXPORT_SYMBOL_GPL(rkvr_sensor_register_callback); -static int rkvr_sync_exec(const char *p, size_t c) -{ - int minor; - int ret = c; - int exist = 0; - - mutex_lock(&minors_lock); - pr_info("rkvr_sync_exec %s\n", p); - for (minor = 0; minor < RKVR_HIDRAW_MAX_DEVICES; minor++) { - if (!rkvr_hidraw_table[minor] || !rkvr_hidraw_table[minor]->exist) - continue; - if (hid_report_sync(&rkvr_hidraw_table[minor]->hid->dev, p, c)) { - hid_err(rkvr_hidraw_table[minor]->hid, "hid_report_sync failed\n"); - ret = -EIO; - goto exit; - } - exist++; - } - if (!exist) - ret = -ENODEV; -exit: - mutex_unlock(&minors_lock); - - return ret; -} - -int rkvr_sensor_sync_inv(const char *p, size_t c) -{ - snprintf(sync_string, sizeof(sync_string), "%s", p); - - return rkvr_sync_exec(sync_string, strlen(sync_string)); -} - -EXPORT_SYMBOL_GPL(rkvr_sensor_sync_inv); - static int rkvr_probe(struct hid_device *hdev, const struct hid_device_id *id) { int retval; diff --git a/drivers/hid/hid-rkvr.h b/drivers/hid/hid-rkvr.h index ff1cd9fd4c69..309bc37cb550 100644 --- a/drivers/hid/hid-rkvr.h +++ b/drivers/hid/hid-rkvr.h @@ -9,7 +9,7 @@ #ifndef __HID_RKVR_H #define __HID_RKVR_H -#define HIDRKVRHANDSHAKE(len) _IOC(_IOC_WRITE, 'H', 0x07, len) +#define HIDRKVRHANDSHAKE(len) _IOC(_IOC_WRITE, 'H', 0x1A, len) #define HID_REPORT_ID_R 4 #define HID_REPORT_ID_W 5 #define HID_REPORT_ID_CRYP 6 @@ -31,7 +31,6 @@ enum tracker_message_type { #define DYNAMIC_LOAD_MPU6500 0 int rkvr_sensor_register_callback(int (*callback)(char *, size_t, void *), void *priv); -int rkvr_sensor_sync_inv(const char *p, size_t c); struct rkvr_iio_hw_device { struct device *dev; -- 2.34.1