lifebook.c 8.2 KB

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