linux-022-add-dts-flags-to-atmel-mxt-touch.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. diff -Naurp a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
  2. --- a/drivers/input/touchscreen/atmel_mxt_ts.c 2018-01-20 11:42:13.000000000 +0100
  3. +++ b/drivers/input/touchscreen/atmel_mxt_ts.c 2018-01-25 09:03:33.876115406 +0100
  4. @@ -24,6 +24,7 @@
  5. #include <linux/i2c.h>
  6. #include <linux/platform_data/atmel_mxt_ts.h>
  7. #include <linux/input/mt.h>
  8. +#include <linux/input/touchscreen.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/of.h>
  11. #include <linux/slab.h>
  12. @@ -216,6 +217,9 @@ struct mxt_data {
  13. unsigned int irq;
  14. unsigned int max_x;
  15. unsigned int max_y;
  16. + bool invert_x;
  17. + bool invert_y;
  18. + bool swap_x_y;
  19. bool xy_switch;
  20. bool in_bootloader;
  21. u16 mem_size;
  22. @@ -257,6 +261,22 @@ struct mxt_data {
  23. struct completion crc_completion;
  24. };
  25. +static void mxt_apply_prop_to_x_y(const struct mxt_data *data,
  26. + int *x, int *y)
  27. +{
  28. + if (data->invert_x)
  29. + *x = data->max_x - *x;
  30. +
  31. + if (data->invert_y)
  32. + *y = data->max_y - *y;
  33. +
  34. + if (data->swap_x_y)
  35. + swap(*x, *y);
  36. +}
  37. +
  38. +
  39. +
  40. +
  41. static size_t mxt_obj_size(const struct mxt_object *obj)
  42. {
  43. return obj->size_minus_one + 1;
  44. @@ -741,6 +761,8 @@ static void mxt_proc_t9_message(struct m
  45. /* Touch active */
  46. input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1);
  47. + mxt_apply_prop_to_x_y(data, &x, &y);
  48. +
  49. input_report_abs(input_dev, ABS_MT_POSITION_X, x);
  50. input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
  51. input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude);
  52. @@ -760,8 +782,8 @@ static void mxt_proc_t100_message(struct
  53. int id;
  54. u8 status;
  55. u8 type = 0;
  56. - u16 x;
  57. - u16 y;
  58. + /*u16*/ int x;
  59. + /*u16*/ int y;
  60. int distance = 0;
  61. int tool = 0;
  62. u8 major = 0;
  63. @@ -845,6 +867,7 @@ static void mxt_proc_t100_message(struct
  64. id, type, x, y, major, pressure, orientation);
  65. input_mt_report_slot_state(input_dev, tool, 1);
  66. + mxt_apply_prop_to_x_y(data, &x, &y);
  67. input_report_abs(input_dev, ABS_MT_POSITION_X, x);
  68. input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
  69. input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, major);
  70. @@ -1778,7 +1801,8 @@ static int mxt_initialize_input_device(s
  71. int error;
  72. unsigned int num_mt_slots;
  73. unsigned int mt_flags = 0;
  74. -
  75. + struct device_node *np = dev->of_node;
  76. +
  77. switch (data->multitouch) {
  78. case MXT_TOUCH_MULTI_T9:
  79. num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
  80. @@ -1818,6 +1842,7 @@ static int mxt_initialize_input_device(s
  81. return -ENOMEM;
  82. }
  83. +
  84. input_dev->name = "Atmel maXTouch Touchscreen";
  85. input_dev->phys = data->phys;
  86. input_dev->id.bustype = BUS_I2C;
  87. @@ -1908,6 +1933,17 @@ static int mxt_initialize_input_device(s
  88. data->input_dev = input_dev;
  89. + if (np) {
  90. + data->invert_x = of_property_read_bool(np, "invert_x")?1:0;
  91. + data->invert_y = of_property_read_bool(np, "invert_y")?1:0;
  92. + data->swap_x_y = of_property_read_bool(np, "swap_x_y")?1:0;
  93. +
  94. + dev_info(dev, "loaded toucscreen properties\n");
  95. + dev_info(dev, "touchscreen-inverted-x %d\n", data->invert_x);
  96. + dev_info(dev, "touchscreen-inverted-y %d\n", data->invert_y);
  97. + dev_info(dev, "touchscreen-swap-x-y %d\n", data->swap_x_y);
  98. + }
  99. +
  100. return 0;
  101. err_free_mem: