jornada720_ts.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * drivers/input/touchscreen/jornada720_ts.c
  3. *
  4. * Copyright (C) 2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com>
  5. *
  6. * Copyright (C) 2006 Filip Zyzniewski <filip.zyzniewski@tefnet.pl>
  7. * based on HP Jornada 56x touchscreen driver by Alex Lange <chicken@handhelds.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * HP Jornada 710/720/729 Touchscreen Driver
  14. */
  15. #include <linux/platform_device.h>
  16. #include <linux/input.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/io.h>
  21. #include <mach/hardware.h>
  22. #include <mach/jornada720.h>
  23. #include <mach/irqs.h>
  24. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  25. MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver");
  26. MODULE_LICENSE("GPL v2");
  27. struct jornada_ts {
  28. struct input_dev *dev;
  29. int x_data[4]; /* X sample values */
  30. int y_data[4]; /* Y sample values */
  31. };
  32. static void jornada720_ts_collect_data(struct jornada_ts *jornada_ts)
  33. {
  34. /* 3 low word X samples */
  35. jornada_ts->x_data[0] = jornada_ssp_byte(TXDUMMY);
  36. jornada_ts->x_data[1] = jornada_ssp_byte(TXDUMMY);
  37. jornada_ts->x_data[2] = jornada_ssp_byte(TXDUMMY);
  38. /* 3 low word Y samples */
  39. jornada_ts->y_data[0] = jornada_ssp_byte(TXDUMMY);
  40. jornada_ts->y_data[1] = jornada_ssp_byte(TXDUMMY);
  41. jornada_ts->y_data[2] = jornada_ssp_byte(TXDUMMY);
  42. /* combined x samples bits */
  43. jornada_ts->x_data[3] = jornada_ssp_byte(TXDUMMY);
  44. /* combined y samples bits */
  45. jornada_ts->y_data[3] = jornada_ssp_byte(TXDUMMY);
  46. }
  47. static int jornada720_ts_average(int coords[4])
  48. {
  49. int coord, high_bits = coords[3];
  50. coord = coords[0] | ((high_bits & 0x03) << 8);
  51. coord += coords[1] | ((high_bits & 0x0c) << 6);
  52. coord += coords[2] | ((high_bits & 0x30) << 4);
  53. return coord / 3;
  54. }
  55. static irqreturn_t jornada720_ts_interrupt(int irq, void *dev_id)
  56. {
  57. struct platform_device *pdev = dev_id;
  58. struct jornada_ts *jornada_ts = platform_get_drvdata(pdev);
  59. struct input_dev *input = jornada_ts->dev;
  60. int x, y;
  61. /* If GPIO_GPIO9 is set to high then report pen up */
  62. if (GPLR & GPIO_GPIO(9)) {
  63. input_report_key(input, BTN_TOUCH, 0);
  64. input_sync(input);
  65. } else {
  66. jornada_ssp_start();
  67. /* proper reply to request is always TXDUMMY */
  68. if (jornada_ssp_inout(GETTOUCHSAMPLES) == TXDUMMY) {
  69. jornada720_ts_collect_data(jornada_ts);
  70. x = jornada720_ts_average(jornada_ts->x_data);
  71. y = jornada720_ts_average(jornada_ts->y_data);
  72. input_report_key(input, BTN_TOUCH, 1);
  73. input_report_abs(input, ABS_X, x);
  74. input_report_abs(input, ABS_Y, y);
  75. input_sync(input);
  76. }
  77. jornada_ssp_end();
  78. }
  79. return IRQ_HANDLED;
  80. }
  81. static int jornada720_ts_probe(struct platform_device *pdev)
  82. {
  83. struct jornada_ts *jornada_ts;
  84. struct input_dev *input_dev;
  85. int error;
  86. jornada_ts = devm_kzalloc(&pdev->dev, sizeof(*jornada_ts), GFP_KERNEL);
  87. if (!jornada_ts)
  88. return -ENOMEM;
  89. input_dev = devm_input_allocate_device(&pdev->dev);
  90. if (!input_dev)
  91. return -ENOMEM;
  92. platform_set_drvdata(pdev, jornada_ts);
  93. jornada_ts->dev = input_dev;
  94. input_dev->name = "HP Jornada 7xx Touchscreen";
  95. input_dev->phys = "jornadats/input0";
  96. input_dev->id.bustype = BUS_HOST;
  97. input_dev->dev.parent = &pdev->dev;
  98. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  99. input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  100. input_set_abs_params(input_dev, ABS_X, 270, 3900, 0, 0);
  101. input_set_abs_params(input_dev, ABS_Y, 180, 3700, 0, 0);
  102. error = devm_request_irq(&pdev->dev, IRQ_GPIO9,
  103. jornada720_ts_interrupt,
  104. IRQF_TRIGGER_RISING,
  105. "HP7XX Touchscreen driver", pdev);
  106. if (error) {
  107. dev_err(&pdev->dev, "HP7XX TS : Unable to acquire irq!\n");
  108. return error;
  109. }
  110. error = input_register_device(jornada_ts->dev);
  111. if (error)
  112. return error;
  113. return 0;
  114. }
  115. /* work with hotplug and coldplug */
  116. MODULE_ALIAS("platform:jornada_ts");
  117. static struct platform_driver jornada720_ts_driver = {
  118. .probe = jornada720_ts_probe,
  119. .driver = {
  120. .name = "jornada_ts",
  121. },
  122. };
  123. module_platform_driver(jornada720_ts_driver);