lifebook.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 = "Panasonic CF-29",
  81. .matches = {
  82. DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
  83. DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
  84. },
  85. .callback = lifebook_set_6byte_proto,
  86. },
  87. {
  88. .ident = "Lifebook B142",
  89. .matches = {
  90. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
  91. },
  92. },
  93. { }
  94. };
  95. static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
  96. {
  97. struct input_dev *dev = psmouse->dev;
  98. unsigned char *packet = psmouse->packet;
  99. int relative_packet = packet[0] & 0x08;
  100. if (relative_packet || !lifebook_use_6byte_proto) {
  101. if (psmouse->pktcnt != 3)
  102. return PSMOUSE_GOOD_DATA;
  103. } else {
  104. switch (psmouse->pktcnt) {
  105. case 1:
  106. return (packet[0] & 0xf8) == 0x00 ?
  107. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  108. case 2:
  109. return PSMOUSE_GOOD_DATA;
  110. case 3:
  111. return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
  112. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  113. case 4:
  114. return (packet[3] & 0xf8) == 0xc0 ?
  115. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  116. case 5:
  117. return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
  118. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  119. case 6:
  120. if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
  121. return PSMOUSE_BAD_DATA;
  122. if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
  123. return PSMOUSE_BAD_DATA;
  124. break; /* report data */
  125. }
  126. }
  127. if (relative_packet) {
  128. input_report_rel(dev, REL_X,
  129. ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
  130. input_report_rel(dev, REL_Y,
  131. -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
  132. } else if (lifebook_use_6byte_proto) {
  133. input_report_abs(dev, ABS_X,
  134. ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
  135. input_report_abs(dev, ABS_Y,
  136. 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
  137. } else {
  138. input_report_abs(dev, ABS_X,
  139. (packet[1] | ((packet[0] & 0x30) << 4)));
  140. input_report_abs(dev, ABS_Y,
  141. 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
  142. }
  143. input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
  144. input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
  145. input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
  146. input_sync(dev);
  147. return PSMOUSE_FULL_PACKET;
  148. }
  149. static int lifebook_absolute_mode(struct psmouse *psmouse)
  150. {
  151. struct ps2dev *ps2dev = &psmouse->ps2dev;
  152. unsigned char param;
  153. if (psmouse_reset(psmouse))
  154. return -1;
  155. /*
  156. Enable absolute output -- ps2_command fails always but if
  157. you leave this call out the touchsreen will never send
  158. absolute coordinates
  159. */
  160. param = lifebook_use_6byte_proto ? 0x08 : 0x07;
  161. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  162. return 0;
  163. }
  164. static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
  165. {
  166. static const unsigned char params[] = { 0, 1, 2, 2, 3 };
  167. unsigned char p;
  168. if (resolution == 0 || resolution > 400)
  169. resolution = 400;
  170. p = params[resolution / 100];
  171. ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
  172. psmouse->resolution = 50 << p;
  173. }
  174. static void lifebook_disconnect(struct psmouse *psmouse)
  175. {
  176. psmouse_reset(psmouse);
  177. }
  178. int lifebook_detect(struct psmouse *psmouse, int set_properties)
  179. {
  180. if (!dmi_check_system(lifebook_dmi_table))
  181. return -1;
  182. if (desired_serio_phys &&
  183. strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
  184. return -1;
  185. if (set_properties) {
  186. psmouse->vendor = "Fujitsu";
  187. psmouse->name = "Lifebook TouchScreen";
  188. }
  189. return 0;
  190. }
  191. int lifebook_init(struct psmouse *psmouse)
  192. {
  193. struct input_dev *input_dev = psmouse->dev;
  194. int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
  195. if (lifebook_absolute_mode(psmouse))
  196. return -1;
  197. input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
  198. input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  199. input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  200. input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  201. input_set_abs_params(input_dev, ABS_X, 0, max_coord, 0, 0);
  202. input_set_abs_params(input_dev, ABS_Y, 0, max_coord, 0, 0);
  203. psmouse->protocol_handler = lifebook_process_byte;
  204. psmouse->set_resolution = lifebook_set_resolution;
  205. psmouse->disconnect = lifebook_disconnect;
  206. psmouse->reconnect = lifebook_absolute_mode;
  207. /*
  208. * Use packet size = 3 even when using 6-byte protocol because
  209. * that's what POLL will return on Lifebooks (according to spec).
  210. */
  211. psmouse->pktsize = 3;
  212. return 0;
  213. }