touchkit_ps2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* ----------------------------------------------------------------------------
  2. * touchkit_ps2.c -- Driver for eGalax TouchKit PS/2 Touchscreens
  3. *
  4. * Copyright (C) 2005 by Stefan Lucke
  5. * Copyright (C) 2004 by Daniel Ritz
  6. * Copyright (C) by Todd E. Johnson (mtouchusb.c)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * Based upon touchkitusb.c
  23. *
  24. * Vendor documentation is available at:
  25. * http://home.eeti.com.tw/web20/drivers/Software%20Programming%20Guide_v2.0.pdf
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/input.h>
  29. #include <linux/serio.h>
  30. #include <linux/libps2.h>
  31. #include "psmouse.h"
  32. #include "touchkit_ps2.h"
  33. #define TOUCHKIT_MAX_XC 0x07ff
  34. #define TOUCHKIT_MAX_YC 0x07ff
  35. #define TOUCHKIT_CMD 0x0a
  36. #define TOUCHKIT_CMD_LENGTH 1
  37. #define TOUCHKIT_CMD_ACTIVE 'A'
  38. #define TOUCHKIT_CMD_FIRMWARE_VERSION 'D'
  39. #define TOUCHKIT_CMD_CONTROLLER_TYPE 'E'
  40. #define TOUCHKIT_SEND_PARMS(s, r, c) ((s) << 12 | (r) << 8 | (c))
  41. #define TOUCHKIT_GET_TOUCHED(packet) (((packet)[0]) & 0x01)
  42. #define TOUCHKIT_GET_X(packet) (((packet)[1] << 7) | (packet)[2])
  43. #define TOUCHKIT_GET_Y(packet) (((packet)[3] << 7) | (packet)[4])
  44. static psmouse_ret_t touchkit_ps2_process_byte(struct psmouse *psmouse)
  45. {
  46. unsigned char *packet = psmouse->packet;
  47. struct input_dev *dev = psmouse->dev;
  48. if (psmouse->pktcnt != 5)
  49. return PSMOUSE_GOOD_DATA;
  50. input_report_abs(dev, ABS_X, TOUCHKIT_GET_X(packet));
  51. input_report_abs(dev, ABS_Y, TOUCHKIT_GET_Y(packet));
  52. input_report_key(dev, BTN_TOUCH, TOUCHKIT_GET_TOUCHED(packet));
  53. input_sync(dev);
  54. return PSMOUSE_FULL_PACKET;
  55. }
  56. int touchkit_ps2_detect(struct psmouse *psmouse, bool set_properties)
  57. {
  58. struct input_dev *dev = psmouse->dev;
  59. unsigned char param[3];
  60. int command;
  61. param[0] = TOUCHKIT_CMD_LENGTH;
  62. param[1] = TOUCHKIT_CMD_ACTIVE;
  63. command = TOUCHKIT_SEND_PARMS(2, 3, TOUCHKIT_CMD);
  64. if (ps2_command(&psmouse->ps2dev, param, command))
  65. return -ENODEV;
  66. if (param[0] != TOUCHKIT_CMD || param[1] != 0x01 ||
  67. param[2] != TOUCHKIT_CMD_ACTIVE)
  68. return -ENODEV;
  69. if (set_properties) {
  70. dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  71. dev->keybit[BIT_WORD(BTN_MOUSE)] = 0;
  72. dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  73. input_set_abs_params(dev, ABS_X, 0, TOUCHKIT_MAX_XC, 0, 0);
  74. input_set_abs_params(dev, ABS_Y, 0, TOUCHKIT_MAX_YC, 0, 0);
  75. psmouse->vendor = "eGalax";
  76. psmouse->name = "Touchscreen";
  77. psmouse->protocol_handler = touchkit_ps2_process_byte;
  78. psmouse->pktsize = 5;
  79. }
  80. return 0;
  81. }