lifebook.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Fujitsu B-series Lifebook PS/2 TouchScreen driver
  3. *
  4. * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
  5. * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
  6. *
  7. * TouchScreen detection, absolute mode setting and packet layout is taken from
  8. * Harald Hoyer's description of the device.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. */
  14. #include <linux/input.h>
  15. #include <linux/serio.h>
  16. #include <linux/libps2.h>
  17. #include <linux/dmi.h>
  18. #include "psmouse.h"
  19. #include "lifebook.h"
  20. static const char *desired_serio_phys;
  21. static int lifebook_set_serio_phys(struct dmi_system_id *d)
  22. {
  23. desired_serio_phys = d->driver_data;
  24. return 0;
  25. }
  26. static unsigned char lifebook_use_6byte_proto;
  27. static int lifebook_set_6byte_proto(struct dmi_system_id *d)
  28. {
  29. lifebook_use_6byte_proto = 1;
  30. return 0;
  31. }
  32. static struct dmi_system_id lifebook_dmi_table[] = {
  33. {
  34. .ident = "FLORA-ie 55mi",
  35. .matches = {
  36. DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
  37. },
  38. },
  39. {
  40. .ident = "LifeBook B",
  41. .matches = {
  42. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
  43. },
  44. },
  45. {
  46. .ident = "Lifebook B",
  47. .matches = {
  48. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
  49. },
  50. },
  51. {
  52. .ident = "Lifebook B213x/B2150",
  53. .matches = {
  54. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
  55. },
  56. },
  57. {
  58. .ident = "Zephyr",
  59. .matches = {
  60. DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
  61. },
  62. },
  63. {
  64. .ident = "CF-18",
  65. .matches = {
  66. DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
  67. },
  68. .callback = lifebook_set_serio_phys,
  69. .driver_data = "isa0060/serio3",
  70. },
  71. {
  72. .ident = "Panasonic CF-28",
  73. .matches = {
  74. DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
  75. DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
  76. },
  77. .callback = lifebook_set_6byte_proto,
  78. },
  79. {
  80. .ident = "Lifebook B142",
  81. .matches = {
  82. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
  83. },
  84. },
  85. { }
  86. };
  87. static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
  88. {
  89. struct input_dev *dev = psmouse->dev;
  90. unsigned char *packet = psmouse->packet;
  91. int relative_packet = packet[0] & 0x08;
  92. if (relative_packet || !lifebook_use_6byte_proto) {
  93. if (psmouse->pktcnt != 3)
  94. return PSMOUSE_GOOD_DATA;
  95. } else {
  96. switch (psmouse->pktcnt) {
  97. case 1:
  98. return (packet[0] & 0xf8) == 0x00 ?
  99. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  100. case 2:
  101. return PSMOUSE_GOOD_DATA;
  102. case 3:
  103. return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
  104. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  105. case 4:
  106. return (packet[3] & 0xf8) == 0xc0 ?
  107. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  108. case 5:
  109. return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
  110. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  111. case 6:
  112. if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
  113. return PSMOUSE_BAD_DATA;
  114. if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
  115. return PSMOUSE_BAD_DATA;
  116. break; /* report data */
  117. }
  118. }
  119. if (relative_packet) {
  120. input_report_rel(dev, REL_X,
  121. ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
  122. input_report_rel(dev, REL_Y,
  123. -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
  124. } else if (lifebook_use_6byte_proto) {
  125. input_report_abs(dev, ABS_X,
  126. ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
  127. input_report_abs(dev, ABS_Y,
  128. 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
  129. } else {
  130. input_report_abs(dev, ABS_X,
  131. (packet[1] | ((packet[0] & 0x30) << 4)));
  132. input_report_abs(dev, ABS_Y,
  133. 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
  134. }
  135. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  136. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  137. input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
  138. input_sync(dev);
  139. return PSMOUSE_FULL_PACKET;
  140. }
  141. static int lifebook_absolute_mode(struct psmouse *psmouse)
  142. {
  143. struct ps2dev *ps2dev = &psmouse->ps2dev;
  144. unsigned char param;
  145. if (psmouse_reset(psmouse))
  146. return -1;
  147. /*
  148. Enable absolute output -- ps2_command fails always but if
  149. you leave this call out the touchsreen will never send
  150. absolute coordinates
  151. */
  152. param = lifebook_use_6byte_proto ? 0x08 : 0x07;
  153. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  154. return 0;
  155. }
  156. static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
  157. {
  158. static const unsigned char params[] = { 0, 1, 2, 2, 3 };
  159. unsigned char p;
  160. if (resolution == 0 || resolution > 400)
  161. resolution = 400;
  162. p = params[resolution / 100];
  163. ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
  164. psmouse->resolution = 50 << p;
  165. }
  166. static void lifebook_disconnect(struct psmouse *psmouse)
  167. {
  168. psmouse_reset(psmouse);
  169. }
  170. int lifebook_detect(struct psmouse *psmouse, int set_properties)
  171. {
  172. if (!dmi_check_system(lifebook_dmi_table))
  173. return -1;
  174. if (desired_serio_phys &&
  175. strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
  176. return -1;
  177. if (set_properties) {
  178. psmouse->vendor = "Fujitsu";
  179. psmouse->name = "Lifebook TouchScreen";
  180. }
  181. return 0;
  182. }
  183. int lifebook_init(struct psmouse *psmouse)
  184. {
  185. struct input_dev *input_dev = psmouse->dev;
  186. int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
  187. if (lifebook_absolute_mode(psmouse))
  188. return -1;
  189. input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
  190. input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  191. input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  192. input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  193. input_set_abs_params(input_dev, ABS_X, 0, max_coord, 0, 0);
  194. input_set_abs_params(input_dev, ABS_Y, 0, max_coord, 0, 0);
  195. psmouse->protocol_handler = lifebook_process_byte;
  196. psmouse->set_resolution = lifebook_set_resolution;
  197. psmouse->disconnect = lifebook_disconnect;
  198. psmouse->reconnect = lifebook_absolute_mode;
  199. /*
  200. * Use packet size = 3 even when using 6-byte protocol because
  201. * that's what POLL will return on Lifebooks (according to spec).
  202. */
  203. psmouse->pktsize = 3;
  204. return 0;
  205. }