d92656a127941e4e7c4e5f7d32518ebc3808060d
[firefly-linux-kernel-4.4.55.git] / drivers / hid / hid-rkvr.c
1 /*
2  * Rockchip VR driver for Linux
3  *
4  * Copyright (C) ROCKCHIP, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 2 of the License, or (at your option)
9  * any later version.
10  */
11
12 /*
13  * Driver for Rockchip VR devices. Based on hidraw driver.
14  */
15
16 #include <linux/cdev.h>
17 #include <linux/poll.h>
18 #include <linux/sched.h>
19 #include <linux/module.h>
20 #include <linux/usb.h>
21 #include <linux/hidraw.h>
22 #include <linux/input.h>
23 #include <linux/platform_device.h>
24 #include "hid-rkvr.h"
25 #include "hid-ids.h"
26
27 #define USB_TRACKER_INTERFACE_PROTOCOL  0
28 /* define rkvr interface number */
29 #define RKVR_INTERFACE_USB_AUDIO_ID 1
30 #define RKVR_INTERFACE_USB_SENSOR_ID 2
31 #define RKVR_INTERFACE_USB_AUDIO_KEY_ID 1
32 /* number of reports to buffer */
33 #define RKVR_HIDRAW_BUFFER_SIZE 64
34 #define RKVR_HIDRAW_MAX_DEVICES 8
35 #define RKVR_FIRST_MINOR 0
36
37 static struct class *rkvr_class;
38
39 static struct hidraw *rkvr_hidraw_table[RKVR_HIDRAW_MAX_DEVICES];
40
41 static DEFINE_MUTEX(minors_lock);
42
43 struct keymap_t {
44         __u16 key_menu_up:1;
45         __u16 key_menu_down:1;
46         __u16 key_home_up:1;
47         __u16 key_home_down:1;
48         __u16 key_power_up:1;
49         __u16 key_power_down:1;
50         __u16 key_volup_up:1;
51         __u16 key_volup_down:1;
52         __u16 key_voldn_up:1;
53         __u16 key_voldn_down:1;
54         __u16 key_esc_up:1;
55         __u16 key_esc_down:1;
56         /*for touch panel **/
57         __u16 key_up_pressed:1;
58         __u16 key_up_released:1;
59         __u16 key_down_pressed:1;
60         __u16 key_down_released:1;
61         __u16 key_left_pressed:1;
62         __u16 key_left_released:1;
63         __u16 key_right_pressed:1;
64         __u16 key_right_released:1;
65         __u16 key_enter_pressed:1;
66         __u16 key_enter_released:1;
67         __u16 key_pressed:1;
68 } __packed;
69
70 union rkvr_data_t {
71         struct rkvr_data {
72                 __u8 buf_head[6];
73                 __u8 buf_sensortemperature[2];
74                 __u8 buf_sensor[40];
75                 __u8 buf_reserve[10];
76                 struct keymap_t key_map;
77         } rkvr_data;
78         __u8 buf[62];
79 } __packed;
80
81 static int rkvr_major;
82 static struct cdev rkvr_cdev;
83 static unsigned int count_array[15] = {0,};
84 static unsigned long old_jiffy_array[15] = {0,};
85 static int rkvr_index;
86 static int opens;
87
88 struct sensor_hid_data {
89         void *priv;
90         int (*send_event)(char *raw_data, size_t raw_len, void *priv);
91 } sensorData;
92
93 static DEFINE_MUTEX(device_list_lock);
94 static struct list_head rkvr_hid_hw_device_list = {
95         .next = &rkvr_hid_hw_device_list,
96         .prev = &rkvr_hid_hw_device_list
97 };
98
99 static struct rkvr_iio_hw_device *inv_hid_alloc(const char *name)
100 {
101         struct rkvr_iio_hw_device *p;
102         const char *s;
103
104         if (!name)
105                 return 0;
106         s = kstrdup_const(name, GFP_KERNEL);
107         if (!s)
108                 goto error;
109         p = kzalloc(sizeof(*p), GFP_KERNEL);
110         if (!p)
111                 goto error;
112         p->name = s;
113         return p;
114 error:
115         pr_err("%s error!\n", __func__);
116         if (s)
117                 kfree_const(s);
118         return 0;
119 }
120
121 static void inv_hid_free(struct rkvr_iio_hw_device *hw_device)
122 {
123         kfree_const(hw_device->name);
124         kfree(hw_device);
125 }
126
127 static int inv_hid_register_devcie(struct rkvr_iio_hw_device *hw_device)
128 {
129
130         mutex_lock(&device_list_lock);
131         if (hw_device->name && (!list_empty(&rkvr_hid_hw_device_list))) {
132                 struct rkvr_iio_hw_device *p;
133
134                 list_for_each_entry(p, &rkvr_hid_hw_device_list, l) {
135                         if (!strcmp(hw_device->name, p->name)) {
136                                 pr_err("%s already exist ,abort\n", hw_device->name);
137                                 return -1;
138                         }
139                 }
140         }
141         list_add_tail(&hw_device->l, &rkvr_hid_hw_device_list);
142         mutex_unlock(&device_list_lock);
143         return 0;
144 }
145
146 static void inv_hid_unregister_and_destroy_devcie_by_name(const char *name)
147 {
148         struct rkvr_iio_hw_device *p = NULL;
149
150         mutex_lock(&device_list_lock);
151         list_for_each_entry(p, &rkvr_hid_hw_device_list, l) {
152                 if (!strcmp(name, p->name)) {
153                         list_del(&p->l);
154                         break;
155                 }
156         }
157         if (p) {
158                 pr_info("find dev with name %s,free now\n", name);
159                 inv_hid_free(p);
160         }
161         mutex_unlock(&device_list_lock);
162 }
163
164 static ssize_t rkvr_hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
165 {
166         struct hidraw_list *list = file->private_data;
167         int ret = 0, len;
168         DECLARE_WAITQUEUE(wait, current);
169
170         mutex_lock(&list->read_mutex);
171         while (ret == 0) {
172                 if (list->head == list->tail) {
173                         add_wait_queue(&list->hidraw->wait, &wait);
174                         set_current_state(TASK_INTERRUPTIBLE);
175
176                         while (list->head == list->tail) {
177                                 if (signal_pending(current)) {
178                                         ret = -ERESTARTSYS;
179                                         break;
180                                 }
181                                 if (!list->hidraw->exist) {
182                                         ret = -EIO;
183                                         break;
184                                 }
185                                 if (file->f_flags & O_NONBLOCK) {
186                                         ret = -EAGAIN;
187                                         break;
188                                 }
189
190                                 /* allow O_NONBLOCK to work well from other threads */
191                                 mutex_unlock(&list->read_mutex);
192                                 schedule();
193                                 mutex_lock(&list->read_mutex);
194                                 set_current_state(TASK_INTERRUPTIBLE);
195                         }
196
197                         set_current_state(TASK_RUNNING);
198                         remove_wait_queue(&list->hidraw->wait, &wait);
199                 }
200
201                 if (ret)
202                         goto out;
203
204                 len = list->buffer[list->tail].len > count ?
205                         count : list->buffer[list->tail].len;
206
207                 if (list->buffer[list->tail].value) {
208                         if (copy_to_user(buffer, list->buffer[list->tail].value, len)) {
209                                 ret = -EFAULT;
210                                 goto out;
211                         }
212                         ret = len;
213                         if (opens > 0 && rkvr_index < 15) {
214                                 if (++count_array[rkvr_index] >= 1000) {
215                                         unsigned long cur_jiffy = jiffies;
216
217                                         hid_dbg(list->hidraw->hid, "rkvr: %d Hz, read(%d) (%d:%s)\n", (int)(1000 * HZ / (cur_jiffy - old_jiffy_array[rkvr_index])), rkvr_index, current->pid, current->comm);
218                                         count_array[rkvr_index] = 0;
219                                         old_jiffy_array[rkvr_index] = cur_jiffy;
220                                 }
221                                 if (++rkvr_index >= opens)
222                                         rkvr_index = 0;
223                         } else {
224                                 rkvr_index = 0;
225                         }
226                 }
227
228                 kfree(list->buffer[list->tail].value);
229                 list->buffer[list->tail].value = NULL;
230                 list->tail = (list->tail + 1) & (RKVR_HIDRAW_BUFFER_SIZE - 1);
231         }
232 out:
233         mutex_unlock(&list->read_mutex);
234         return ret;
235 }
236
237 /* The first byte is expected to be a report number.
238  * This function is to be called with the minors_lock mutex held
239  */
240 static ssize_t rkvr_hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type)
241 {
242         unsigned int minor = iminor(file_inode(file));
243         struct hid_device *dev;
244         __u8 *buf;
245         int ret = 0;
246
247         if (!rkvr_hidraw_table[minor] || !rkvr_hidraw_table[minor]->exist) {
248                 ret = -ENODEV;
249                 goto out;
250         }
251
252         dev = rkvr_hidraw_table[minor]->hid;
253
254         if (count > HID_MAX_BUFFER_SIZE) {
255                 hid_warn(dev, "rkvr - pid %d passed too large report\n",
256                          task_pid_nr(current));
257                 ret = -EINVAL;
258                 goto out;
259         }
260
261         if (count < 2) {
262                 hid_warn(dev, "rkvr - pid %d passed too short report\n",
263                         task_pid_nr(current));
264                 ret = -EINVAL;
265                 goto out;
266         }
267
268         buf = kmalloc(count * sizeof(__u8), GFP_KERNEL);
269         if (!buf) {
270                 ret = -ENOMEM;
271                 goto out;
272         }
273
274         if (copy_from_user(buf, buffer, count)) {
275                 ret = -EFAULT;
276                 goto out_free;
277         }
278
279         if ((report_type == HID_OUTPUT_REPORT) &&
280                 !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) {
281                 ret = hid_hw_output_report(dev, buf, count);
282                 /*
283                  * compatibility with old implementation of USB-HID and I2C-HID:
284                  * if the device does not support receiving output reports,
285                  * on an interrupt endpoint, fallback to SET_REPORT HID command.
286                  */
287                 if (ret != -ENOSYS)
288                         goto out_free;
289         }
290
291         ret = hid_hw_raw_request(dev, buf[0], buf, count, report_type,
292                                 HID_REQ_SET_REPORT);
293
294 out_free:
295         kfree(buf);
296 out:
297         return ret;
298 }
299
300 /* the first byte is expected to be a report number */
301 static ssize_t rkvr_hidraw_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
302 {
303         ssize_t ret;
304
305         mutex_lock(&minors_lock);
306         ret = rkvr_hidraw_send_report(file, buffer, count, HID_OUTPUT_REPORT);
307         mutex_unlock(&minors_lock);
308         return ret;
309 }
310
311 /* This function performs a Get_Report transfer over the control endpoint
312  * per section 7.2.1 of the HID specification, version 1.1.  The first byte
313  * of buffer is the report number to request, or 0x0 if the defice does not
314  * use numbered reports. The report_type parameter can be HID_FEATURE_REPORT
315  * or HID_INPUT_REPORT.  This function is to be called with the minors_lock
316  *  mutex held.
317  */
318 static ssize_t rkvr_hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type)
319 {
320         unsigned int minor = iminor(file_inode(file));
321         struct hid_device *dev;
322         __u8 *buf;
323         int ret = 0, len;
324         unsigned char report_number;
325
326         dev = rkvr_hidraw_table[minor]->hid;
327
328         if (!dev->ll_driver->raw_request) {
329                 ret = -ENODEV;
330                 goto out;
331         }
332
333         if (count > HID_MAX_BUFFER_SIZE) {
334                 hid_warn(dev, "rkvr - hidraw: pid %d passed too large report\n",
335                                 task_pid_nr(current));
336                 ret = -EINVAL;
337                 goto out;
338         }
339
340         if (count < 2) {
341                 hid_warn(dev, "rkvr - hidraw: pid %d passed too short report\n",
342                                 task_pid_nr(current));
343                 ret = -EINVAL;
344                 goto out;
345         }
346
347         buf = kmalloc(count * sizeof(__u8), GFP_KERNEL);
348         if (!buf) {
349                 ret = -ENOMEM;
350                 goto out;
351         }
352
353         /*
354         * Read the first byte from the user. This is the report number,
355         * which is passed to hid_hw_raw_request().
356         */
357         if (copy_from_user(&report_number, buffer, 1)) {
358                 ret = -EFAULT;
359                 goto out_free;
360         }
361
362         ret = hid_hw_raw_request(dev, report_number, buf, count, report_type,
363                                  HID_REQ_GET_REPORT);
364         if (ret < 0)
365                 goto out_free;
366         len = (ret < count) ? ret : count;
367
368         if (copy_to_user(buffer, buf, len)) {
369                 ret = -EFAULT;
370                 goto out_free;
371         }
372
373         ret = len;
374
375 out_free:
376         kfree(buf);
377 out:
378         return ret;
379 }
380
381 static unsigned int rkvr_hidraw_poll(struct file *file, poll_table *wait)
382 {
383         struct hidraw_list *list = file->private_data;
384
385         poll_wait(file, &list->hidraw->wait, wait);
386         if (list->head != list->tail)
387                 return POLLIN | POLLRDNORM;
388         if (!list->hidraw->exist)
389                 return POLLERR | POLLHUP;
390
391         return 0;
392 }
393
394 static int rkvr_hidraw_open(struct inode *inode, struct file *file)
395 {
396         unsigned int minor = iminor(inode);
397         struct hidraw *dev;
398         struct hidraw_list *list;
399         unsigned long flags;
400         int err = 0;
401
402         list = kzalloc(sizeof(*list), GFP_KERNEL);
403         if (!list) {
404                 err = -ENOMEM;
405                 goto out;
406         }
407
408         mutex_lock(&minors_lock);
409         if (!rkvr_hidraw_table[minor] || !rkvr_hidraw_table[minor]->exist) {
410                 err = -ENODEV;
411                 goto out_unlock;
412         }
413
414         dev = rkvr_hidraw_table[minor];
415         if (!dev->open++) {
416                 err = hid_hw_power(dev->hid, PM_HINT_FULLON);
417                 if (err < 0) {
418                         dev->open--;
419                         goto out_unlock;
420                 }
421
422                 err = hid_hw_open(dev->hid);
423
424                 if (err < 0) {
425                         hid_hw_power(dev->hid, PM_HINT_NORMAL);
426                         dev->open--;
427                         goto out_unlock;
428                 }
429         }
430
431         list->hidraw = rkvr_hidraw_table[minor];
432         mutex_init(&list->read_mutex);
433         spin_lock_irqsave(&rkvr_hidraw_table[minor]->list_lock, flags);
434         list_add_tail(&list->node, &rkvr_hidraw_table[minor]->list);
435         spin_unlock_irqrestore(&rkvr_hidraw_table[minor]->list_lock, flags);
436         file->private_data = list;
437
438         opens = dev->open;
439
440 out_unlock:
441         mutex_unlock(&minors_lock);
442 out:
443         if (err < 0)
444                 kfree(list);
445
446         return err;
447 }
448
449 static int rkvr_hidraw_fasync(int fd, struct file *file, int on)
450 {
451         struct hidraw_list *list = file->private_data;
452
453         return fasync_helper(fd, file, on, &list->fasync);
454 }
455
456 static void rkvr_drop_ref(struct hidraw *hidraw, int exists_bit)
457 {
458         if (exists_bit) { /*hw removed**/
459                 hidraw->exist = 0;
460                 if (hidraw->open) {
461                         hid_hw_close(hidraw->hid);
462                         wake_up_interruptible(&hidraw->wait);
463                 }
464         } else {
465                 --hidraw->open;
466         }
467
468         if (!hidraw->open) {
469                 if (!hidraw->exist) { /*no opened && no hardware,delete all**/
470                         rkvr_hidraw_table[hidraw->minor] = NULL;
471                         kfree(hidraw);
472                 } else {
473                         /* close device for last reader */
474                         hid_hw_power(hidraw->hid, PM_HINT_NORMAL);
475                         hid_hw_close(hidraw->hid);
476                 }
477         }
478 }
479
480 static int rkvr_hidraw_release(struct inode *inode, struct file *file)
481 {
482         unsigned int minor = iminor(inode);
483         struct hidraw_list *list = file->private_data;
484         unsigned long flags;
485
486         mutex_lock(&minors_lock);
487
488         spin_lock_irqsave(&rkvr_hidraw_table[minor]->list_lock, flags);
489         list_del(&list->node);
490         spin_unlock_irqrestore(&rkvr_hidraw_table[minor]->list_lock, flags);
491
492         kfree(list);
493         rkvr_drop_ref(rkvr_hidraw_table[minor], 0);
494
495         mutex_unlock(&minors_lock);
496
497         return 0;
498 }
499
500 static void rkvr_send_key_event(struct input_dev *input, int key_value, int state)
501 {
502         if (!input) {
503                 return;
504         }
505         if (state) {
506                 input_report_key(input, key_value, 1);
507                 input_sync(input);
508         } else {
509                 input_report_key(input, key_value, 0);
510                 input_sync(input);
511         }
512 }
513
514 static int rkvr_keys_event(struct hid_device *hdev, void *data, unsigned long len)
515 {
516         struct input_dev *input = hdev->hiddev;
517         union rkvr_data_t *rkvr_data = (union rkvr_data_t *)data;
518
519         if (rkvr_data->rkvr_data.key_map.key_menu_up)
520                 rkvr_send_key_event(input, KEY_MENU, 0);
521         else if (rkvr_data->rkvr_data.key_map.key_menu_down)
522                 rkvr_send_key_event(input, KEY_MENU, 1);
523         else if (rkvr_data->rkvr_data.key_map.key_home_up)
524                 rkvr_send_key_event(input, KEY_HOME, 0);
525         else if (rkvr_data->rkvr_data.key_map.key_home_down)
526                 rkvr_send_key_event(input, KEY_HOME, 1);
527         else if (rkvr_data->rkvr_data.key_map.key_power_up)
528                 rkvr_send_key_event(input, KEY_POWER, 0);
529         else if (rkvr_data->rkvr_data.key_map.key_power_down)
530                 rkvr_send_key_event(input, KEY_POWER, 1);
531         else if (rkvr_data->rkvr_data.key_map.key_volup_up)
532                 rkvr_send_key_event(input, KEY_VOLUMEUP, 0);
533         else if (rkvr_data->rkvr_data.key_map.key_volup_down)
534                 rkvr_send_key_event(input, KEY_VOLUMEUP, 1);
535         else if (rkvr_data->rkvr_data.key_map.key_voldn_up)
536                 rkvr_send_key_event(input, KEY_VOLUMEDOWN, 0);
537         else if (rkvr_data->rkvr_data.key_map.key_voldn_down)
538                 rkvr_send_key_event(input, KEY_VOLUMEDOWN, 1);
539         else if (rkvr_data->rkvr_data.key_map.key_esc_up)
540                 rkvr_send_key_event(input, KEY_ESC, 0);
541         else if (rkvr_data->rkvr_data.key_map.key_esc_down)
542                 rkvr_send_key_event(input, KEY_ESC, 1);
543         else if (rkvr_data->rkvr_data.key_map.key_up_pressed) {
544                 rkvr_send_key_event(input, KEY_UP, 1);
545                 rkvr_send_key_event(input, KEY_UP, 0);
546         } else if (rkvr_data->rkvr_data.key_map.key_down_pressed) {
547                 rkvr_send_key_event(input, KEY_DOWN, 1);
548                 rkvr_send_key_event(input, KEY_DOWN, 0);
549         } else if (rkvr_data->rkvr_data.key_map.key_left_pressed) {
550                 rkvr_send_key_event(input, KEY_LEFT, 1);
551                 rkvr_send_key_event(input, KEY_LEFT, 0);
552         } else if (rkvr_data->rkvr_data.key_map.key_right_pressed) {
553                 rkvr_send_key_event(input, KEY_RIGHT, 1);
554                 rkvr_send_key_event(input, KEY_RIGHT, 0);
555         } else if (rkvr_data->rkvr_data.key_map.key_enter_pressed) {
556                 rkvr_send_key_event(input, KEY_ENTER, 1);
557                 rkvr_send_key_event(input, KEY_ENTER, 0);
558         }
559         return 0;
560 }
561
562 static int rkvr_report_event(struct hid_device *hid, u8 *data, int len)
563 {
564         struct hidraw *dev = hid->hidraw;
565         struct hidraw_list *list;
566         int ret = 0;
567         unsigned long flags;
568         union rkvr_data_t *rkvr_data = (union rkvr_data_t *)data;
569         struct sensor_hid_data *pdata = hid_get_drvdata(hid);
570
571         spin_lock_irqsave(&dev->list_lock, flags);
572         if (hid->hiddev) {
573                 rkvr_keys_event(hid, data, len);
574         }
575         if (pdata && pdata->priv && pdata->send_event) {
576                 pdata->send_event(rkvr_data->buf, len, pdata->priv);
577                 spin_unlock_irqrestore(&dev->list_lock, flags);
578         } else {
579                 list_for_each_entry(list, &dev->list, node) {
580                         int new_head = (list->head + 1) & (RKVR_HIDRAW_BUFFER_SIZE - 1);
581
582                         if (new_head == list->tail)
583                                 continue;
584
585                         list->buffer[list->head].value = kmemdup(data, len, GFP_ATOMIC);
586                         if (!list->buffer[list->head].value) {
587                                 ret = -ENOMEM;
588                                 spin_unlock_irqrestore(&dev->list_lock, flags);
589                                 break;
590                         }
591
592                         list->buffer[list->head].len = len;
593                         list->head = new_head;
594                         kill_fasync(&list->fasync, SIGIO, POLL_IN);
595                 }
596                 spin_unlock_irqrestore(&dev->list_lock, flags);
597                 wake_up_interruptible(&dev->wait);
598         }
599         return ret;
600 }
601
602 /******************************************
603  *--------------------
604  *| ID | BUF .....   |
605  *--------------------
606  *
607  ******************************************/
608 static int rkvr_send_report(struct device *dev, unsigned char *data, size_t len)
609 {
610         struct hid_device *hid = container_of(dev, struct hid_device, dev);
611         unsigned char reportnum = HID_REPORT_ID_RKVR;
612         unsigned char rtype = HID_OUTPUT_REPORT;
613         int ret = -EINVAL;
614
615         ret = hid_hw_raw_request(hid, reportnum, (unsigned char *)data, len, rtype, HID_REQ_SET_REPORT);
616         if (ret != len) {
617                 hid_err(hid, "rkvr_send_report fail\n");
618                 ret = -EIO;
619                 goto fail;
620         }
621         hid_info(hid, "rkvr_send_report ok\n");
622         ret = 0;
623 fail:
624         return ret;
625 }
626
627 /*
628  * for enable sensor data
629  ************************************
630  * buf contents ---->
631  * first 8 bytes :random digits
632  * left bytes    :encryt data
633  * eg:32654:3AA4618F6B455D37F06279EC2D6BC478C759443277F3E4E982203562E7ED
634  ***********************************
635  */
636
637 static int hid_report_sync(struct device *dev, const char *data, size_t count)
638 {
639         struct hid_device *hid = container_of(dev, struct hid_device, dev);
640         u64 *tmp;
641         unsigned char buf[64] = {HID_REPORT_ID_RKVR, RKVR_ID_SYNC};
642         unsigned char buf2[3] = {0};
643         char *colon;
644         int i, ret = 0;
645         char *p;
646         size_t len;
647
648         p = kmalloc(sizeof(*p) * count, GFP_KERNEL);
649         if (!p) {
650                 hid_err(hid, "no mem\n");
651                 return -ENOMEM;
652         }
653         memcpy(p, data, count);
654         colon = strnchr(p, count, ':');
655         if (!colon) {
656                 hid_err(hid, "must have conlon\n");
657                 ret = -EINVAL;
658                 goto fail;
659         }
660         if (colon - p + 1 >= count) {
661                 hid_err(hid, "must have sync string after conlon\n");
662                 ret = -EINVAL;
663                 goto fail;
664         }
665         colon[0] = 0;
666         colon++;
667         tmp = (u64 *)(buf + 2);
668         if (kstrtoull(p, 10, tmp)) {
669                 hid_err(hid, "convert rand string fail,only decimal string allowed\n");
670                 ret = -EINVAL;
671                 goto fail;
672         }
673         hid_info(hid, "uint64 %llu\n", *(u64 *)(buf + 2));
674         len = min((count - (colon - p)) / 2, sizeof(buf) - (sizeof(*tmp) + 2));
675         for (i = 0; i < len; i++) {
676                 buf2[0] = colon[i * 2];
677                 buf2[1] = colon[i * 2 + 1];
678                 if (kstrtou8(buf2, 16, &buf[sizeof(*tmp) + 2 + i])) {
679                         hid_err(hid, "err sync string,only hex string allowed\n");
680                         ret = -EINVAL;
681                         goto fail;
682                 }
683         }
684         len = i + sizeof(*tmp) + 2;
685         ret = rkvr_send_report(dev, (unsigned char *)buf, len);
686         if (ret) {
687                 hid_err(hid, "hid_report_encrypt fail\n");
688                 ret = -EIO;
689                 goto fail;
690         }
691         hid_info(hid, "hid_report_encrypt ok\n");
692         ret = count;
693 fail:
694         kfree(p);
695
696         return ret;
697 }
698
699 static void hid_report_fill_rw(unsigned char *buf, u8 reg, u8 *data, int len, int w)
700 {
701         if (w)
702                 buf[0] = (1 << 7) | (len && 0x7f);
703         else
704                 buf[0] = len && 0x7f;
705         buf[1] = reg;
706         memcpy(&buf[2], data, len);
707 }
708
709 #if DEBUG_SYS
710
711 static int hid_report_readreg(struct device *dev, u8 reg, u8 *data, int len)
712 {
713         struct hid_device *hid = container_of(dev, struct hid_device, dev);
714         unsigned char report_number = reg;
715         unsigned char report_type = HID_REGR_REPORT;
716         char buf[1 + sizeof(data) * len];
717         int readlen = 1 + sizeof(data) * len;
718         int ret;
719
720         ret = hid_hw_raw_request(hid, report_number, (unsigned char *)buf, readlen, report_type, HID_REQ_GET_REPORT);
721         if (ret != readlen) {
722                 hid_info(hid, "id_hw_raw_request fail\n");
723         } else {
724                 memcpy(data, &buf[1], readlen);
725                 hid_info(hid, "hid_report_readreg %02x %02x\n", reg, data[0]);
726         }
727
728         return 0;
729 }
730
731 static int hid_report_writereg(struct device *dev, u8 reg, u8 data)
732 {
733         struct hid_device *hid = container_of(dev, struct hid_device, dev);
734         unsigned char report_number = HID_REPORT_ID_W;
735         unsigned char report_type = HID_REGW_REPORT;
736         char buf[3 + sizeof(data)];
737         int ret;
738
739         hid_report_fill_rw(&buf[1], reg, &data, sizeof(data), 1);
740         ret = hid_hw_raw_request(hid, report_number, (unsigned char *)buf, 4, report_type, HID_REQ_SET_REPORT);
741         if (ret != 4)
742                 hid_info(hid, "id_hw_raw_request fail\n");
743         else
744                 hid_info(hid, "id_hw_raw_request ok\n");
745
746         return 0;
747 }
748
749 static ssize_t rkvr_dev_attr_debug_store(struct device *dev, struct device_attribute *attr,
750                         const char *buf, size_t count)
751 {
752         struct hidraw *devraw;
753
754         devraw = dev_get_drvdata(dev);
755         if (0 == strncmp(buf, "write", 5))
756                 hid_report_writereg(&devraw->hid->dev, 0, 0);
757         hid_info(devraw->hid, "%s\n", buf);
758
759         return count;
760 }
761
762 static ssize_t rkvr_dev_attr_debug_show(struct device *dev, struct device_attribute *attr,
763                                 char *buf)
764 {
765         size_t count = 0;
766         u8 mpu6500_id = 0;
767         struct hidraw *devraw;
768
769         devraw = dev_get_drvdata(dev);
770         if (!hid_report_readreg(&devraw->hid->dev, 0x75 | 0x80, &mpu6500_id, 1))
771                 count += sprintf(&buf[count], "reg value %d\n", mpu6500_id);
772         else
773                 count += sprintf(&buf[count], "read fail\n");
774
775         return count;
776 }
777 static DEVICE_ATTR(debug, 0664, rkvr_dev_attr_debug_show, rkvr_dev_attr_debug_store);
778
779 static ssize_t rkvr_dev_attr_sync_store(struct device *dev, struct device_attribute *attr,
780                         const char *buf, size_t count)
781 {
782         struct hidraw *devraw = dev_get_drvdata(dev);
783         int ret;
784
785         ret = hid_report_sync(&devraw->hid->dev, buf, count - 1);
786         return ret > 0 ? count : ret;
787 }
788
789 static DEVICE_ATTR(sync, S_IWUSR, NULL, rkvr_dev_attr_sync_store);
790 #endif
791
792 static int rkvr_hid_read(struct rkvr_iio_hw_device *hdev, int reg, unsigned char *data, int len)
793 {
794         struct hid_device *hid = container_of(hdev->dev, struct hid_device, dev);
795         unsigned char report_number = reg;
796         unsigned char report_type = HID_REGR_REPORT;
797         char buf[1 + sizeof(data) * len];
798         int readlen = 1 + sizeof(data) * len;
799         int ret;
800
801         ret = hid_hw_raw_request(hid, report_number, (unsigned char *)buf, readlen, report_type, HID_REQ_GET_REPORT);
802         if (ret != readlen) {
803                 hid_err(hid, "id_hw_raw_request fail\n");
804         } else {
805                 memcpy(data, &buf[1], sizeof(data) * len);
806         }
807
808         return 0;
809 }
810
811 static int rkvr_hid_write(struct rkvr_iio_hw_device *hdev, int reg, unsigned char data)
812 {
813         struct hid_device *hid = container_of(hdev->dev, struct hid_device, dev);
814         unsigned char report_number = HID_REPORT_ID_W;
815         unsigned char report_type = HID_REGW_REPORT;
816         char buf[3 + sizeof(data)];
817         int ret;
818
819         hid_report_fill_rw(&buf[1], reg, &data, sizeof(data), 1);
820         ret = hid_hw_raw_request(hid, report_number, (unsigned char *)buf, 4, report_type, HID_REQ_SET_REPORT);
821         if (ret != 4)
822                 hid_info(hid, "id_hw_raw_request fail\n");
823         else
824                 hid_info(hid, "id_hw_raw_request ok\n");
825
826         return 0;
827 }
828
829 static int rkvr_hid_open(struct rkvr_iio_hw_device *hdev)
830 {
831         struct hid_device *hid;
832         int err;
833
834         hid = container_of(hdev->dev, struct hid_device, dev);
835         err = hid_hw_power(hid, PM_HINT_FULLON);
836         if (err < 0)
837                 return err;
838         err = hid_hw_open(hid);
839         if (err < 0) {
840                 hid_hw_power(hid, PM_HINT_NORMAL);
841                 return err;
842         }
843
844         return 0;
845 }
846
847 static void rkvr_hid_close(struct rkvr_iio_hw_device *hdev)
848 {
849         struct hid_device *hid;
850
851         hid = container_of(hdev->dev, struct hid_device, dev);
852         hid_hw_power(hid, PM_HINT_NORMAL);
853         hid_hw_close(hid);
854 }
855
856 #if DYNAMIC_LOAD_MPU6500
857 static int register_mpu6500;
858 struct platform_device mpu6500_dev = {
859         .name = "mpu6500",
860 };
861 #endif
862
863 static int rkvr_connect(struct hid_device *hid)
864 {
865         int minor, result;
866         struct hidraw *dev;
867
868         /* we accept any HID device, no matter the applications */
869         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
870         if (!dev)
871                 return -ENOMEM;
872         result = -EINVAL;
873         mutex_lock(&minors_lock);
874         for (minor = 0; minor < RKVR_HIDRAW_MAX_DEVICES; minor++) {
875                 if (rkvr_hidraw_table[minor])
876                         continue;
877                 rkvr_hidraw_table[minor] = dev;
878                 result = 0;
879                 break;
880         }
881         if (result) {
882                 mutex_unlock(&minors_lock);
883                 kfree(dev);
884                 goto out;
885         }
886
887         dev->dev = device_create(rkvr_class, &hid->dev, MKDEV(rkvr_major, minor),
888                                         NULL, "%s%d", "rkvr", minor);
889
890         if (IS_ERR(dev->dev)) {
891                 rkvr_hidraw_table[minor] = NULL;
892                 mutex_unlock(&minors_lock);
893                 result = PTR_ERR(dev->dev);
894                 kfree(dev);
895                 goto out;
896         }
897
898         dev_set_drvdata(dev->dev, dev);
899 #if DEBUG_SYS
900         device_create_file(dev->dev, &dev_attr_debug);
901         device_create_file(dev->dev, &dev_attr_sync);
902 #endif
903
904         {
905                 struct rkvr_iio_hw_device *hw_device;
906
907                 hw_device = inv_hid_alloc("hid-rkvr");
908                 if (!hw_device) {
909                         hid_err(hid, "inv_hid_alloc(\"hid-rkvr\") fail\n");
910                         rkvr_hidraw_table[minor] = NULL;
911                         mutex_unlock(&minors_lock);
912                         result = PTR_ERR(dev->dev);
913                         kfree(dev);
914                         goto out;
915                 }
916                 hw_device->dev = &hid->dev;
917                 hw_device->open = rkvr_hid_open;
918                 hw_device->close = rkvr_hid_close;
919                 hw_device->read = rkvr_hid_read;
920                 hw_device->write = rkvr_hid_write;
921                 if (inv_hid_register_devcie(hw_device)) {
922                         hid_err(hid, "inv_hid_register_devcie(\"hid-rkvr\") fail\n");
923                         inv_hid_free(hw_device);
924                         rkvr_hidraw_table[minor] = NULL;
925                         mutex_unlock(&minors_lock);
926                         result = PTR_ERR(dev->dev);
927                         kfree(dev);
928                         goto out;
929                 }
930         }
931
932 #if DYNAMIC_LOAD_MPU6500
933         if (!register_mpu6500) {
934                 register_mpu6500 = 1;
935                 hid_info(hid, "--->platform_device_register-->\n");
936                 platform_device_register(&mpu6500_dev);
937         }
938 #endif
939
940         if (hid_hw_open(hid)) {
941                 rkvr_hidraw_table[minor] = NULL;
942                 mutex_unlock(&minors_lock);
943                 result = PTR_ERR(dev->dev);
944                 kfree(dev);
945                 hid_err(hid, "rkvr_connect:hid_hw_open fail\n");
946                 goto out;
947         }
948
949         init_waitqueue_head(&dev->wait);
950         spin_lock_init(&dev->list_lock);
951         INIT_LIST_HEAD(&dev->list);
952
953         dev->hid = hid;
954         dev->minor = minor;
955         dev->exist = 1;
956         hid->hidraw = dev; /*struct hidraw * **/
957         mutex_unlock(&minors_lock);
958 out:
959         return result;
960 }
961
962 static int rkvr_keys_remove(struct hid_device *hdev)
963 {
964         struct input_dev *input = hdev->hiddev;
965
966         input_unregister_device(input);
967         return 0;
968 }
969
970 static unsigned int key_codes[] = {
971         KEY_MENU,
972         KEY_HOME,
973         KEY_POWER,
974         KEY_VOLUMEUP,
975         KEY_VOLUMEDOWN,
976         KEY_WAKEUP,
977         KEY_ESC,
978         KEY_LEFT,
979         KEY_RIGHT,
980         KEY_UP,
981         KEY_DOWN,
982         KEY_ENTER
983 };
984
985 static int __must_check rkvr_keys_probe(struct hid_device *hdev)
986 {
987
988         struct device *dev = &hdev->dev;
989         struct input_dev *input = NULL;
990         int i, error = 0;
991
992         input = devm_input_allocate_device(dev);
993         if (!input) {
994                 hid_err(hdev, "input_allocate_device fail\n");
995                 return -ENOMEM;
996         }
997         input->name = "rkvr-keypad";
998         input->phys = "rkvr-keys/input0";
999         input->dev.parent = dev;
1000         input->id.bustype = BUS_HOST;
1001         input->id.vendor = 0x071b;
1002         input->id.product = 0x3205;
1003         input->id.version = 0x0001;
1004
1005         for (i = 0; i < sizeof(key_codes) / sizeof(key_codes[0]); i++) {
1006                 hid_info(hdev, "input_set_capability %d\n", key_codes[i]);
1007                 input_set_capability(input, EV_KEY, key_codes[i]);
1008         }
1009
1010         error = input_register_device(input);
1011         if (error) {
1012                 hid_err(hdev, "rkvr-s: Unable to register input device, error: %d\n", error);
1013                 return error;
1014         }
1015         hdev->hiddev = input;
1016
1017         return 0;
1018 }
1019
1020 static inline int __must_check rkvr_hw_start(struct hid_device *hdev, unsigned int connect_mask)
1021 {
1022         int ret = hdev->ll_driver->start(hdev);
1023
1024         if (ret)
1025                 return ret;
1026         ret = rkvr_connect(hdev);
1027         if (ret)
1028                 hdev->ll_driver->stop(hdev);
1029
1030         return ret;
1031 }
1032
1033 static void rkvr_disconnect(struct hid_device *hid)
1034 {
1035         struct hidraw *hidraw = hid->hidraw;
1036
1037         mutex_lock(&minors_lock);
1038         /* always unregistering inv_hid_device when hardware disconnect */
1039         inv_hid_unregister_and_destroy_devcie_by_name("hid-rkvr");
1040 #if DEBUG_SYS
1041         device_remove_file(hidraw->dev, &dev_attr_debug);
1042         device_remove_file(hidraw->dev, &dev_attr_sync);
1043 #endif
1044
1045         device_destroy(rkvr_class, MKDEV(rkvr_major, hidraw->minor));
1046         rkvr_drop_ref(hidraw, 1);
1047         mutex_unlock(&minors_lock);
1048 }
1049
1050 static void rkvr_hw_stop(struct hid_device *hdev)
1051 {
1052         rkvr_disconnect(hdev);
1053         hdev->ll_driver->stop(hdev);
1054 }
1055
1056 static long rkvr_hidraw_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1057 {
1058         struct inode *inode = file_inode(file);
1059         unsigned int minor = iminor(inode);
1060         long ret = 0;
1061         struct hidraw *dev;
1062         void __user *user_arg = (void __user *)arg;
1063
1064         mutex_lock(&minors_lock);
1065         dev = rkvr_hidraw_table[minor];
1066         if (!dev) {
1067                 ret = -ENODEV;
1068                 goto out;
1069         }
1070
1071         switch (cmd) {
1072         case HIDIOCGRDESCSIZE:
1073                 if (put_user(dev->hid->rsize, (int __user *)arg))
1074                         ret = -EFAULT;
1075                 break;
1076
1077         case HIDIOCGRDESC:
1078                 {
1079                         __u32 len;
1080
1081                         if (get_user(len, (int __user *)arg))
1082                                 ret = -EFAULT;
1083                         else if (len > HID_MAX_DESCRIPTOR_SIZE - 1)
1084                                 ret = -EINVAL;
1085                         else if (copy_to_user(user_arg + offsetof(
1086                                 struct hidraw_report_descriptor,
1087                                 value[0]),
1088                                 dev->hid->rdesc,
1089                                 min(dev->hid->rsize, len)))
1090                                 ret = -EFAULT;
1091                         break;
1092                 }
1093         case HIDIOCGRAWINFO:
1094                 {
1095                         struct hidraw_devinfo dinfo;
1096
1097                         dinfo.bustype = dev->hid->bus;
1098                         dinfo.vendor = dev->hid->vendor;
1099                         dinfo.product = dev->hid->product;
1100                         if (copy_to_user(user_arg, &dinfo, sizeof(dinfo)))
1101                                 ret = -EFAULT;
1102                         break;
1103                 }
1104         default:
1105                 {
1106                         struct hid_device *hid = dev->hid;
1107
1108                         if (_IOC_TYPE(cmd) != 'H') {
1109                                 ret = -EINVAL;
1110                                 break;
1111                         }
1112
1113                         if (_IOC_NR(cmd) == _IOC_NR(HIDIOCSFEATURE(0))) {
1114                                 int len = _IOC_SIZE(cmd);
1115
1116                                 ret = rkvr_hidraw_send_report(file, user_arg, len, HID_FEATURE_REPORT);
1117                                 break;
1118                         }
1119                         if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGFEATURE(0))) {
1120                                 int len = _IOC_SIZE(cmd);
1121
1122                                 ret = rkvr_hidraw_get_report(file, user_arg, len, HID_FEATURE_REPORT);
1123                                 break;
1124                         }
1125
1126                         if (_IOC_NR(cmd) == _IOC_NR(HIDRKVRHANDSHAKE(0))) {
1127                                 int len = _IOC_SIZE(cmd);
1128                                 char *buf;
1129
1130                                 buf = kzalloc(len + 1, GFP_KERNEL);
1131                                 if (!buf) {
1132                                         ret = -ENOMEM;
1133                                         break;
1134                                 }
1135                                 if (copy_from_user(buf, user_arg, len)) {
1136                                         ret = -EFAULT;
1137                                         kfree(buf);
1138                                         break;
1139                                 }
1140                                 ret = hid_report_sync(&hid->dev, buf, len);
1141                                 kfree(buf);
1142                                 break;
1143                         }
1144
1145                         /* Begin Read-only ioctls. */
1146                         if (_IOC_DIR(cmd) != _IOC_READ) {
1147                                 ret = -EINVAL;
1148                                 break;
1149                         }
1150
1151                         if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWNAME(0))) {
1152                                 int len = strlen(hid->name) + 1;
1153
1154                                 if (len > _IOC_SIZE(cmd))
1155                                         len = _IOC_SIZE(cmd);
1156                                 ret = copy_to_user(user_arg, hid->name, len) ?
1157                                         -EFAULT : len;
1158                                 break;
1159                         }
1160
1161                         if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWPHYS(0))) {
1162                                 int len = strlen(hid->phys) + 1;
1163
1164                                 if (len > _IOC_SIZE(cmd))
1165                                         len = _IOC_SIZE(cmd);
1166                                 ret = copy_to_user(user_arg, hid->phys, len) ?
1167                                         -EFAULT : len;
1168                                 break;
1169                         }
1170                 }
1171
1172         ret = -ENOTTY;
1173         }
1174 out:
1175         mutex_unlock(&minors_lock);
1176         return ret;
1177 }
1178
1179 static const struct file_operations rkvr_ops = {
1180         .owner = THIS_MODULE,
1181         .read = rkvr_hidraw_read,
1182         .write = rkvr_hidraw_write,
1183         .poll = rkvr_hidraw_poll,
1184         .open = rkvr_hidraw_open,
1185         .release = rkvr_hidraw_release,
1186         .unlocked_ioctl = rkvr_hidraw_ioctl,
1187 #ifdef CONFIG_COMPAT
1188         .compat_ioctl   = rkvr_hidraw_ioctl,
1189 #endif
1190         .fasync = rkvr_hidraw_fasync,
1191         .llseek = noop_llseek,
1192 };
1193
1194 int rkvr_sensor_register_callback(int (*callback)(char *, size_t, void *), void *priv)
1195 {
1196         sensorData.priv = priv;
1197         sensorData.send_event = callback;
1198
1199         return 0;
1200 }
1201 EXPORT_SYMBOL_GPL(rkvr_sensor_register_callback);
1202
1203 static int rkvr_probe(struct hid_device *hdev, const struct hid_device_id *id)
1204 {
1205         int retval;
1206         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1207
1208         retval = hid_parse(hdev);
1209         if (retval) {
1210                 hid_err(hdev, "rkvr - parse failed\n");
1211                 goto exit;
1212         }
1213         hid_set_drvdata(hdev, &sensorData);
1214         if (intf->cur_altsetting->desc.bInterfaceNumber == RKVR_INTERFACE_USB_SENSOR_ID) {
1215                 retval = rkvr_keys_probe(hdev);
1216                 if (retval) {
1217                         hid_err(hdev, "rkvr_keys_probe failed\n");
1218                         goto exit_stop;
1219                 }
1220                 retval = rkvr_hw_start(hdev, 0);
1221                 if (retval) {
1222                         hid_err(hdev, "rkvr - rkvr hw start failed\n");
1223                         rkvr_keys_remove(hdev);
1224                         goto exit_stop;
1225                 }
1226         } else {
1227                 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1228                 if (retval) {
1229                         hid_err(hdev, "rkvr - hid hw start failed\n");
1230                         goto exit;
1231                 }
1232         }
1233
1234         return 0;
1235
1236 exit_stop:
1237         hid_hw_stop(hdev);
1238 exit:
1239         return retval;
1240 }
1241
1242 static void rkvr_remove(struct hid_device *hdev)
1243 {
1244         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1245
1246         if (intf->cur_altsetting->desc.bInterfaceNumber == RKVR_INTERFACE_USB_SENSOR_ID) {
1247                 rkvr_hw_stop(hdev);
1248                 rkvr_keys_remove(hdev);
1249         } else {
1250                 hid_hw_stop(hdev);
1251         }
1252 }
1253
1254 static int rkvr_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size)
1255 {
1256         int retval = 0;
1257         static unsigned int count;
1258         static unsigned long old_jiffy;
1259
1260         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1261
1262         if (intf->cur_altsetting->desc.bInterfaceNumber != RKVR_INTERFACE_USB_SENSOR_ID) {
1263                 hid_info(hdev, "%s,ignored interface number is %d\n", __func__,
1264                         intf->cur_altsetting->desc.bInterfaceNumber);
1265                 return 0;
1266         }
1267
1268         /* print sensor poll frequency */
1269         if (++count >= 1000) {
1270                 unsigned long cur_jiffy = jiffies;
1271
1272                 hid_dbg(hdev, "rkvr: %d Hz, hidrkvr %d\n", (int)(1000 * HZ / (cur_jiffy - old_jiffy)), (hdev->hidraw ? 1 : 0));
1273                 count = 0;
1274                 old_jiffy = cur_jiffy;
1275         }
1276
1277         if (hdev->hidraw || hdev->hiddev) {
1278                 retval = rkvr_report_event(hdev, data, size);
1279                 if (retval < 0)
1280                         hid_info(hdev, "rkvr: raw event err %d\n", retval);
1281         }
1282
1283         return retval;
1284 }
1285
1286 static const struct hid_device_id rkvr_devices[] = {
1287         { HID_USB_DEVICE(USB_VENDOR_ID_ROCKCHIP, USB_DEVICE_ID_NANOC) },
1288         { }
1289 };
1290
1291 MODULE_DEVICE_TABLE(hid, rkvr_devices);
1292
1293 static struct hid_driver rkvr_driver = {
1294         .name = "rkvr",
1295         .id_table = rkvr_devices,
1296         .probe = rkvr_probe,
1297         .remove = rkvr_remove,
1298         .raw_event = rkvr_raw_event
1299 };
1300
1301 static int __init rkvr_init(void)
1302 {
1303         int retval;
1304         dev_t dev_id;
1305
1306         rkvr_class = class_create(THIS_MODULE, "rkvr");
1307         if (IS_ERR(rkvr_class))
1308                 return PTR_ERR(rkvr_class);
1309
1310         retval = hid_register_driver(&rkvr_driver);
1311         if (retval < 0) {
1312                 pr_warn("rkvr_init - Can't register drive.\n");
1313                 goto out_class;
1314         }
1315
1316         retval = alloc_chrdev_region(&dev_id, RKVR_FIRST_MINOR,
1317                                         RKVR_HIDRAW_MAX_DEVICES, "rkvr");
1318         if (retval < 0) {
1319                 pr_warn("rkvr_init - Can't allocate chrdev region.\n");
1320                 goto out_register;
1321         }
1322
1323         rkvr_major = MAJOR(dev_id);
1324         cdev_init(&rkvr_cdev, &rkvr_ops);
1325         cdev_add(&rkvr_cdev, dev_id, RKVR_HIDRAW_MAX_DEVICES);
1326         return 0;
1327
1328 out_register:
1329         hid_unregister_driver(&rkvr_driver);
1330 out_class:
1331         class_destroy(rkvr_class);
1332
1333         return retval;
1334 }
1335
1336 static void __exit rkvr_exit(void)
1337 {
1338         dev_t dev_id = MKDEV(rkvr_major, 0);
1339
1340         cdev_del(&rkvr_cdev);
1341
1342         unregister_chrdev_region(dev_id, RKVR_HIDRAW_MAX_DEVICES);
1343
1344         hid_unregister_driver(&rkvr_driver);
1345         class_destroy(rkvr_class);
1346 }
1347
1348 module_init(rkvr_init);
1349 module_exit(rkvr_exit);
1350
1351 MODULE_AUTHOR("zwp");
1352 MODULE_DESCRIPTION("USB ROCKCHIP VR char device driver.");
1353 MODULE_LICENSE("GPL v2");