joydev.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * Joystick device driver for the input driver suite.
  3. *
  4. * Copyright (c) 1999-2002 Vojtech Pavlik
  5. * Copyright (c) 1999 Colin Van Dyke
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <asm/io.h>
  13. #include <asm/system.h>
  14. #include <linux/delay.h>
  15. #include <linux/errno.h>
  16. #include <linux/joystick.h>
  17. #include <linux/input.h>
  18. #include <linux/kernel.h>
  19. #include <linux/major.h>
  20. #include <linux/slab.h>
  21. #include <linux/mm.h>
  22. #include <linux/miscdevice.h>
  23. #include <linux/module.h>
  24. #include <linux/poll.h>
  25. #include <linux/init.h>
  26. #include <linux/smp_lock.h>
  27. #include <linux/device.h>
  28. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  29. MODULE_DESCRIPTION("Joystick device interfaces");
  30. MODULE_SUPPORTED_DEVICE("input/js");
  31. MODULE_LICENSE("GPL");
  32. #define JOYDEV_MINOR_BASE 0
  33. #define JOYDEV_MINORS 16
  34. #define JOYDEV_BUFFER_SIZE 64
  35. struct joydev {
  36. int exist;
  37. int open;
  38. int minor;
  39. char name[16];
  40. struct input_handle handle;
  41. wait_queue_head_t wait;
  42. struct list_head client_list;
  43. struct js_corr corr[ABS_MAX + 1];
  44. struct JS_DATA_SAVE_TYPE glue;
  45. int nabs;
  46. int nkey;
  47. __u16 keymap[KEY_MAX - BTN_MISC + 1];
  48. __u16 keypam[KEY_MAX - BTN_MISC + 1];
  49. __u8 absmap[ABS_MAX + 1];
  50. __u8 abspam[ABS_MAX + 1];
  51. __s16 abs[ABS_MAX + 1];
  52. };
  53. struct joydev_client {
  54. struct js_event buffer[JOYDEV_BUFFER_SIZE];
  55. int head;
  56. int tail;
  57. int startup;
  58. struct fasync_struct *fasync;
  59. struct joydev *joydev;
  60. struct list_head node;
  61. };
  62. static struct joydev *joydev_table[JOYDEV_MINORS];
  63. static int joydev_correct(int value, struct js_corr *corr)
  64. {
  65. switch (corr->type) {
  66. case JS_CORR_NONE:
  67. break;
  68. case JS_CORR_BROKEN:
  69. value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 :
  70. ((corr->coef[3] * (value - corr->coef[1])) >> 14)) :
  71. ((corr->coef[2] * (value - corr->coef[0])) >> 14);
  72. break;
  73. default:
  74. return 0;
  75. }
  76. return value < -32767 ? -32767 : (value > 32767 ? 32767 : value);
  77. }
  78. static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  79. {
  80. struct joydev *joydev = handle->private;
  81. struct joydev_client *client;
  82. struct js_event event;
  83. switch (type) {
  84. case EV_KEY:
  85. if (code < BTN_MISC || value == 2)
  86. return;
  87. event.type = JS_EVENT_BUTTON;
  88. event.number = joydev->keymap[code - BTN_MISC];
  89. event.value = value;
  90. break;
  91. case EV_ABS:
  92. event.type = JS_EVENT_AXIS;
  93. event.number = joydev->absmap[code];
  94. event.value = joydev_correct(value, joydev->corr + event.number);
  95. if (event.value == joydev->abs[event.number])
  96. return;
  97. joydev->abs[event.number] = event.value;
  98. break;
  99. default:
  100. return;
  101. }
  102. event.time = jiffies_to_msecs(jiffies);
  103. list_for_each_entry(client, &joydev->client_list, node) {
  104. memcpy(client->buffer + client->head, &event, sizeof(struct js_event));
  105. if (client->startup == joydev->nabs + joydev->nkey)
  106. if (client->tail == (client->head = (client->head + 1) & (JOYDEV_BUFFER_SIZE - 1)))
  107. client->startup = 0;
  108. kill_fasync(&client->fasync, SIGIO, POLL_IN);
  109. }
  110. wake_up_interruptible(&joydev->wait);
  111. }
  112. static int joydev_fasync(int fd, struct file *file, int on)
  113. {
  114. int retval;
  115. struct joydev_client *client = file->private_data;
  116. retval = fasync_helper(fd, file, on, &client->fasync);
  117. return retval < 0 ? retval : 0;
  118. }
  119. static void joydev_free(struct joydev *joydev)
  120. {
  121. joydev_table[joydev->minor] = NULL;
  122. kfree(joydev);
  123. }
  124. static int joydev_release(struct inode *inode, struct file *file)
  125. {
  126. struct joydev_client *client = file->private_data;
  127. struct joydev *joydev = client->joydev;
  128. joydev_fasync(-1, file, 0);
  129. list_del(&client->node);
  130. kfree(client);
  131. if (!--joydev->open) {
  132. if (joydev->exist)
  133. input_close_device(&joydev->handle);
  134. else
  135. joydev_free(joydev);
  136. }
  137. return 0;
  138. }
  139. static int joydev_open(struct inode *inode, struct file *file)
  140. {
  141. struct joydev_client *client;
  142. struct joydev *joydev;
  143. int i = iminor(inode) - JOYDEV_MINOR_BASE;
  144. int error;
  145. if (i >= JOYDEV_MINORS)
  146. return -ENODEV;
  147. joydev = joydev_table[i];
  148. if (!joydev || !joydev->exist)
  149. return -ENODEV;
  150. client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL);
  151. if (!client)
  152. return -ENOMEM;
  153. client->joydev = joydev;
  154. list_add_tail(&client->node, &joydev->client_list);
  155. if (!joydev->open++ && joydev->exist) {
  156. error = input_open_device(&joydev->handle);
  157. if (error) {
  158. list_del(&client->node);
  159. kfree(client);
  160. return error;
  161. }
  162. }
  163. file->private_data = client;
  164. return 0;
  165. }
  166. static ssize_t joydev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  167. {
  168. return -EINVAL;
  169. }
  170. static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  171. {
  172. struct joydev_client *client = file->private_data;
  173. struct joydev *joydev = client->joydev;
  174. struct input_dev *input = joydev->handle.dev;
  175. int retval = 0;
  176. if (!joydev->exist)
  177. return -ENODEV;
  178. if (count < sizeof(struct js_event))
  179. return -EINVAL;
  180. if (count == sizeof(struct JS_DATA_TYPE)) {
  181. struct JS_DATA_TYPE data;
  182. int i;
  183. for (data.buttons = i = 0; i < 32 && i < joydev->nkey; i++)
  184. data.buttons |= test_bit(joydev->keypam[i], input->key) ? (1 << i) : 0;
  185. data.x = (joydev->abs[0] / 256 + 128) >> joydev->glue.JS_CORR.x;
  186. data.y = (joydev->abs[1] / 256 + 128) >> joydev->glue.JS_CORR.y;
  187. if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE)))
  188. return -EFAULT;
  189. client->startup = 0;
  190. client->tail = client->head;
  191. return sizeof(struct JS_DATA_TYPE);
  192. }
  193. if (client->startup == joydev->nabs + joydev->nkey &&
  194. client->head == client->tail && (file->f_flags & O_NONBLOCK))
  195. return -EAGAIN;
  196. retval = wait_event_interruptible(joydev->wait,
  197. !joydev->exist ||
  198. client->startup < joydev->nabs + joydev->nkey ||
  199. client->head != client->tail);
  200. if (retval)
  201. return retval;
  202. if (!joydev->exist)
  203. return -ENODEV;
  204. while (client->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) {
  205. struct js_event event;
  206. event.time = jiffies_to_msecs(jiffies);
  207. if (client->startup < joydev->nkey) {
  208. event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
  209. event.number = client->startup;
  210. event.value = !!test_bit(joydev->keypam[event.number], input->key);
  211. } else {
  212. event.type = JS_EVENT_AXIS | JS_EVENT_INIT;
  213. event.number = client->startup - joydev->nkey;
  214. event.value = joydev->abs[event.number];
  215. }
  216. if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
  217. return -EFAULT;
  218. client->startup++;
  219. retval += sizeof(struct js_event);
  220. }
  221. while (client->head != client->tail && retval + sizeof(struct js_event) <= count) {
  222. if (copy_to_user(buf + retval, client->buffer + client->tail, sizeof(struct js_event)))
  223. return -EFAULT;
  224. client->tail = (client->tail + 1) & (JOYDEV_BUFFER_SIZE - 1);
  225. retval += sizeof(struct js_event);
  226. }
  227. return retval;
  228. }
  229. /* No kernel lock - fine */
  230. static unsigned int joydev_poll(struct file *file, poll_table *wait)
  231. {
  232. struct joydev_client *client = file->private_data;
  233. struct joydev *joydev = client->joydev;
  234. poll_wait(file, &joydev->wait, wait);
  235. return ((client->head != client->tail || client->startup < joydev->nabs + joydev->nkey) ?
  236. (POLLIN | POLLRDNORM) : 0) | (joydev->exist ? 0 : (POLLHUP | POLLERR));
  237. }
  238. static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp)
  239. {
  240. struct input_dev *dev = joydev->handle.dev;
  241. int i, j;
  242. switch (cmd) {
  243. case JS_SET_CAL:
  244. return copy_from_user(&joydev->glue.JS_CORR, argp,
  245. sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
  246. case JS_GET_CAL:
  247. return copy_to_user(argp, &joydev->glue.JS_CORR,
  248. sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
  249. case JS_SET_TIMEOUT:
  250. return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
  251. case JS_GET_TIMEOUT:
  252. return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
  253. case JSIOCGVERSION:
  254. return put_user(JS_VERSION, (__u32 __user *) argp);
  255. case JSIOCGAXES:
  256. return put_user(joydev->nabs, (__u8 __user *) argp);
  257. case JSIOCGBUTTONS:
  258. return put_user(joydev->nkey, (__u8 __user *) argp);
  259. case JSIOCSCORR:
  260. if (copy_from_user(joydev->corr, argp,
  261. sizeof(joydev->corr[0]) * joydev->nabs))
  262. return -EFAULT;
  263. for (i = 0; i < joydev->nabs; i++) {
  264. j = joydev->abspam[i];
  265. joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i);
  266. }
  267. return 0;
  268. case JSIOCGCORR:
  269. return copy_to_user(argp, joydev->corr,
  270. sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0;
  271. case JSIOCSAXMAP:
  272. if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1)))
  273. return -EFAULT;
  274. for (i = 0; i < joydev->nabs; i++) {
  275. if (joydev->abspam[i] > ABS_MAX)
  276. return -EINVAL;
  277. joydev->absmap[joydev->abspam[i]] = i;
  278. }
  279. return 0;
  280. case JSIOCGAXMAP:
  281. return copy_to_user(argp, joydev->abspam,
  282. sizeof(__u8) * (ABS_MAX + 1)) ? -EFAULT : 0;
  283. case JSIOCSBTNMAP:
  284. if (copy_from_user(joydev->keypam, argp, sizeof(__u16) * (KEY_MAX - BTN_MISC + 1)))
  285. return -EFAULT;
  286. for (i = 0; i < joydev->nkey; i++) {
  287. if (joydev->keypam[i] > KEY_MAX || joydev->keypam[i] < BTN_MISC)
  288. return -EINVAL;
  289. joydev->keymap[joydev->keypam[i] - BTN_MISC] = i;
  290. }
  291. return 0;
  292. case JSIOCGBTNMAP:
  293. return copy_to_user(argp, joydev->keypam,
  294. sizeof(__u16) * (KEY_MAX - BTN_MISC + 1)) ? -EFAULT : 0;
  295. default:
  296. if ((cmd & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT)) == JSIOCGNAME(0)) {
  297. int len;
  298. if (!dev->name)
  299. return 0;
  300. len = strlen(dev->name) + 1;
  301. if (len > _IOC_SIZE(cmd))
  302. len = _IOC_SIZE(cmd);
  303. if (copy_to_user(argp, dev->name, len))
  304. return -EFAULT;
  305. return len;
  306. }
  307. }
  308. return -EINVAL;
  309. }
  310. #ifdef CONFIG_COMPAT
  311. static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  312. {
  313. struct joydev_client *client = file->private_data;
  314. struct joydev *joydev = client->joydev;
  315. void __user *argp = (void __user *)arg;
  316. s32 tmp32;
  317. struct JS_DATA_SAVE_TYPE_32 ds32;
  318. int err;
  319. if (!joydev->exist)
  320. return -ENODEV;
  321. switch(cmd) {
  322. case JS_SET_TIMELIMIT:
  323. err = get_user(tmp32, (s32 __user *) arg);
  324. if (err == 0)
  325. joydev->glue.JS_TIMELIMIT = tmp32;
  326. break;
  327. case JS_GET_TIMELIMIT:
  328. tmp32 = joydev->glue.JS_TIMELIMIT;
  329. err = put_user(tmp32, (s32 __user *) arg);
  330. break;
  331. case JS_SET_ALL:
  332. err = copy_from_user(&ds32, argp,
  333. sizeof(ds32)) ? -EFAULT : 0;
  334. if (err == 0) {
  335. joydev->glue.JS_TIMEOUT = ds32.JS_TIMEOUT;
  336. joydev->glue.BUSY = ds32.BUSY;
  337. joydev->glue.JS_EXPIRETIME = ds32.JS_EXPIRETIME;
  338. joydev->glue.JS_TIMELIMIT = ds32.JS_TIMELIMIT;
  339. joydev->glue.JS_SAVE = ds32.JS_SAVE;
  340. joydev->glue.JS_CORR = ds32.JS_CORR;
  341. }
  342. break;
  343. case JS_GET_ALL:
  344. ds32.JS_TIMEOUT = joydev->glue.JS_TIMEOUT;
  345. ds32.BUSY = joydev->glue.BUSY;
  346. ds32.JS_EXPIRETIME = joydev->glue.JS_EXPIRETIME;
  347. ds32.JS_TIMELIMIT = joydev->glue.JS_TIMELIMIT;
  348. ds32.JS_SAVE = joydev->glue.JS_SAVE;
  349. ds32.JS_CORR = joydev->glue.JS_CORR;
  350. err = copy_to_user(argp, &ds32, sizeof(ds32)) ? -EFAULT : 0;
  351. break;
  352. default:
  353. err = joydev_ioctl_common(joydev, cmd, argp);
  354. }
  355. return err;
  356. }
  357. #endif /* CONFIG_COMPAT */
  358. static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  359. {
  360. struct joydev_client *client = file->private_data;
  361. struct joydev *joydev = client->joydev;
  362. void __user *argp = (void __user *)arg;
  363. if (!joydev->exist)
  364. return -ENODEV;
  365. switch(cmd) {
  366. case JS_SET_TIMELIMIT:
  367. return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
  368. case JS_GET_TIMELIMIT:
  369. return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
  370. case JS_SET_ALL:
  371. return copy_from_user(&joydev->glue, argp,
  372. sizeof(joydev->glue)) ? -EFAULT : 0;
  373. case JS_GET_ALL:
  374. return copy_to_user(argp, &joydev->glue,
  375. sizeof(joydev->glue)) ? -EFAULT : 0;
  376. default:
  377. return joydev_ioctl_common(joydev, cmd, argp);
  378. }
  379. }
  380. static const struct file_operations joydev_fops = {
  381. .owner = THIS_MODULE,
  382. .read = joydev_read,
  383. .write = joydev_write,
  384. .poll = joydev_poll,
  385. .open = joydev_open,
  386. .release = joydev_release,
  387. .ioctl = joydev_ioctl,
  388. #ifdef CONFIG_COMPAT
  389. .compat_ioctl = joydev_compat_ioctl,
  390. #endif
  391. .fasync = joydev_fasync,
  392. };
  393. static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
  394. const struct input_device_id *id)
  395. {
  396. struct joydev *joydev;
  397. struct class_device *cdev;
  398. dev_t devt;
  399. int i, j, t, minor;
  400. int error;
  401. for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++);
  402. if (minor == JOYDEV_MINORS) {
  403. printk(KERN_ERR "joydev: no more free joydev devices\n");
  404. return -ENFILE;
  405. }
  406. joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL);
  407. if (!joydev)
  408. return -ENOMEM;
  409. INIT_LIST_HEAD(&joydev->client_list);
  410. init_waitqueue_head(&joydev->wait);
  411. joydev->minor = minor;
  412. joydev->exist = 1;
  413. joydev->handle.dev = dev;
  414. joydev->handle.name = joydev->name;
  415. joydev->handle.handler = handler;
  416. joydev->handle.private = joydev;
  417. sprintf(joydev->name, "js%d", minor);
  418. for (i = 0; i < ABS_MAX + 1; i++)
  419. if (test_bit(i, dev->absbit)) {
  420. joydev->absmap[i] = joydev->nabs;
  421. joydev->abspam[joydev->nabs] = i;
  422. joydev->nabs++;
  423. }
  424. for (i = BTN_JOYSTICK - BTN_MISC; i < KEY_MAX - BTN_MISC + 1; i++)
  425. if (test_bit(i + BTN_MISC, dev->keybit)) {
  426. joydev->keymap[i] = joydev->nkey;
  427. joydev->keypam[joydev->nkey] = i + BTN_MISC;
  428. joydev->nkey++;
  429. }
  430. for (i = 0; i < BTN_JOYSTICK - BTN_MISC; i++)
  431. if (test_bit(i + BTN_MISC, dev->keybit)) {
  432. joydev->keymap[i] = joydev->nkey;
  433. joydev->keypam[joydev->nkey] = i + BTN_MISC;
  434. joydev->nkey++;
  435. }
  436. for (i = 0; i < joydev->nabs; i++) {
  437. j = joydev->abspam[i];
  438. if (dev->absmax[j] == dev->absmin[j]) {
  439. joydev->corr[i].type = JS_CORR_NONE;
  440. joydev->abs[i] = dev->abs[j];
  441. continue;
  442. }
  443. joydev->corr[i].type = JS_CORR_BROKEN;
  444. joydev->corr[i].prec = dev->absfuzz[j];
  445. joydev->corr[i].coef[0] = (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
  446. joydev->corr[i].coef[1] = (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
  447. if (!(t = ((dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j])))
  448. continue;
  449. joydev->corr[i].coef[2] = (1 << 29) / t;
  450. joydev->corr[i].coef[3] = (1 << 29) / t;
  451. joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i);
  452. }
  453. joydev_table[minor] = joydev;
  454. devt = MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
  455. cdev = class_device_create(&input_class, &dev->cdev, devt,
  456. dev->cdev.dev, joydev->name);
  457. if (IS_ERR(cdev)) {
  458. error = PTR_ERR(cdev);
  459. goto err_free_joydev;
  460. }
  461. /* temporary symlink to keep userspace happy */
  462. error = sysfs_create_link(&input_class.subsys.kset.kobj,
  463. &cdev->kobj, joydev->name);
  464. if (error)
  465. goto err_cdev_destroy;
  466. error = input_register_handle(&joydev->handle);
  467. if (error)
  468. goto err_remove_link;
  469. return 0;
  470. err_remove_link:
  471. sysfs_remove_link(&input_class.subsys.kset.kobj, joydev->name);
  472. err_cdev_destroy:
  473. class_device_destroy(&input_class, devt);
  474. err_free_joydev:
  475. joydev_table[minor] = NULL;
  476. kfree(joydev);
  477. return error;
  478. }
  479. static void joydev_disconnect(struct input_handle *handle)
  480. {
  481. struct joydev *joydev = handle->private;
  482. struct joydev_client *client;
  483. input_unregister_handle(handle);
  484. sysfs_remove_link(&input_class.subsys.kset.kobj, joydev->name);
  485. class_device_destroy(&input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
  486. joydev->exist = 0;
  487. if (joydev->open) {
  488. input_close_device(handle);
  489. wake_up_interruptible(&joydev->wait);
  490. list_for_each_entry(client, &joydev->client_list, node)
  491. kill_fasync(&client->fasync, SIGIO, POLL_HUP);
  492. } else
  493. joydev_free(joydev);
  494. }
  495. static const struct input_device_id joydev_blacklist[] = {
  496. {
  497. .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
  498. .evbit = { BIT(EV_KEY) },
  499. .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
  500. }, /* Avoid itouchpads, touchscreens and tablets */
  501. { } /* Terminating entry */
  502. };
  503. static const struct input_device_id joydev_ids[] = {
  504. {
  505. .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
  506. .evbit = { BIT(EV_ABS) },
  507. .absbit = { BIT(ABS_X) },
  508. },
  509. {
  510. .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
  511. .evbit = { BIT(EV_ABS) },
  512. .absbit = { BIT(ABS_WHEEL) },
  513. },
  514. {
  515. .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
  516. .evbit = { BIT(EV_ABS) },
  517. .absbit = { BIT(ABS_THROTTLE) },
  518. },
  519. { } /* Terminating entry */
  520. };
  521. MODULE_DEVICE_TABLE(input, joydev_ids);
  522. static struct input_handler joydev_handler = {
  523. .event = joydev_event,
  524. .connect = joydev_connect,
  525. .disconnect = joydev_disconnect,
  526. .fops = &joydev_fops,
  527. .minor = JOYDEV_MINOR_BASE,
  528. .name = "joydev",
  529. .id_table = joydev_ids,
  530. .blacklist = joydev_blacklist,
  531. };
  532. static int __init joydev_init(void)
  533. {
  534. return input_register_handler(&joydev_handler);
  535. }
  536. static void __exit joydev_exit(void)
  537. {
  538. input_unregister_handler(&joydev_handler);
  539. }
  540. module_init(joydev_init);
  541. module_exit(joydev_exit);