synaptics_rmi_dev.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Synaptics RMI4 touchscreen driver
  3. *
  4. * Copyright (C) 2012 Synaptics Incorporated
  5. *
  6. * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
  7. * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/i2c.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/input.h>
  26. #include <linux/gpio.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/cdev.h>
  29. #include <linux/input/synaptics_dsx.h>
  30. #include "synaptics_i2c_rmi4.h"
  31. #define CHAR_DEVICE_NAME "rmi"
  32. #define DEVICE_CLASS_NAME "rmidev"
  33. #define DEV_NUMBER 1
  34. #define REG_ADDR_LIMIT 0xFFFF
  35. static ssize_t rmidev_sysfs_open_store(struct device *dev,
  36. struct device_attribute *attr, const char *buf, size_t count);
  37. static ssize_t rmidev_sysfs_release_store(struct device *dev,
  38. struct device_attribute *attr, const char *buf, size_t count);
  39. static ssize_t rmidev_sysfs_address_store(struct device *dev,
  40. struct device_attribute *attr, const char *buf, size_t count);
  41. static ssize_t rmidev_sysfs_length_store(struct device *dev,
  42. struct device_attribute *attr, const char *buf, size_t count);
  43. static ssize_t rmidev_sysfs_data_show(struct device *dev,
  44. struct device_attribute *attr, char *buf);
  45. static ssize_t rmidev_sysfs_data_store(struct device *dev,
  46. struct device_attribute *attr, const char *buf, size_t count);
  47. struct rmidev_handle {
  48. dev_t dev_no;
  49. unsigned short address;
  50. unsigned int length;
  51. struct device dev;
  52. struct synaptics_rmi4_data *rmi4_data;
  53. struct synaptics_rmi4_exp_fn_ptr *fn_ptr;
  54. struct kobject *sysfs_dir;
  55. void *data;
  56. };
  57. struct rmidev_data {
  58. int ref_count;
  59. struct cdev main_dev;
  60. struct class *device_class;
  61. struct mutex file_mutex;
  62. struct rmidev_handle *rmi_dev;
  63. };
  64. static struct device_attribute attrs[] = {
  65. __ATTR(open, S_IWUSR,
  66. NULL,
  67. rmidev_sysfs_open_store),
  68. __ATTR(release, S_IWUSR,
  69. NULL,
  70. rmidev_sysfs_release_store),
  71. __ATTR(address, S_IWUSR,
  72. NULL,
  73. rmidev_sysfs_address_store),
  74. __ATTR(length, S_IWUSR,
  75. NULL,
  76. rmidev_sysfs_length_store),
  77. __ATTR(data, S_IWUSR,
  78. rmidev_sysfs_data_show,
  79. rmidev_sysfs_data_store),
  80. };
  81. static int rmidev_major_num;
  82. static struct class *rmidev_device_class;
  83. static struct rmidev_handle *rmidev;
  84. static struct completion remove_complete;
  85. static ssize_t rmidev_sysfs_open_store(struct device *dev,
  86. struct device_attribute *attr, const char *buf, size_t count)
  87. {
  88. unsigned int input;
  89. if (sscanf(buf, "%u", &input) != 1)
  90. return -EINVAL;
  91. if (input != 1)
  92. return -EINVAL;
  93. rmidev->fn_ptr->enable(rmidev->rmi4_data, false);
  94. dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
  95. "%s: Attention interrupt disabled\n",
  96. __func__);
  97. return count;
  98. }
  99. static ssize_t rmidev_sysfs_release_store(struct device *dev,
  100. struct device_attribute *attr, const char *buf, size_t count)
  101. {
  102. unsigned int input;
  103. if (sscanf(buf, "%u", &input) != 1)
  104. return -EINVAL;
  105. if (input != 1)
  106. return -EINVAL;
  107. rmidev->fn_ptr->enable(rmidev->rmi4_data, true);
  108. dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
  109. "%s: Attention interrupt enabled\n",
  110. __func__);
  111. return count;
  112. }
  113. static ssize_t rmidev_sysfs_address_store(struct device *dev,
  114. struct device_attribute *attr, const char *buf, size_t count)
  115. {
  116. unsigned int input;
  117. if (sscanf(buf, "%u", &input) != 1)
  118. return -EINVAL;
  119. if (input > REG_ADDR_LIMIT)
  120. return -EINVAL;
  121. rmidev->address = (unsigned short)input;
  122. return count;
  123. }
  124. static ssize_t rmidev_sysfs_length_store(struct device *dev,
  125. struct device_attribute *attr, const char *buf, size_t count)
  126. {
  127. unsigned int input;
  128. if (sscanf(buf, "%u", &input) != 1)
  129. return -EINVAL;
  130. if (input > REG_ADDR_LIMIT)
  131. return -EINVAL;
  132. rmidev->length = input;
  133. return count;
  134. }
  135. static ssize_t rmidev_sysfs_data_show(struct device *dev,
  136. struct device_attribute *attr, char *buf)
  137. {
  138. int retval;
  139. unsigned int data_length = rmidev->length;
  140. if (data_length > (REG_ADDR_LIMIT - rmidev->address))
  141. data_length = REG_ADDR_LIMIT - rmidev->address;
  142. if (data_length) {
  143. retval = rmidev->fn_ptr->read(rmidev->rmi4_data,
  144. rmidev->address,
  145. (unsigned char *)buf,
  146. data_length);
  147. if (retval < 0) {
  148. dev_err(&rmidev->rmi4_data->i2c_client->dev,
  149. "%s: Failed to read data\n",
  150. __func__);
  151. return retval;
  152. }
  153. } else {
  154. return -EINVAL;
  155. }
  156. return data_length;
  157. }
  158. static ssize_t rmidev_sysfs_data_store(struct device *dev,
  159. struct device_attribute *attr, const char *buf, size_t count)
  160. {
  161. int retval;
  162. unsigned int data_length = rmidev->length;
  163. if (data_length > (REG_ADDR_LIMIT - rmidev->address))
  164. data_length = REG_ADDR_LIMIT - rmidev->address;
  165. if (data_length) {
  166. retval = rmidev->fn_ptr->write(rmidev->rmi4_data,
  167. rmidev->address,
  168. (unsigned char *)buf,
  169. data_length);
  170. if (retval < 0) {
  171. dev_err(&rmidev->rmi4_data->i2c_client->dev,
  172. "%s: Failed to write data\n",
  173. __func__);
  174. return retval;
  175. }
  176. } else {
  177. return -EINVAL;
  178. }
  179. return data_length;
  180. }
  181. /*
  182. * rmidev_llseek - used to set up register address
  183. *
  184. * @filp: file structure for seek
  185. * @off: offset
  186. * if whence == SEEK_SET,
  187. * high 16 bits: page address
  188. * low 16 bits: register address
  189. * if whence == SEEK_CUR,
  190. * offset from current position
  191. * if whence == SEEK_END,
  192. * offset from end position (0xFFFF)
  193. * @whence: SEEK_SET, SEEK_CUR, or SEEK_END
  194. */
  195. static loff_t rmidev_llseek(struct file *filp, loff_t off, int whence)
  196. {
  197. loff_t newpos;
  198. struct rmidev_data *dev_data = filp->private_data;
  199. if (IS_ERR(dev_data)) {
  200. pr_err("%s: Pointer of char device data is invalid", __func__);
  201. return -EBADF;
  202. }
  203. mutex_lock(&(dev_data->file_mutex));
  204. switch (whence) {
  205. case SEEK_SET:
  206. newpos = off;
  207. break;
  208. case SEEK_CUR:
  209. newpos = filp->f_pos + off;
  210. break;
  211. case SEEK_END:
  212. newpos = REG_ADDR_LIMIT + off;
  213. break;
  214. default:
  215. newpos = -EINVAL;
  216. goto clean_up;
  217. }
  218. if (newpos < 0 || newpos > REG_ADDR_LIMIT) {
  219. dev_err(&rmidev->rmi4_data->i2c_client->dev,
  220. "%s: New position 0x%04x is invalid\n",
  221. __func__, (unsigned int)newpos);
  222. newpos = -EINVAL;
  223. goto clean_up;
  224. }
  225. filp->f_pos = newpos;
  226. clean_up:
  227. mutex_unlock(&(dev_data->file_mutex));
  228. return newpos;
  229. }
  230. /*
  231. * rmidev_read: - use to read data from rmi device
  232. *
  233. * @filp: file structure for read
  234. * @buf: user space buffer pointer
  235. * @count: number of bytes to read
  236. * @f_pos: offset (starting register address)
  237. */
  238. static ssize_t rmidev_read(struct file *filp, char __user *buf,
  239. size_t count, loff_t *f_pos)
  240. {
  241. ssize_t retval;
  242. unsigned char *tmpbuf;
  243. struct rmidev_data *dev_data = filp->private_data;
  244. if (IS_ERR(dev_data)) {
  245. pr_err("%s: Pointer of char device data is invalid", __func__);
  246. return -EBADF;
  247. }
  248. mutex_lock(&(dev_data->file_mutex));
  249. if (count > (REG_ADDR_LIMIT - *f_pos))
  250. count = REG_ADDR_LIMIT - *f_pos;
  251. if (count == 0) {
  252. retval = 0;
  253. goto unlock;
  254. }
  255. if (*f_pos > REG_ADDR_LIMIT) {
  256. retval = -EFAULT;
  257. goto unlock;
  258. }
  259. tmpbuf = kzalloc(count + 1, GFP_KERNEL);
  260. if (!tmpbuf) {
  261. retval = -ENOMEM;
  262. goto unlock;
  263. }
  264. retval = rmidev->fn_ptr->read(rmidev->rmi4_data,
  265. *f_pos,
  266. tmpbuf,
  267. count);
  268. if (retval < 0)
  269. goto clean_up;
  270. if (copy_to_user(buf, tmpbuf, count))
  271. retval = -EFAULT;
  272. else
  273. *f_pos += retval;
  274. clean_up:
  275. kfree(tmpbuf);
  276. unlock:
  277. mutex_unlock(&(dev_data->file_mutex));
  278. return retval;
  279. }
  280. /*
  281. * rmidev_write: - used to write data to rmi device
  282. *
  283. * @filep: file structure for write
  284. * @buf: user space buffer pointer
  285. * @count: number of bytes to write
  286. * @f_pos: offset (starting register address)
  287. */
  288. static ssize_t rmidev_write(struct file *filp, const char __user *buf,
  289. size_t count, loff_t *f_pos)
  290. {
  291. ssize_t retval;
  292. unsigned char *tmpbuf;
  293. struct rmidev_data *dev_data = filp->private_data;
  294. if (IS_ERR(dev_data)) {
  295. pr_err("%s: Pointer of char device data is invalid", __func__);
  296. return -EBADF;
  297. }
  298. mutex_lock(&(dev_data->file_mutex));
  299. if (*f_pos > REG_ADDR_LIMIT) {
  300. retval = -EFAULT;
  301. goto unlock;
  302. }
  303. if (count > (REG_ADDR_LIMIT - *f_pos))
  304. count = REG_ADDR_LIMIT - *f_pos;
  305. if (count == 0) {
  306. retval = 0;
  307. goto unlock;
  308. }
  309. tmpbuf = kzalloc(count + 1, GFP_KERNEL);
  310. if (!tmpbuf) {
  311. retval = -ENOMEM;
  312. goto unlock;
  313. }
  314. if (copy_from_user(tmpbuf, buf, count)) {
  315. retval = -EFAULT;
  316. goto clean_up;
  317. }
  318. retval = rmidev->fn_ptr->write(rmidev->rmi4_data,
  319. *f_pos,
  320. tmpbuf,
  321. count);
  322. if (retval >= 0)
  323. *f_pos += retval;
  324. clean_up:
  325. kfree(tmpbuf);
  326. unlock:
  327. mutex_unlock(&(dev_data->file_mutex));
  328. return retval;
  329. }
  330. /*
  331. * rmidev_open: enable access to rmi device
  332. * @inp: inode struture
  333. * @filp: file structure
  334. */
  335. static int rmidev_open(struct inode *inp, struct file *filp)
  336. {
  337. int retval = 0;
  338. struct rmidev_data *dev_data =
  339. container_of(inp->i_cdev, struct rmidev_data, main_dev);
  340. if (!dev_data)
  341. return -EACCES;
  342. filp->private_data = dev_data;
  343. mutex_lock(&(dev_data->file_mutex));
  344. rmidev->fn_ptr->enable(rmidev->rmi4_data, false);
  345. dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
  346. "%s: Attention interrupt disabled\n",
  347. __func__);
  348. if (dev_data->ref_count < 1)
  349. dev_data->ref_count++;
  350. else
  351. retval = -EACCES;
  352. mutex_unlock(&(dev_data->file_mutex));
  353. return retval;
  354. }
  355. /*
  356. * rmidev_release: - release access to rmi device
  357. * @inp: inode structure
  358. * @filp: file structure
  359. */
  360. static int rmidev_release(struct inode *inp, struct file *filp)
  361. {
  362. struct rmidev_data *dev_data =
  363. container_of(inp->i_cdev, struct rmidev_data, main_dev);
  364. if (!dev_data)
  365. return -EACCES;
  366. mutex_lock(&(dev_data->file_mutex));
  367. dev_data->ref_count--;
  368. if (dev_data->ref_count < 0)
  369. dev_data->ref_count = 0;
  370. rmidev->fn_ptr->enable(rmidev->rmi4_data, true);
  371. dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
  372. "%s: Attention interrupt enabled\n",
  373. __func__);
  374. mutex_unlock(&(dev_data->file_mutex));
  375. return 0;
  376. }
  377. static const struct file_operations rmidev_fops = {
  378. .owner = THIS_MODULE,
  379. .llseek = rmidev_llseek,
  380. .read = rmidev_read,
  381. .write = rmidev_write,
  382. .open = rmidev_open,
  383. .release = rmidev_release,
  384. };
  385. static void rmidev_device_cleanup(struct rmidev_data *dev_data)
  386. {
  387. dev_t devno;
  388. if (dev_data) {
  389. devno = dev_data->main_dev.dev;
  390. if (dev_data->device_class)
  391. device_destroy(dev_data->device_class, devno);
  392. cdev_del(&dev_data->main_dev);
  393. unregister_chrdev_region(devno, 1);
  394. dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
  395. "%s: rmidev device removed\n",
  396. __func__);
  397. }
  398. return;
  399. }
  400. static char *rmi_char_devnode(struct device *dev, umode_t *mode)
  401. {
  402. if (!mode)
  403. return NULL;
  404. *mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  405. return kasprintf(GFP_KERNEL, "rmi/%s", dev_name(dev));
  406. }
  407. static int rmidev_create_device_class(void)
  408. {
  409. rmidev_device_class = class_create(THIS_MODULE, DEVICE_CLASS_NAME);
  410. if (IS_ERR(rmidev_device_class)) {
  411. pr_err("%s: Failed to create /dev/%s\n",
  412. __func__, CHAR_DEVICE_NAME);
  413. return -ENODEV;
  414. }
  415. rmidev_device_class->devnode = rmi_char_devnode;
  416. return 0;
  417. }
  418. static int rmidev_init_device(struct synaptics_rmi4_data *rmi4_data)
  419. {
  420. int retval;
  421. dev_t dev_no;
  422. unsigned char attr_count;
  423. struct rmidev_data *dev_data;
  424. struct device *device_ptr;
  425. rmidev = kzalloc(sizeof(*rmidev), GFP_KERNEL);
  426. if (!rmidev) {
  427. dev_err(&rmi4_data->i2c_client->dev,
  428. "%s: Failed to alloc mem for rmidev\n",
  429. __func__);
  430. retval = -ENOMEM;
  431. goto err_rmidev;
  432. }
  433. rmidev->fn_ptr = kzalloc(sizeof(*(rmidev->fn_ptr)), GFP_KERNEL);
  434. if (!rmidev) {
  435. dev_err(&rmi4_data->i2c_client->dev,
  436. "%s: Failed to alloc mem for fn_ptr\n",
  437. __func__);
  438. retval = -ENOMEM;
  439. goto err_fn_ptr;
  440. }
  441. rmidev->fn_ptr->read = rmi4_data->i2c_read;
  442. rmidev->fn_ptr->write = rmi4_data->i2c_write;
  443. rmidev->fn_ptr->enable = rmi4_data->irq_enable;
  444. rmidev->rmi4_data = rmi4_data;
  445. retval = rmidev_create_device_class();
  446. if (retval < 0) {
  447. dev_err(&rmi4_data->i2c_client->dev,
  448. "%s: Failed to create device class\n",
  449. __func__);
  450. goto err_device_class;
  451. }
  452. if (rmidev_major_num) {
  453. dev_no = MKDEV(rmidev_major_num, DEV_NUMBER);
  454. retval = register_chrdev_region(dev_no, 1, CHAR_DEVICE_NAME);
  455. } else {
  456. retval = alloc_chrdev_region(&dev_no, 0, 1, CHAR_DEVICE_NAME);
  457. if (retval < 0) {
  458. dev_err(&rmi4_data->i2c_client->dev,
  459. "%s: Failed to allocate char device region\n",
  460. __func__);
  461. goto err_device_region;
  462. }
  463. rmidev_major_num = MAJOR(dev_no);
  464. dev_dbg(&rmi4_data->i2c_client->dev,
  465. "%s: Major number of rmidev = %d\n",
  466. __func__, rmidev_major_num);
  467. }
  468. dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL);
  469. if (!dev_data) {
  470. dev_err(&rmi4_data->i2c_client->dev,
  471. "%s: Failed to alloc mem for dev_data\n",
  472. __func__);
  473. retval = -ENOMEM;
  474. goto err_dev_data;
  475. }
  476. mutex_init(&dev_data->file_mutex);
  477. dev_data->rmi_dev = rmidev;
  478. rmidev->data = dev_data;
  479. cdev_init(&dev_data->main_dev, &rmidev_fops);
  480. retval = cdev_add(&dev_data->main_dev, dev_no, 1);
  481. if (retval < 0) {
  482. dev_err(&rmi4_data->i2c_client->dev,
  483. "%s: Failed to add rmi char device\n",
  484. __func__);
  485. goto err_char_device;
  486. }
  487. dev_set_name(&rmidev->dev, "rmidev%d", MINOR(dev_no));
  488. dev_data->device_class = rmidev_device_class;
  489. device_ptr = device_create(dev_data->device_class, NULL, dev_no,
  490. NULL, CHAR_DEVICE_NAME"%d", MINOR(dev_no));
  491. if (IS_ERR(device_ptr)) {
  492. dev_err(&rmi4_data->i2c_client->dev,
  493. "%s: Failed to create rmi char device\n",
  494. __func__);
  495. retval = -ENODEV;
  496. goto err_char_device;
  497. }
  498. retval = gpio_export(rmi4_data->board->irq_gpio, false);
  499. if (retval < 0) {
  500. dev_err(&rmi4_data->i2c_client->dev,
  501. "%s: Failed to export attention gpio\n",
  502. __func__);
  503. } else {
  504. retval = gpio_export_link(&(rmi4_data->input_dev->dev),
  505. "attn", rmi4_data->board->irq_gpio);
  506. if (retval < 0) {
  507. dev_err(&rmi4_data->input_dev->dev,
  508. "%s Failed to create gpio symlink\n",
  509. __func__);
  510. } else {
  511. dev_dbg(&rmi4_data->input_dev->dev,
  512. "%s: Exported attention gpio %d\n",
  513. __func__, rmi4_data->board->irq_gpio);
  514. }
  515. }
  516. rmidev->sysfs_dir = kobject_create_and_add("rmidev",
  517. &rmi4_data->input_dev->dev.kobj);
  518. if (!rmidev->sysfs_dir) {
  519. dev_err(&rmi4_data->i2c_client->dev,
  520. "%s: Failed to create sysfs directory\n",
  521. __func__);
  522. goto err_sysfs_dir;
  523. }
  524. for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
  525. retval = sysfs_create_file(rmidev->sysfs_dir,
  526. &attrs[attr_count].attr);
  527. if (retval < 0) {
  528. dev_err(&rmi4_data->input_dev->dev,
  529. "%s: Failed to create sysfs attributes\n",
  530. __func__);
  531. retval = -ENODEV;
  532. goto err_sysfs_attrs;
  533. }
  534. }
  535. init_completion(&remove_complete);
  536. return 0;
  537. err_sysfs_attrs:
  538. for (attr_count--; attr_count >= 0; attr_count--) {
  539. sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
  540. &attrs[attr_count].attr);
  541. }
  542. kobject_put(rmidev->sysfs_dir);
  543. err_sysfs_dir:
  544. err_char_device:
  545. rmidev_device_cleanup(dev_data);
  546. kfree(dev_data);
  547. err_dev_data:
  548. unregister_chrdev_region(dev_no, 1);
  549. err_device_region:
  550. class_destroy(rmidev_device_class);
  551. err_device_class:
  552. kfree(rmidev->fn_ptr);
  553. err_fn_ptr:
  554. kfree(rmidev);
  555. err_rmidev:
  556. return retval;
  557. }
  558. static void rmidev_remove_device(struct synaptics_rmi4_data *rmi4_data)
  559. {
  560. unsigned char attr_count;
  561. struct rmidev_data *dev_data;
  562. if (!rmidev)
  563. return;
  564. for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++)
  565. sysfs_remove_file(rmidev->sysfs_dir, &attrs[attr_count].attr);
  566. kobject_put(rmidev->sysfs_dir);
  567. dev_data = rmidev->data;
  568. if (dev_data) {
  569. rmidev_device_cleanup(dev_data);
  570. kfree(dev_data);
  571. }
  572. unregister_chrdev_region(rmidev->dev_no, 1);
  573. class_destroy(rmidev_device_class);
  574. kfree(rmidev->fn_ptr);
  575. kfree(rmidev);
  576. complete(&remove_complete);
  577. return;
  578. }
  579. static int __init rmidev_module_init(void)
  580. {
  581. synaptics_rmi4_new_function(RMI_DEV, true,
  582. rmidev_init_device,
  583. rmidev_remove_device,
  584. NULL);
  585. return 0;
  586. }
  587. static void __exit rmidev_module_exit(void)
  588. {
  589. init_completion(&remove_complete);
  590. synaptics_rmi4_new_function(RMI_DEV, false,
  591. rmidev_init_device,
  592. rmidev_remove_device,
  593. NULL);
  594. wait_for_completion(&remove_complete);
  595. return;
  596. }
  597. module_init(rmidev_module_init);
  598. module_exit(rmidev_module_exit);
  599. MODULE_AUTHOR("Synaptics, Inc.");
  600. MODULE_DESCRIPTION("RMI4 RMI_Dev Module");
  601. MODULE_LICENSE("GPL v2");