lifebook.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. struct lifebook_data {
  21. struct input_dev *dev2; /* Relative device */
  22. char phys[32];
  23. };
  24. static const char *desired_serio_phys;
  25. static int lifebook_set_serio_phys(const struct dmi_system_id *d)
  26. {
  27. desired_serio_phys = d->driver_data;
  28. return 0;
  29. }
  30. static unsigned char lifebook_use_6byte_proto;
  31. static int lifebook_set_6byte_proto(const struct dmi_system_id *d)
  32. {
  33. lifebook_use_6byte_proto = 1;
  34. return 0;
  35. }
  36. static const struct dmi_system_id lifebook_dmi_table[] = {
  37. {
  38. .ident = "FLORA-ie 55mi",
  39. .matches = {
  40. DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
  41. },
  42. },
  43. {
  44. .ident = "LifeBook B",
  45. .matches = {
  46. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
  47. },
  48. },
  49. {
  50. .ident = "Lifebook B",
  51. .matches = {
  52. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
  53. },
  54. },
  55. {
  56. .ident = "Lifebook B213x/B2150",
  57. .matches = {
  58. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
  59. },
  60. },
  61. {
  62. .ident = "Zephyr",
  63. .matches = {
  64. DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
  65. },
  66. },
  67. {
  68. .ident = "CF-18",
  69. .matches = {
  70. DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
  71. },
  72. .callback = lifebook_set_serio_phys,
  73. .driver_data = "isa0060/serio3",
  74. },
  75. {
  76. .ident = "Panasonic CF-28",
  77. .matches = {
  78. DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
  79. DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
  80. },
  81. .callback = lifebook_set_6byte_proto,
  82. },
  83. {
  84. .ident = "Panasonic CF-29",
  85. .matches = {
  86. DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
  87. DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
  88. },
  89. .callback = lifebook_set_6byte_proto,
  90. },
  91. {
  92. .ident = "CF-72",
  93. .matches = {
  94. DMI_MATCH(DMI_PRODUCT_NAME, "CF-72"),
  95. },
  96. .callback = lifebook_set_serio_phys,
  97. .driver_data = "isa0060/serio3",
  98. },
  99. {
  100. .ident = "Lifebook B142",
  101. .matches = {
  102. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
  103. },
  104. },
  105. { }
  106. };
  107. static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
  108. {
  109. struct lifebook_data *priv = psmouse->private;
  110. struct input_dev *dev1 = psmouse->dev;
  111. struct input_dev *dev2 = priv ? priv->dev2 : NULL;
  112. unsigned char *packet = psmouse->packet;
  113. int relative_packet = packet[0] & 0x08;
  114. if (relative_packet || !lifebook_use_6byte_proto) {
  115. if (psmouse->pktcnt != 3)
  116. return PSMOUSE_GOOD_DATA;
  117. } else {
  118. switch (psmouse->pktcnt) {
  119. case 1:
  120. return (packet[0] & 0xf8) == 0x00 ?
  121. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  122. case 2:
  123. return PSMOUSE_GOOD_DATA;
  124. case 3:
  125. return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
  126. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  127. case 4:
  128. return (packet[3] & 0xf8) == 0xc0 ?
  129. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  130. case 5:
  131. return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
  132. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  133. case 6:
  134. if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
  135. return PSMOUSE_BAD_DATA;
  136. if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
  137. return PSMOUSE_BAD_DATA;
  138. break; /* report data */
  139. }
  140. }
  141. if (relative_packet) {
  142. if (!dev2)
  143. printk(KERN_WARNING "lifebook.c: got relative packet "
  144. "but no relative device set up\n");
  145. } else if (lifebook_use_6byte_proto) {
  146. input_report_abs(dev1, ABS_X,
  147. ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
  148. input_report_abs(dev1, ABS_Y,
  149. 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
  150. } else {
  151. input_report_abs(dev1, ABS_X,
  152. (packet[1] | ((packet[0] & 0x30) << 4)));
  153. input_report_abs(dev1, ABS_Y,
  154. 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
  155. }
  156. input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
  157. input_sync(dev1);
  158. if (dev2) {
  159. if (relative_packet) {
  160. input_report_rel(dev2, REL_X,
  161. ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
  162. input_report_rel(dev2, REL_Y,
  163. -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
  164. }
  165. input_report_key(dev2, BTN_LEFT, packet[0] & 0x01);
  166. input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02);
  167. input_sync(dev2);
  168. }
  169. return PSMOUSE_FULL_PACKET;
  170. }
  171. static int lifebook_absolute_mode(struct psmouse *psmouse)
  172. {
  173. struct ps2dev *ps2dev = &psmouse->ps2dev;
  174. unsigned char param;
  175. if (psmouse_reset(psmouse))
  176. return -1;
  177. /*
  178. Enable absolute output -- ps2_command fails always but if
  179. you leave this call out the touchsreen will never send
  180. absolute coordinates
  181. */
  182. param = lifebook_use_6byte_proto ? 0x08 : 0x07;
  183. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  184. return 0;
  185. }
  186. static void lifebook_relative_mode(struct psmouse *psmouse)
  187. {
  188. struct ps2dev *ps2dev = &psmouse->ps2dev;
  189. unsigned char param = 0x06;
  190. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  191. }
  192. static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
  193. {
  194. static const unsigned char params[] = { 0, 1, 2, 2, 3 };
  195. unsigned char p;
  196. if (resolution == 0 || resolution > 400)
  197. resolution = 400;
  198. p = params[resolution / 100];
  199. ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
  200. psmouse->resolution = 50 << p;
  201. }
  202. static void lifebook_disconnect(struct psmouse *psmouse)
  203. {
  204. struct lifebook_data *priv = psmouse->private;
  205. psmouse_reset(psmouse);
  206. if (priv) {
  207. input_unregister_device(priv->dev2);
  208. kfree(priv);
  209. }
  210. psmouse->private = NULL;
  211. }
  212. int lifebook_detect(struct psmouse *psmouse, int set_properties)
  213. {
  214. if (!dmi_check_system(lifebook_dmi_table))
  215. return -1;
  216. if (desired_serio_phys &&
  217. strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
  218. return -1;
  219. if (set_properties) {
  220. psmouse->vendor = "Fujitsu";
  221. psmouse->name = "Lifebook TouchScreen";
  222. }
  223. return 0;
  224. }
  225. static int lifebook_create_relative_device(struct psmouse *psmouse)
  226. {
  227. struct input_dev *dev2;
  228. struct lifebook_data *priv;
  229. int error = -ENOMEM;
  230. priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
  231. dev2 = input_allocate_device();
  232. if (!priv || !dev2)
  233. goto err_out;
  234. priv->dev2 = dev2;
  235. snprintf(priv->phys, sizeof(priv->phys),
  236. "%s/input1", psmouse->ps2dev.serio->phys);
  237. dev2->phys = priv->phys;
  238. dev2->name = "PS/2 Touchpad";
  239. dev2->id.bustype = BUS_I8042;
  240. dev2->id.vendor = 0x0002;
  241. dev2->id.product = PSMOUSE_LIFEBOOK;
  242. dev2->id.version = 0x0000;
  243. dev2->dev.parent = &psmouse->ps2dev.serio->dev;
  244. dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
  245. dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  246. dev2->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  247. BIT_MASK(BTN_RIGHT);
  248. error = input_register_device(priv->dev2);
  249. if (error)
  250. goto err_out;
  251. psmouse->private = priv;
  252. return 0;
  253. err_out:
  254. input_free_device(dev2);
  255. kfree(priv);
  256. return error;
  257. }
  258. int lifebook_init(struct psmouse *psmouse)
  259. {
  260. struct input_dev *dev1 = psmouse->dev;
  261. int max_coord = lifebook_use_6byte_proto ? 4096 : 1024;
  262. if (lifebook_absolute_mode(psmouse))
  263. return -1;
  264. dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
  265. dev1->relbit[0] = 0;
  266. dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  267. input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
  268. input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);
  269. if (!desired_serio_phys) {
  270. if (lifebook_create_relative_device(psmouse)) {
  271. lifebook_relative_mode(psmouse);
  272. return -1;
  273. }
  274. }
  275. psmouse->protocol_handler = lifebook_process_byte;
  276. psmouse->set_resolution = lifebook_set_resolution;
  277. psmouse->disconnect = lifebook_disconnect;
  278. psmouse->reconnect = lifebook_absolute_mode;
  279. psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
  280. /*
  281. * Use packet size = 3 even when using 6-byte protocol because
  282. * that's what POLL will return on Lifebooks (according to spec).
  283. */
  284. psmouse->pktsize = 3;
  285. return 0;
  286. }