lifebook.c 8.1 KB

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