lifebook.c 8.0 KB

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