lifebook.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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(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(struct dmi_system_id *d)
  32. {
  33. lifebook_use_6byte_proto = 1;
  34. return 0;
  35. }
  36. static 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 = "Lifebook B142",
  93. .matches = {
  94. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
  95. },
  96. },
  97. { }
  98. };
  99. static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
  100. {
  101. struct lifebook_data *priv = psmouse->private;
  102. struct input_dev *dev1 = psmouse->dev;
  103. struct input_dev *dev2 = priv->dev2;
  104. unsigned char *packet = psmouse->packet;
  105. int relative_packet = packet[0] & 0x08;
  106. if (relative_packet || !lifebook_use_6byte_proto) {
  107. if (psmouse->pktcnt != 3)
  108. return PSMOUSE_GOOD_DATA;
  109. } else {
  110. switch (psmouse->pktcnt) {
  111. case 1:
  112. return (packet[0] & 0xf8) == 0x00 ?
  113. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  114. case 2:
  115. return PSMOUSE_GOOD_DATA;
  116. case 3:
  117. return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
  118. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  119. case 4:
  120. return (packet[3] & 0xf8) == 0xc0 ?
  121. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  122. case 5:
  123. return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
  124. PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
  125. case 6:
  126. if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
  127. return PSMOUSE_BAD_DATA;
  128. if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
  129. return PSMOUSE_BAD_DATA;
  130. break; /* report data */
  131. }
  132. }
  133. if (relative_packet) {
  134. if (!dev2)
  135. printk(KERN_WARNING "lifebook.c: got relative packet "
  136. "but no relative device set up\n");
  137. } else if (lifebook_use_6byte_proto) {
  138. input_report_abs(dev1, ABS_X,
  139. ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
  140. input_report_abs(dev1, ABS_Y,
  141. 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
  142. } else {
  143. input_report_abs(dev1, ABS_X,
  144. (packet[1] | ((packet[0] & 0x30) << 4)));
  145. input_report_abs(dev1, ABS_Y,
  146. 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
  147. }
  148. input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
  149. input_sync(dev1);
  150. if (dev2) {
  151. if (relative_packet) {
  152. input_report_rel(dev2, REL_X,
  153. ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
  154. input_report_rel(dev2, REL_Y,
  155. -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
  156. }
  157. input_report_key(dev2, BTN_LEFT, packet[0] & 0x01);
  158. input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02);
  159. input_sync(dev2);
  160. }
  161. return PSMOUSE_FULL_PACKET;
  162. }
  163. static int lifebook_absolute_mode(struct psmouse *psmouse)
  164. {
  165. struct ps2dev *ps2dev = &psmouse->ps2dev;
  166. unsigned char param;
  167. if (psmouse_reset(psmouse))
  168. return -1;
  169. /*
  170. Enable absolute output -- ps2_command fails always but if
  171. you leave this call out the touchsreen will never send
  172. absolute coordinates
  173. */
  174. param = lifebook_use_6byte_proto ? 0x08 : 0x07;
  175. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  176. return 0;
  177. }
  178. static void lifebook_relative_mode(struct psmouse *psmouse)
  179. {
  180. struct ps2dev *ps2dev = &psmouse->ps2dev;
  181. unsigned char param = 0x06;
  182. ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
  183. }
  184. static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
  185. {
  186. static const unsigned char params[] = { 0, 1, 2, 2, 3 };
  187. unsigned char p;
  188. if (resolution == 0 || resolution > 400)
  189. resolution = 400;
  190. p = params[resolution / 100];
  191. ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
  192. psmouse->resolution = 50 << p;
  193. }
  194. static void lifebook_disconnect(struct psmouse *psmouse)
  195. {
  196. psmouse_reset(psmouse);
  197. kfree(psmouse->private);
  198. psmouse->private = NULL;
  199. }
  200. int lifebook_detect(struct psmouse *psmouse, int set_properties)
  201. {
  202. if (!dmi_check_system(lifebook_dmi_table))
  203. return -1;
  204. if (desired_serio_phys &&
  205. strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
  206. return -1;
  207. if (set_properties) {
  208. psmouse->vendor = "Fujitsu";
  209. psmouse->name = "Lifebook TouchScreen";
  210. }
  211. return 0;
  212. }
  213. static int lifebook_create_relative_device(struct psmouse *psmouse)
  214. {
  215. struct input_dev *dev2;
  216. struct lifebook_data *priv;
  217. int error = -ENOMEM;
  218. priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
  219. dev2 = input_allocate_device();
  220. if (!priv || !dev2)
  221. goto err_out;
  222. priv->dev2 = dev2;
  223. snprintf(priv->phys, sizeof(priv->phys),
  224. "%s/input1", psmouse->ps2dev.serio->phys);
  225. dev2->phys = priv->phys;
  226. dev2->name = "PS/2 Touchpad";
  227. dev2->id.bustype = BUS_I8042;
  228. dev2->id.vendor = 0x0002;
  229. dev2->id.product = PSMOUSE_LIFEBOOK;
  230. dev2->id.version = 0x0000;
  231. dev2->dev.parent = &psmouse->ps2dev.serio->dev;
  232. dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  233. dev2->relbit[LONG(REL_X)] = BIT(REL_X) | BIT(REL_Y);
  234. dev2->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
  235. error = input_register_device(priv->dev2);
  236. if (error)
  237. goto err_out;
  238. psmouse->private = priv;
  239. return 0;
  240. err_out:
  241. input_free_device(dev2);
  242. kfree(priv);
  243. return error;
  244. }
  245. int lifebook_init(struct psmouse *psmouse)
  246. {
  247. struct input_dev *dev1 = psmouse->dev;
  248. int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
  249. if (lifebook_absolute_mode(psmouse))
  250. return -1;
  251. dev1->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
  252. dev1->relbit[0] = 0;
  253. dev1->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  254. input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
  255. input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);
  256. if (!desired_serio_phys) {
  257. if (lifebook_create_relative_device(psmouse)) {
  258. lifebook_relative_mode(psmouse);
  259. return -1;
  260. }
  261. }
  262. psmouse->protocol_handler = lifebook_process_byte;
  263. psmouse->set_resolution = lifebook_set_resolution;
  264. psmouse->disconnect = lifebook_disconnect;
  265. psmouse->reconnect = lifebook_absolute_mode;
  266. psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
  267. /*
  268. * Use packet size = 3 even when using 6-byte protocol because
  269. * that's what POLL will return on Lifebooks (according to spec).
  270. */
  271. psmouse->pktsize = 3;
  272. return 0;
  273. }