of_touchscreen.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Generic DT helper functions for touchscreen devices
  3. *
  4. * Copyright (c) 2014 Sebastian Reichel <sre@kernel.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/of.h>
  12. #include <linux/input.h>
  13. #include <linux/input/mt.h>
  14. #include <linux/input/touchscreen.h>
  15. static u32 of_get_optional_u32(struct device_node *np,
  16. const char *property)
  17. {
  18. u32 val = 0;
  19. of_property_read_u32(np, property, &val);
  20. return val;
  21. }
  22. static void touchscreen_set_params(struct input_dev *dev,
  23. unsigned long axis,
  24. int max, int fuzz)
  25. {
  26. struct input_absinfo *absinfo;
  27. if (!test_bit(axis, dev->absbit)) {
  28. /*
  29. * Emit a warning only if the axis is not a multitouch
  30. * axis, which might not be set by the driver.
  31. */
  32. if (!input_is_mt_axis(axis))
  33. dev_warn(&dev->dev,
  34. "DT specifies parameters but the axis is not set up\n");
  35. return;
  36. }
  37. absinfo = &dev->absinfo[axis];
  38. absinfo->maximum = max;
  39. absinfo->fuzz = fuzz;
  40. }
  41. /**
  42. * touchscreen_parse_of_params - parse common touchscreen DT properties
  43. * @dev: device that should be parsed
  44. *
  45. * This function parses common DT properties for touchscreens and setups the
  46. * input device accordingly. The function keeps previously setuped default
  47. * values if no value is specified via DT.
  48. */
  49. void touchscreen_parse_of_params(struct input_dev *dev)
  50. {
  51. struct device_node *np = dev->dev.parent->of_node;
  52. u32 maximum, fuzz;
  53. input_alloc_absinfo(dev);
  54. if (!dev->absinfo)
  55. return;
  56. maximum = of_get_optional_u32(np, "touchscreen-size-x");
  57. fuzz = of_get_optional_u32(np, "touchscreen-fuzz-x");
  58. if (maximum || fuzz) {
  59. touchscreen_set_params(dev, ABS_X, maximum, fuzz);
  60. touchscreen_set_params(dev, ABS_MT_POSITION_X, maximum, fuzz);
  61. }
  62. maximum = of_get_optional_u32(np, "touchscreen-size-y");
  63. fuzz = of_get_optional_u32(np, "touchscreen-fuzz-y");
  64. if (maximum || fuzz) {
  65. touchscreen_set_params(dev, ABS_Y, maximum, fuzz);
  66. touchscreen_set_params(dev, ABS_MT_POSITION_Y, maximum, fuzz);
  67. }
  68. maximum = of_get_optional_u32(np, "touchscreen-max-pressure");
  69. fuzz = of_get_optional_u32(np, "touchscreen-fuzz-pressure");
  70. if (maximum || fuzz) {
  71. touchscreen_set_params(dev, ABS_PRESSURE, maximum, fuzz);
  72. touchscreen_set_params(dev, ABS_MT_PRESSURE, maximum, fuzz);
  73. }
  74. }
  75. EXPORT_SYMBOL(touchscreen_parse_of_params);