lifebook.c 8.2 KB

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