qts_core.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/soc/qcom/panel_event_notifier.h>
  6. #include <linux/export.h>
  7. #include <linux/slab.h>
  8. #include <linux/kernel.h>
  9. #include <linux/device.h>
  10. #include <linux/i2c.h>
  11. #include <linux/spi/spi.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/gpio.h>
  15. #include <linux/firmware.h>
  16. #include <linux/mutex.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/fs.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/kthread.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include "linux/gunyah/gh_msgq.h"
  26. #include "linux/gunyah/gh_rm_drv.h"
  27. #include <linux/gunyah/gh_irq_lend.h>
  28. #include <linux/gunyah/gh_mem_notifier.h>
  29. #include "qts_core_common.h"
  30. #include <linux/clk.h>
  31. #include <linux/kobject.h>
  32. #define QTS_NAME "qti-ts"
  33. enum trusted_touch_mode_config {
  34. TRUSTED_TOUCH_VM_MODE,
  35. TRUSTED_TOUCH_MODE_NONE
  36. };
  37. enum trusted_touch_pvm_states {
  38. TRUSTED_TOUCH_PVM_INIT,
  39. PVM_I2C_RESOURCE_ACQUIRED,
  40. PVM_INTERRUPT_DISABLED,
  41. PVM_IOMEM_LENT,
  42. PVM_IOMEM_LENT_NOTIFIED,
  43. PVM_IRQ_LENT,
  44. PVM_IRQ_LENT_NOTIFIED,
  45. PVM_IOMEM_RELEASE_NOTIFIED,
  46. PVM_IRQ_RELEASE_NOTIFIED,
  47. PVM_ALL_RESOURCES_RELEASE_NOTIFIED,
  48. PVM_IRQ_RECLAIMED,
  49. PVM_IOMEM_RECLAIMED,
  50. PVM_INTERRUPT_ENABLED,
  51. PVM_I2C_RESOURCE_RELEASED,
  52. TRUSTED_TOUCH_PVM_STATE_MAX
  53. };
  54. enum trusted_touch_tvm_states {
  55. TRUSTED_TOUCH_TVM_INIT,
  56. TVM_IOMEM_LENT_NOTIFIED,
  57. TVM_IRQ_LENT_NOTIFIED,
  58. TVM_ALL_RESOURCES_LENT_NOTIFIED,
  59. TVM_IOMEM_ACCEPTED,
  60. TVM_I2C_SESSION_ACQUIRED,
  61. TVM_IRQ_ACCEPTED,
  62. TVM_INTERRUPT_ENABLED,
  63. TVM_INTERRUPT_DISABLED,
  64. TVM_IRQ_RELEASED,
  65. TVM_I2C_SESSION_RELEASED,
  66. TVM_IOMEM_RELEASED,
  67. TRUSTED_TOUCH_TVM_STATE_MAX
  68. };
  69. #define TRUSTED_TOUCH_MEM_LABEL 0x7
  70. #define TOUCH_RESET_GPIO_BASE 0xf118000
  71. #define TOUCH_RESET_GPIO_SIZE 0x1000
  72. #define TOUCH_RESET_GPIO_OFFSET 0x4
  73. #define TOUCH_INTR_GPIO_BASE 0xf119000
  74. #define TOUCH_INTR_GPIO_SIZE 0x1000
  75. #define TOUCH_INTR_GPIO_OFFSET 0x8
  76. #define TRUSTED_TOUCH_EVENT_LEND_FAILURE -1
  77. #define TRUSTED_TOUCH_EVENT_LEND_NOTIFICATION_FAILURE -2
  78. #define TRUSTED_TOUCH_EVENT_ACCEPT_FAILURE -3
  79. #define TRUSTED_TOUCH_EVENT_FUNCTIONAL_FAILURE -4
  80. #define TRUSTED_TOUCH_EVENT_RELEASE_FAILURE -5
  81. #define TRUSTED_TOUCH_EVENT_RECLAIM_FAILURE -6
  82. #define TRUSTED_TOUCH_EVENT_I2C_FAILURE -7
  83. #define TRUSTED_TOUCH_EVENT_NOTIFICATIONS_PENDING 5
  84. struct trusted_touch_vm_info {
  85. enum gh_irq_label irq_label;
  86. enum gh_mem_notifier_tag mem_tag;
  87. enum gh_vm_names vm_name;
  88. const char *trusted_touch_type;
  89. u32 hw_irq;
  90. gh_memparcel_handle_t vm_mem_handle;
  91. u32 *iomem_bases;
  92. u32 *iomem_sizes;
  93. u32 iomem_list_size;
  94. void *mem_cookie;
  95. atomic_t vm_state;
  96. };
  97. struct qts_data;
  98. struct qts_data {
  99. struct i2c_client *client;
  100. struct spi_device *spi;
  101. struct device *dev;
  102. struct device_node *dp;
  103. void *vendor_data; /* vendor touch driver data */
  104. u32 bus_type; /*i2c or spi*/
  105. u32 client_type; /* primary or secondary */
  106. struct drm_panel *panel;
  107. struct workqueue_struct *ts_workqueue;
  108. struct work_struct resume_work;
  109. struct work_struct suspend_work;
  110. bool schedule_suspend;
  111. bool schedule_resume;
  112. void *notifier_cookie;
  113. /* Resources */
  114. struct regulator *vdd;
  115. struct regulator *avdd;
  116. u32 irq_gpio;
  117. u32 irq_gpio_flags;
  118. u32 reset_gpio;
  119. u32 reset_gpio_flags;
  120. int irq;
  121. bool irq_disabled;
  122. bool power_disabled;
  123. struct mutex transition_lock;
  124. bool suspended;
  125. /* vendor callback ops */
  126. struct qts_vendor_callback_ops vendor_ops;
  127. /* TUI */
  128. bool tui_supported;
  129. struct trusted_touch_vm_info *vm_info;
  130. struct mutex qts_clk_io_ctrl_mutex;
  131. const char *touch_environment;
  132. struct completion trusted_touch_powerdown;
  133. struct clk *core_clk;
  134. struct clk *iface_clk;
  135. atomic_t trusted_touch_initialized;
  136. atomic_t trusted_touch_enabled;
  137. atomic_t trusted_touch_transition;
  138. atomic_t trusted_touch_event;
  139. atomic_t trusted_touch_abort_status;
  140. atomic_t delayed_tvm_probe_pending;
  141. atomic_t delayed_pvm_probe_pending;
  142. atomic_t trusted_touch_mode;
  143. };
  144. struct qts_data_entries;
  145. struct qts_data_entries {
  146. struct kset *qts_kset;
  147. struct qts_data info[QTS_CLIENT_MAX];
  148. struct mutex qts_data_entries_lock;
  149. };
  150. #ifdef CONFIG_ARCH_QTI_VM
  151. void qts_trusted_touch_tvm_i2c_failure_report(struct qts_data *qts_data);
  152. #endif