jornada720_ts.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/gpio/consumer.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/input.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/io.h>
  22. #include <mach/jornada720.h>
  23. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  24. MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver");
  25. MODULE_LICENSE("GPL v2");
  26. struct jornada_ts {
  27. struct input_dev *dev;
  28. struct gpio_desc *gpio;
  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 is high then report pen up */
  62. if (gpiod_get_value(jornada_ts->gpio)) {
  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, irq;
  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->gpio = devm_gpiod_get(&pdev->dev, "penup", GPIOD_IN);
  94. if (IS_ERR(jornada_ts->gpio))
  95. return PTR_ERR(jornada_ts->gpio);
  96. irq = gpiod_to_irq(jornada_ts->gpio);
  97. if (irq <= 0)
  98. return irq < 0 ? irq : -EINVAL;
  99. jornada_ts->dev = input_dev;
  100. input_dev->name = "HP Jornada 7xx Touchscreen";
  101. input_dev->phys = "jornadats/input0";
  102. input_dev->id.bustype = BUS_HOST;
  103. input_dev->dev.parent = &pdev->dev;
  104. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  105. input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  106. input_set_abs_params(input_dev, ABS_X, 270, 3900, 0, 0);
  107. input_set_abs_params(input_dev, ABS_Y, 180, 3700, 0, 0);
  108. error = devm_request_irq(&pdev->dev, irq, jornada720_ts_interrupt,
  109. IRQF_TRIGGER_RISING,
  110. "HP7XX Touchscreen driver", pdev);
  111. if (error) {
  112. dev_err(&pdev->dev, "HP7XX TS : Unable to acquire irq!\n");
  113. return error;
  114. }
  115. error = input_register_device(jornada_ts->dev);
  116. if (error)
  117. return error;
  118. return 0;
  119. }
  120. /* work with hotplug and coldplug */
  121. MODULE_ALIAS("platform:jornada_ts");
  122. static struct platform_driver jornada720_ts_driver = {
  123. .probe = jornada720_ts_probe,
  124. .driver = {
  125. .name = "jornada_ts",
  126. },
  127. };
  128. module_platform_driver(jornada720_ts_driver);