joydev.c 17 KB

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