wacom_w8001.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Wacom W8001 penabled serial touchscreen driver
  3. *
  4. * Copyright (c) 2008 Jaya Kumar
  5. * Copyright (c) 2010 Red Hat, Inc.
  6. * Copyright (c) 2010 - 2011 Ping Cheng, Wacom. <pingc@wacom.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive for
  10. * more details.
  11. *
  12. * Layout based on Elo serial touchscreen driver by Vojtech Pavlik
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/input/mt.h>
  19. #include <linux/serio.h>
  20. #include <linux/ctype.h>
  21. #include <linux/delay.h>
  22. #define DRIVER_DESC "Wacom W8001 serial touchscreen driver"
  23. MODULE_AUTHOR("Jaya Kumar <jayakumar.lkml@gmail.com>");
  24. MODULE_DESCRIPTION(DRIVER_DESC);
  25. MODULE_LICENSE("GPL");
  26. #define W8001_MAX_LENGTH 11
  27. #define W8001_LEAD_MASK 0x80
  28. #define W8001_LEAD_BYTE 0x80
  29. #define W8001_TAB_MASK 0x40
  30. #define W8001_TAB_BYTE 0x40
  31. /* set in first byte of touch data packets */
  32. #define W8001_TOUCH_MASK (0x10 | W8001_LEAD_MASK)
  33. #define W8001_TOUCH_BYTE (0x10 | W8001_LEAD_BYTE)
  34. #define W8001_QUERY_PACKET 0x20
  35. #define W8001_CMD_STOP '0'
  36. #define W8001_CMD_START '1'
  37. #define W8001_CMD_QUERY '*'
  38. #define W8001_CMD_TOUCHQUERY '%'
  39. /* length of data packets in bytes, depends on device. */
  40. #define W8001_PKTLEN_TOUCH93 5
  41. #define W8001_PKTLEN_TOUCH9A 7
  42. #define W8001_PKTLEN_TPCPEN 9
  43. #define W8001_PKTLEN_TPCCTL 11 /* control packet */
  44. #define W8001_PKTLEN_TOUCH2FG 13
  45. /* resolution in points/mm */
  46. #define W8001_PEN_RESOLUTION 100
  47. #define W8001_TOUCH_RESOLUTION 10
  48. struct w8001_coord {
  49. u8 rdy;
  50. u8 tsw;
  51. u8 f1;
  52. u8 f2;
  53. u16 x;
  54. u16 y;
  55. u16 pen_pressure;
  56. u8 tilt_x;
  57. u8 tilt_y;
  58. };
  59. /* touch query reply packet */
  60. struct w8001_touch_query {
  61. u16 x;
  62. u16 y;
  63. u8 panel_res;
  64. u8 capacity_res;
  65. u8 sensor_id;
  66. };
  67. /*
  68. * Per-touchscreen data.
  69. */
  70. struct w8001 {
  71. struct input_dev *pen_dev;
  72. struct input_dev *touch_dev;
  73. struct serio *serio;
  74. struct completion cmd_done;
  75. int id;
  76. int idx;
  77. unsigned char response_type;
  78. unsigned char response[W8001_MAX_LENGTH];
  79. unsigned char data[W8001_MAX_LENGTH];
  80. char phys[32];
  81. int type;
  82. unsigned int pktlen;
  83. u16 max_touch_x;
  84. u16 max_touch_y;
  85. u16 max_pen_x;
  86. u16 max_pen_y;
  87. char pen_name[64];
  88. char touch_name[64];
  89. int open_count;
  90. struct mutex mutex;
  91. };
  92. static void parse_pen_data(u8 *data, struct w8001_coord *coord)
  93. {
  94. memset(coord, 0, sizeof(*coord));
  95. coord->rdy = data[0] & 0x20;
  96. coord->tsw = data[0] & 0x01;
  97. coord->f1 = data[0] & 0x02;
  98. coord->f2 = data[0] & 0x04;
  99. coord->x = (data[1] & 0x7F) << 9;
  100. coord->x |= (data[2] & 0x7F) << 2;
  101. coord->x |= (data[6] & 0x60) >> 5;
  102. coord->y = (data[3] & 0x7F) << 9;
  103. coord->y |= (data[4] & 0x7F) << 2;
  104. coord->y |= (data[6] & 0x18) >> 3;
  105. coord->pen_pressure = data[5] & 0x7F;
  106. coord->pen_pressure |= (data[6] & 0x07) << 7 ;
  107. coord->tilt_x = data[7] & 0x7F;
  108. coord->tilt_y = data[8] & 0x7F;
  109. }
  110. static void parse_single_touch(u8 *data, struct w8001_coord *coord)
  111. {
  112. coord->x = (data[1] << 7) | data[2];
  113. coord->y = (data[3] << 7) | data[4];
  114. coord->tsw = data[0] & 0x01;
  115. }
  116. static void scale_touch_coordinates(struct w8001 *w8001,
  117. unsigned int *x, unsigned int *y)
  118. {
  119. if (w8001->max_pen_x && w8001->max_touch_x)
  120. *x = *x * w8001->max_pen_x / w8001->max_touch_x;
  121. if (w8001->max_pen_y && w8001->max_touch_y)
  122. *y = *y * w8001->max_pen_y / w8001->max_touch_y;
  123. }
  124. static void parse_multi_touch(struct w8001 *w8001)
  125. {
  126. struct input_dev *dev = w8001->touch_dev;
  127. unsigned char *data = w8001->data;
  128. unsigned int x, y;
  129. int i;
  130. int count = 0;
  131. for (i = 0; i < 2; i++) {
  132. bool touch = data[0] & (1 << i);
  133. input_mt_slot(dev, i);
  134. if (touch) {
  135. x = (data[6 * i + 1] << 7) | data[6 * i + 2];
  136. y = (data[6 * i + 3] << 7) | data[6 * i + 4];
  137. /* data[5,6] and [11,12] is finger capacity */
  138. /* scale to pen maximum */
  139. scale_touch_coordinates(w8001, &x, &y);
  140. input_report_abs(dev, ABS_MT_POSITION_X, x);
  141. input_report_abs(dev, ABS_MT_POSITION_Y, y);
  142. count++;
  143. }
  144. }
  145. /* emulate single touch events when stylus is out of proximity.
  146. * This is to make single touch backward support consistent
  147. * across all Wacom single touch devices.
  148. */
  149. if (w8001->type != BTN_TOOL_PEN &&
  150. w8001->type != BTN_TOOL_RUBBER) {
  151. w8001->type = count == 1 ? BTN_TOOL_FINGER : KEY_RESERVED;
  152. input_mt_report_pointer_emulation(dev, true);
  153. }
  154. input_sync(dev);
  155. }
  156. static void parse_touchquery(u8 *data, struct w8001_touch_query *query)
  157. {
  158. memset(query, 0, sizeof(*query));
  159. query->panel_res = data[1];
  160. query->sensor_id = data[2] & 0x7;
  161. query->capacity_res = data[7];
  162. query->x = data[3] << 9;
  163. query->x |= data[4] << 2;
  164. query->x |= (data[2] >> 5) & 0x3;
  165. query->y = data[5] << 9;
  166. query->y |= data[6] << 2;
  167. query->y |= (data[2] >> 3) & 0x3;
  168. /* Early days' single-finger touch models need the following defaults */
  169. if (!query->x && !query->y) {
  170. query->x = 1024;
  171. query->y = 1024;
  172. if (query->panel_res)
  173. query->x = query->y = (1 << query->panel_res);
  174. query->panel_res = W8001_TOUCH_RESOLUTION;
  175. }
  176. }
  177. static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
  178. {
  179. struct input_dev *dev = w8001->pen_dev;
  180. /*
  181. * We have 1 bit for proximity (rdy) and 3 bits for tip, side,
  182. * side2/eraser. If rdy && f2 are set, this can be either pen + side2,
  183. * or eraser. Assume:
  184. * - if dev is already in proximity and f2 is toggled → pen + side2
  185. * - if dev comes into proximity with f2 set → eraser
  186. * If f2 disappears after assuming eraser, fake proximity out for
  187. * eraser and in for pen.
  188. */
  189. switch (w8001->type) {
  190. case BTN_TOOL_RUBBER:
  191. if (!coord->f2) {
  192. input_report_abs(dev, ABS_PRESSURE, 0);
  193. input_report_key(dev, BTN_TOUCH, 0);
  194. input_report_key(dev, BTN_STYLUS, 0);
  195. input_report_key(dev, BTN_STYLUS2, 0);
  196. input_report_key(dev, BTN_TOOL_RUBBER, 0);
  197. input_sync(dev);
  198. w8001->type = BTN_TOOL_PEN;
  199. }
  200. break;
  201. case BTN_TOOL_FINGER:
  202. case KEY_RESERVED:
  203. w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  204. break;
  205. default:
  206. input_report_key(dev, BTN_STYLUS2, coord->f2);
  207. break;
  208. }
  209. input_report_abs(dev, ABS_X, coord->x);
  210. input_report_abs(dev, ABS_Y, coord->y);
  211. input_report_abs(dev, ABS_PRESSURE, coord->pen_pressure);
  212. input_report_key(dev, BTN_TOUCH, coord->tsw);
  213. input_report_key(dev, BTN_STYLUS, coord->f1);
  214. input_report_key(dev, w8001->type, coord->rdy);
  215. input_sync(dev);
  216. if (!coord->rdy)
  217. w8001->type = KEY_RESERVED;
  218. }
  219. static void report_single_touch(struct w8001 *w8001, struct w8001_coord *coord)
  220. {
  221. struct input_dev *dev = w8001->touch_dev;
  222. unsigned int x = coord->x;
  223. unsigned int y = coord->y;
  224. /* scale to pen maximum */
  225. scale_touch_coordinates(w8001, &x, &y);
  226. input_report_abs(dev, ABS_X, x);
  227. input_report_abs(dev, ABS_Y, y);
  228. input_report_key(dev, BTN_TOUCH, coord->tsw);
  229. input_sync(dev);
  230. w8001->type = coord->tsw ? BTN_TOOL_FINGER : KEY_RESERVED;
  231. }
  232. static irqreturn_t w8001_interrupt(struct serio *serio,
  233. unsigned char data, unsigned int flags)
  234. {
  235. struct w8001 *w8001 = serio_get_drvdata(serio);
  236. struct w8001_coord coord;
  237. unsigned char tmp;
  238. w8001->data[w8001->idx] = data;
  239. switch (w8001->idx++) {
  240. case 0:
  241. if ((data & W8001_LEAD_MASK) != W8001_LEAD_BYTE) {
  242. pr_debug("w8001: unsynchronized data: 0x%02x\n", data);
  243. w8001->idx = 0;
  244. }
  245. break;
  246. case W8001_PKTLEN_TOUCH93 - 1:
  247. case W8001_PKTLEN_TOUCH9A - 1:
  248. tmp = w8001->data[0] & W8001_TOUCH_BYTE;
  249. if (tmp != W8001_TOUCH_BYTE)
  250. break;
  251. if (w8001->pktlen == w8001->idx) {
  252. w8001->idx = 0;
  253. if (w8001->type != BTN_TOOL_PEN &&
  254. w8001->type != BTN_TOOL_RUBBER) {
  255. parse_single_touch(w8001->data, &coord);
  256. report_single_touch(w8001, &coord);
  257. }
  258. }
  259. break;
  260. /* Pen coordinates packet */
  261. case W8001_PKTLEN_TPCPEN - 1:
  262. tmp = w8001->data[0] & W8001_TAB_MASK;
  263. if (unlikely(tmp == W8001_TAB_BYTE))
  264. break;
  265. tmp = w8001->data[0] & W8001_TOUCH_BYTE;
  266. if (tmp == W8001_TOUCH_BYTE)
  267. break;
  268. w8001->idx = 0;
  269. parse_pen_data(w8001->data, &coord);
  270. report_pen_events(w8001, &coord);
  271. break;
  272. /* control packet */
  273. case W8001_PKTLEN_TPCCTL - 1:
  274. tmp = w8001->data[0] & W8001_TOUCH_MASK;
  275. if (tmp == W8001_TOUCH_BYTE)
  276. break;
  277. w8001->idx = 0;
  278. memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH);
  279. w8001->response_type = W8001_QUERY_PACKET;
  280. complete(&w8001->cmd_done);
  281. break;
  282. /* 2 finger touch packet */
  283. case W8001_PKTLEN_TOUCH2FG - 1:
  284. w8001->idx = 0;
  285. parse_multi_touch(w8001);
  286. break;
  287. }
  288. return IRQ_HANDLED;
  289. }
  290. static int w8001_command(struct w8001 *w8001, unsigned char command,
  291. bool wait_response)
  292. {
  293. int rc;
  294. w8001->response_type = 0;
  295. init_completion(&w8001->cmd_done);
  296. rc = serio_write(w8001->serio, command);
  297. if (rc == 0 && wait_response) {
  298. wait_for_completion_timeout(&w8001->cmd_done, HZ);
  299. if (w8001->response_type != W8001_QUERY_PACKET)
  300. rc = -EIO;
  301. }
  302. return rc;
  303. }
  304. static int w8001_open(struct input_dev *dev)
  305. {
  306. struct w8001 *w8001 = input_get_drvdata(dev);
  307. int err;
  308. err = mutex_lock_interruptible(&w8001->mutex);
  309. if (err)
  310. return err;
  311. if (w8001->open_count++ == 0) {
  312. err = w8001_command(w8001, W8001_CMD_START, false);
  313. if (err)
  314. w8001->open_count--;
  315. }
  316. mutex_unlock(&w8001->mutex);
  317. return err;
  318. }
  319. static void w8001_close(struct input_dev *dev)
  320. {
  321. struct w8001 *w8001 = input_get_drvdata(dev);
  322. mutex_lock(&w8001->mutex);
  323. if (--w8001->open_count == 0)
  324. w8001_command(w8001, W8001_CMD_STOP, false);
  325. mutex_unlock(&w8001->mutex);
  326. }
  327. static int w8001_detect(struct w8001 *w8001)
  328. {
  329. int error;
  330. error = w8001_command(w8001, W8001_CMD_STOP, false);
  331. if (error)
  332. return error;
  333. msleep(250); /* wait 250ms before querying the device */
  334. return 0;
  335. }
  336. static int w8001_setup_pen(struct w8001 *w8001, char *basename,
  337. size_t basename_sz)
  338. {
  339. struct input_dev *dev = w8001->pen_dev;
  340. struct w8001_coord coord;
  341. int error;
  342. /* penabled? */
  343. error = w8001_command(w8001, W8001_CMD_QUERY, true);
  344. if (error)
  345. return error;
  346. __set_bit(EV_KEY, dev->evbit);
  347. __set_bit(EV_ABS, dev->evbit);
  348. __set_bit(BTN_TOUCH, dev->keybit);
  349. __set_bit(BTN_TOOL_PEN, dev->keybit);
  350. __set_bit(BTN_TOOL_RUBBER, dev->keybit);
  351. __set_bit(BTN_STYLUS, dev->keybit);
  352. __set_bit(BTN_STYLUS2, dev->keybit);
  353. __set_bit(INPUT_PROP_DIRECT, dev->propbit);
  354. parse_pen_data(w8001->response, &coord);
  355. w8001->max_pen_x = coord.x;
  356. w8001->max_pen_y = coord.y;
  357. input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
  358. input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
  359. input_abs_set_res(dev, ABS_X, W8001_PEN_RESOLUTION);
  360. input_abs_set_res(dev, ABS_Y, W8001_PEN_RESOLUTION);
  361. input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
  362. if (coord.tilt_x && coord.tilt_y) {
  363. input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
  364. input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
  365. }
  366. w8001->id = 0x90;
  367. strlcat(basename, " Penabled", basename_sz);
  368. return 0;
  369. }
  370. static int w8001_setup_touch(struct w8001 *w8001, char *basename,
  371. size_t basename_sz)
  372. {
  373. struct input_dev *dev = w8001->touch_dev;
  374. struct w8001_touch_query touch;
  375. int error;
  376. /* Touch enabled? */
  377. error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
  378. if (error)
  379. return error;
  380. /*
  381. * Some non-touch devices may reply to the touch query. But their
  382. * second byte is empty, which indicates touch is not supported.
  383. */
  384. if (!w8001->response[1])
  385. return -ENXIO;
  386. __set_bit(EV_KEY, dev->evbit);
  387. __set_bit(EV_ABS, dev->evbit);
  388. __set_bit(BTN_TOUCH, dev->keybit);
  389. __set_bit(INPUT_PROP_DIRECT, dev->propbit);
  390. parse_touchquery(w8001->response, &touch);
  391. w8001->max_touch_x = touch.x;
  392. w8001->max_touch_y = touch.y;
  393. if (w8001->max_pen_x && w8001->max_pen_y) {
  394. /* if pen is supported scale to pen maximum */
  395. touch.x = w8001->max_pen_x;
  396. touch.y = w8001->max_pen_y;
  397. touch.panel_res = W8001_PEN_RESOLUTION;
  398. }
  399. input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
  400. input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
  401. input_abs_set_res(dev, ABS_X, touch.panel_res);
  402. input_abs_set_res(dev, ABS_Y, touch.panel_res);
  403. switch (touch.sensor_id) {
  404. case 0:
  405. case 2:
  406. w8001->pktlen = W8001_PKTLEN_TOUCH93;
  407. w8001->id = 0x93;
  408. strlcat(basename, " 1FG", basename_sz);
  409. break;
  410. case 1:
  411. case 3:
  412. case 4:
  413. w8001->pktlen = W8001_PKTLEN_TOUCH9A;
  414. strlcat(basename, " 1FG", basename_sz);
  415. w8001->id = 0x9a;
  416. break;
  417. case 5:
  418. w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
  419. __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
  420. input_mt_init_slots(dev, 2, 0);
  421. input_set_abs_params(dev, ABS_MT_POSITION_X,
  422. 0, touch.x, 0, 0);
  423. input_set_abs_params(dev, ABS_MT_POSITION_Y,
  424. 0, touch.y, 0, 0);
  425. strlcat(basename, " 2FG", basename_sz);
  426. if (w8001->max_pen_x && w8001->max_pen_y)
  427. w8001->id = 0xE3;
  428. else
  429. w8001->id = 0xE2;
  430. break;
  431. }
  432. strlcat(basename, " Touchscreen", basename_sz);
  433. return 0;
  434. }
  435. static void w8001_set_devdata(struct input_dev *dev, struct w8001 *w8001,
  436. struct serio *serio)
  437. {
  438. dev->phys = w8001->phys;
  439. dev->id.bustype = BUS_RS232;
  440. dev->id.product = w8001->id;
  441. dev->id.vendor = 0x056a;
  442. dev->id.version = 0x0100;
  443. dev->open = w8001_open;
  444. dev->close = w8001_close;
  445. dev->dev.parent = &serio->dev;
  446. input_set_drvdata(dev, w8001);
  447. }
  448. /*
  449. * w8001_disconnect() is the opposite of w8001_connect()
  450. */
  451. static void w8001_disconnect(struct serio *serio)
  452. {
  453. struct w8001 *w8001 = serio_get_drvdata(serio);
  454. serio_close(serio);
  455. if (w8001->pen_dev)
  456. input_unregister_device(w8001->pen_dev);
  457. if (w8001->touch_dev)
  458. input_unregister_device(w8001->touch_dev);
  459. kfree(w8001);
  460. serio_set_drvdata(serio, NULL);
  461. }
  462. /*
  463. * w8001_connect() is the routine that is called when someone adds a
  464. * new serio device that supports the w8001 protocol and registers it as
  465. * an input device.
  466. */
  467. static int w8001_connect(struct serio *serio, struct serio_driver *drv)
  468. {
  469. struct w8001 *w8001;
  470. struct input_dev *input_dev_pen;
  471. struct input_dev *input_dev_touch;
  472. char basename[64];
  473. int err, err_pen, err_touch;
  474. w8001 = kzalloc(sizeof(struct w8001), GFP_KERNEL);
  475. input_dev_pen = input_allocate_device();
  476. input_dev_touch = input_allocate_device();
  477. if (!w8001 || !input_dev_pen || !input_dev_touch) {
  478. err = -ENOMEM;
  479. goto fail1;
  480. }
  481. w8001->serio = serio;
  482. w8001->pen_dev = input_dev_pen;
  483. w8001->touch_dev = input_dev_touch;
  484. mutex_init(&w8001->mutex);
  485. init_completion(&w8001->cmd_done);
  486. snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys);
  487. serio_set_drvdata(serio, w8001);
  488. err = serio_open(serio, drv);
  489. if (err)
  490. goto fail2;
  491. err = w8001_detect(w8001);
  492. if (err)
  493. goto fail3;
  494. /* For backwards-compatibility we compose the basename based on
  495. * capabilities and then just append the tool type
  496. */
  497. strlcpy(basename, "Wacom Serial", sizeof(basename));
  498. err_pen = w8001_setup_pen(w8001, basename, sizeof(basename));
  499. err_touch = w8001_setup_touch(w8001, basename, sizeof(basename));
  500. if (err_pen && err_touch) {
  501. err = -ENXIO;
  502. goto fail3;
  503. }
  504. if (!err_pen) {
  505. strlcpy(w8001->pen_name, basename, sizeof(w8001->pen_name));
  506. strlcat(w8001->pen_name, " Pen", sizeof(w8001->pen_name));
  507. input_dev_pen->name = w8001->pen_name;
  508. w8001_set_devdata(input_dev_pen, w8001, serio);
  509. err = input_register_device(w8001->pen_dev);
  510. if (err)
  511. goto fail3;
  512. } else {
  513. input_free_device(input_dev_pen);
  514. input_dev_pen = NULL;
  515. w8001->pen_dev = NULL;
  516. }
  517. if (!err_touch) {
  518. strlcpy(w8001->touch_name, basename, sizeof(w8001->touch_name));
  519. strlcat(w8001->touch_name, " Finger",
  520. sizeof(w8001->touch_name));
  521. input_dev_touch->name = w8001->touch_name;
  522. w8001_set_devdata(input_dev_touch, w8001, serio);
  523. err = input_register_device(w8001->touch_dev);
  524. if (err)
  525. goto fail4;
  526. } else {
  527. input_free_device(input_dev_touch);
  528. input_dev_touch = NULL;
  529. w8001->touch_dev = NULL;
  530. }
  531. return 0;
  532. fail4:
  533. if (w8001->pen_dev)
  534. input_unregister_device(w8001->pen_dev);
  535. fail3:
  536. serio_close(serio);
  537. fail2:
  538. serio_set_drvdata(serio, NULL);
  539. fail1:
  540. input_free_device(input_dev_pen);
  541. input_free_device(input_dev_touch);
  542. kfree(w8001);
  543. return err;
  544. }
  545. static struct serio_device_id w8001_serio_ids[] = {
  546. {
  547. .type = SERIO_RS232,
  548. .proto = SERIO_W8001,
  549. .id = SERIO_ANY,
  550. .extra = SERIO_ANY,
  551. },
  552. { 0 }
  553. };
  554. MODULE_DEVICE_TABLE(serio, w8001_serio_ids);
  555. static struct serio_driver w8001_drv = {
  556. .driver = {
  557. .name = "w8001",
  558. },
  559. .description = DRIVER_DESC,
  560. .id_table = w8001_serio_ids,
  561. .interrupt = w8001_interrupt,
  562. .connect = w8001_connect,
  563. .disconnect = w8001_disconnect,
  564. };
  565. module_serio_driver(w8001_drv);