950-0689-input-goodix-Add-option-to-poll-instead-of-relying-o.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From 13a9614267e7d8d4075144a7bf4dbebfcc565367 Mon Sep 17 00:00:00 2001
  2. From: Dave Stevenson <[email protected]>
  3. Date: Mon, 30 Jan 2023 14:46:16 +0000
  4. Subject: [PATCH] input: goodix: Add option to poll instead of relying
  5. on IRQ line
  6. The interrupt line from the touch controller is not necessarily
  7. connected to the SoC, so add the option to poll for touch info.
  8. Signed-off-by: Dave Stevenson <[email protected]>
  9. ---
  10. drivers/input/touchscreen/goodix.c | 70 +++++++++++++++++++++++++++---
  11. drivers/input/touchscreen/goodix.h | 2 +
  12. 2 files changed, 66 insertions(+), 6 deletions(-)
  13. --- a/drivers/input/touchscreen/goodix.c
  14. +++ b/drivers/input/touchscreen/goodix.c
  15. @@ -48,6 +48,8 @@
  16. #define MAX_CONTACTS_LOC 5
  17. #define TRIGGER_LOC 6
  18. +#define POLL_INTERVAL_MS 17 /* 17ms = 60fps */
  19. +
  20. /* Our special handling for GPIO accesses through ACPI is x86 specific */
  21. #if defined CONFIG_X86 && defined CONFIG_ACPI
  22. #define ACPI_GPIO_SUPPORT
  23. @@ -513,16 +515,67 @@ static irqreturn_t goodix_ts_irq_handler
  24. return IRQ_HANDLED;
  25. }
  26. +static void goodix_ts_irq_poll_timer(struct timer_list *t)
  27. +{
  28. + struct goodix_ts_data *ts = from_timer(ts, t, timer);
  29. +
  30. + schedule_work(&ts->work_i2c_poll);
  31. + mod_timer(&ts->timer, jiffies + msecs_to_jiffies(POLL_INTERVAL_MS));
  32. +}
  33. +
  34. +static void goodix_ts_work_i2c_poll(struct work_struct *work)
  35. +{
  36. + struct goodix_ts_data *ts = container_of(work,
  37. + struct goodix_ts_data, work_i2c_poll);
  38. +
  39. + goodix_process_events(ts);
  40. + goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0);
  41. +}
  42. +
  43. +static void goodix_enable_irq(struct goodix_ts_data *ts)
  44. +{
  45. + if (ts->client->irq) {
  46. + enable_irq(ts->client->irq);
  47. + } else {
  48. + ts->timer.expires = jiffies + msecs_to_jiffies(POLL_INTERVAL_MS);
  49. + add_timer(&ts->timer);
  50. + }
  51. +}
  52. +
  53. +static void goodix_disable_irq(struct goodix_ts_data *ts)
  54. +{
  55. + if (ts->client->irq) {
  56. + disable_irq(ts->client->irq);
  57. + } else {
  58. + del_timer(&ts->timer);
  59. + cancel_work_sync(&ts->work_i2c_poll);
  60. + }
  61. +}
  62. +
  63. static void goodix_free_irq(struct goodix_ts_data *ts)
  64. {
  65. - devm_free_irq(&ts->client->dev, ts->client->irq, ts);
  66. + if (ts->client->irq) {
  67. + devm_free_irq(&ts->client->dev, ts->client->irq, ts);
  68. + } else {
  69. + del_timer(&ts->timer);
  70. + cancel_work_sync(&ts->work_i2c_poll);
  71. + }
  72. }
  73. static int goodix_request_irq(struct goodix_ts_data *ts)
  74. {
  75. - return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
  76. - NULL, goodix_ts_irq_handler,
  77. - ts->irq_flags, ts->client->name, ts);
  78. + if (ts->client->irq) {
  79. + return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
  80. + NULL, goodix_ts_irq_handler,
  81. + ts->irq_flags, ts->client->name, ts);
  82. + } else {
  83. + INIT_WORK(&ts->work_i2c_poll,
  84. + goodix_ts_work_i2c_poll);
  85. + timer_setup(&ts->timer, goodix_ts_irq_poll_timer, 0);
  86. + if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE)
  87. + goodix_enable_irq(ts);
  88. + return 0;
  89. + }
  90. }
  91. static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
  92. @@ -1425,6 +1478,11 @@ static void goodix_ts_remove(struct i2c_
  93. {
  94. struct goodix_ts_data *ts = i2c_get_clientdata(client);
  95. + if (!client->irq) {
  96. + del_timer(&ts->timer);
  97. + cancel_work_sync(&ts->work_i2c_poll);
  98. + }
  99. +
  100. if (ts->load_cfg_from_disk)
  101. wait_for_completion(&ts->firmware_loading_complete);
  102. }
  103. @@ -1440,7 +1498,7 @@ static int __maybe_unused goodix_suspend
  104. /* We need gpio pins to suspend/resume */
  105. if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
  106. - disable_irq(client->irq);
  107. + goodix_disable_irq(ts);
  108. return 0;
  109. }
  110. @@ -1484,7 +1542,7 @@ static int __maybe_unused goodix_resume(
  111. int error;
  112. if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
  113. - enable_irq(client->irq);
  114. + goodix_enable_irq(ts);
  115. return 0;
  116. }
  117. --- a/drivers/input/touchscreen/goodix.h
  118. +++ b/drivers/input/touchscreen/goodix.h
  119. @@ -104,6 +104,8 @@ struct goodix_ts_data {
  120. u8 main_clk[GOODIX_MAIN_CLK_LEN];
  121. int bak_ref_len;
  122. u8 *bak_ref;
  123. + struct timer_list timer;
  124. + struct work_struct work_i2c_poll;
  125. };
  126. int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len);