qts_core.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "%s: " fmt, __func__
  6. #include <linux/vmalloc.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/delay.h>
  9. #include <linux/input.h>
  10. #include <linux/input/mt.h>
  11. #include <linux/of_gpio.h>
  12. #include <linux/of_graph.h>
  13. #include <linux/of_device.h>
  14. #include <linux/sysfs.h>
  15. #include <linux/sort.h>
  16. #include <linux/atomic.h>
  17. #include <linux/pinctrl/qcom-pinctrl.h>
  18. #include <linux/pm.h>
  19. #include <linux/pm_runtime.h>
  20. #include <linux/component.h>
  21. #include <linux/sched.h>
  22. #include <linux/version.h>
  23. #include <linux/types.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/wait.h>
  27. #include <linux/time.h>
  28. #include "qts_core.h"
  29. static struct qts_data_entries *qts_data_entries;
  30. struct drm_panel *active_panel;
  31. static void qts_trusted_touch_abort_handler(struct qts_data *qts_data, int error);
  32. static struct gh_acl_desc *qts_vm_get_acl(enum gh_vm_names vm_name)
  33. {
  34. struct gh_acl_desc *acl_desc;
  35. gh_vmid_t vmid;
  36. gh_rm_get_vmid(vm_name, &vmid);
  37. acl_desc = kzalloc(offsetof(struct gh_acl_desc, acl_entries[1]),
  38. GFP_KERNEL);
  39. if (!acl_desc)
  40. return ERR_PTR(ENOMEM);
  41. acl_desc->n_acl_entries = 1;
  42. acl_desc->acl_entries[0].vmid = vmid;
  43. acl_desc->acl_entries[0].perms = GH_RM_ACL_R | GH_RM_ACL_W;
  44. return acl_desc;
  45. }
  46. static struct gh_sgl_desc *qts_vm_get_sgl(struct trusted_touch_vm_info *vm_info)
  47. {
  48. struct gh_sgl_desc *sgl_desc;
  49. int i;
  50. sgl_desc = kzalloc(offsetof(struct gh_sgl_desc,
  51. sgl_entries[vm_info->iomem_list_size]), GFP_KERNEL);
  52. if (!sgl_desc)
  53. return ERR_PTR(ENOMEM);
  54. sgl_desc->n_sgl_entries = vm_info->iomem_list_size;
  55. for (i = 0; i < vm_info->iomem_list_size; i++) {
  56. sgl_desc->sgl_entries[i].ipa_base = vm_info->iomem_bases[i];
  57. sgl_desc->sgl_entries[i].size = vm_info->iomem_sizes[i];
  58. }
  59. return sgl_desc;
  60. }
  61. static int qts_populate_vm_info_iomem(struct qts_data *qts_data)
  62. {
  63. int i, gpio, rc = 0;
  64. int num_regs, num_sizes, num_gpios, list_size;
  65. struct resource res;
  66. struct device_node *np = qts_data->dev->of_node;
  67. struct trusted_touch_vm_info *vm_info = qts_data->vm_info;
  68. num_regs = of_property_count_u32_elems(np, "qts,trusted-touch-io-bases");
  69. if (num_regs < 0) {
  70. pr_err("Invalid number of IO regions specified\n");
  71. return -EINVAL;
  72. }
  73. num_sizes = of_property_count_u32_elems(np, "qts,trusted-touch-io-sizes");
  74. if (num_sizes < 0) {
  75. pr_err("Invalid number of IO regions specified\n");
  76. return -EINVAL;
  77. }
  78. if (num_regs != num_sizes) {
  79. pr_err("IO bases and sizes array lengths mismatch\n");
  80. return -EINVAL;
  81. }
  82. num_gpios = of_gpio_named_count(np, "qts,trusted-touch-vm-gpio-list");
  83. if (num_gpios < 0) {
  84. pr_warn("Ignoring invalid trusted gpio list: %d\n", num_gpios);
  85. num_gpios = 0;
  86. }
  87. list_size = num_regs + num_gpios;
  88. vm_info->iomem_list_size = list_size;
  89. vm_info->iomem_bases = devm_kcalloc(qts_data->dev, list_size, sizeof(*vm_info->iomem_bases),
  90. GFP_KERNEL);
  91. if (!vm_info->iomem_bases)
  92. return -ENOMEM;
  93. vm_info->iomem_sizes = devm_kcalloc(qts_data->dev, list_size, sizeof(*vm_info->iomem_sizes),
  94. GFP_KERNEL);
  95. if (!vm_info->iomem_sizes)
  96. return -ENOMEM;
  97. for (i = 0; i < num_gpios; ++i) {
  98. gpio = of_get_named_gpio(np, "qts,trusted-touch-vm-gpio-list", i);
  99. if (gpio < 0 || !gpio_is_valid(gpio)) {
  100. pr_err("Invalid gpio %d at position %d\n", gpio, i);
  101. return gpio;
  102. }
  103. if (!msm_gpio_get_pin_address(gpio, &res)) {
  104. pr_err("Failed to retrieve gpio-%d resource\n", gpio);
  105. return -ENODATA;
  106. }
  107. vm_info->iomem_bases[i] = res.start;
  108. vm_info->iomem_sizes[i] = resource_size(&res);
  109. }
  110. rc = of_property_read_u32_array(np, "qts,trusted-touch-io-bases",
  111. &vm_info->iomem_bases[i], list_size - i);
  112. if (rc) {
  113. pr_err("Failed to read trusted touch io bases:%d\n", rc);
  114. return rc;
  115. }
  116. rc = of_property_read_u32_array(np, "qts,trusted-touch-io-sizes",
  117. &vm_info->iomem_sizes[i], list_size - i);
  118. if (rc) {
  119. pr_err("Failed to read trusted touch io sizes:%d\n", rc);
  120. return rc;
  121. }
  122. return 0;
  123. }
  124. static int qts_populate_vm_info(struct qts_data *qts_data)
  125. {
  126. int rc;
  127. struct trusted_touch_vm_info *vm_info;
  128. struct device_node *np = qts_data->dev->of_node;
  129. vm_info = devm_kzalloc(qts_data->dev, sizeof(struct trusted_touch_vm_info), GFP_KERNEL);
  130. if (!vm_info)
  131. return -ENOMEM;
  132. qts_data->vm_info = vm_info;
  133. vm_info->vm_name = GH_TRUSTED_VM;
  134. rc = of_property_read_u32(np, "qts,trusted-touch-spi-irq", &vm_info->hw_irq);
  135. if (rc) {
  136. pr_err("Failed to read trusted touch SPI irq:%d\n", rc);
  137. return rc;
  138. }
  139. rc = qts_populate_vm_info_iomem(qts_data);
  140. if (rc) {
  141. pr_err("Failed to read trusted touch mmio ranges:%d\n", rc);
  142. return rc;
  143. }
  144. rc = of_property_read_string(np, "qts,trusted-touch-type",
  145. &vm_info->trusted_touch_type);
  146. if (rc) {
  147. pr_warn("%s: No trusted touch type selection made\n");
  148. vm_info->mem_tag = GH_MEM_NOTIFIER_TAG_TOUCH_PRIMARY;
  149. vm_info->irq_label = GH_IRQ_LABEL_TRUSTED_TOUCH_PRIMARY;
  150. rc = 0;
  151. } else if (!strcmp(vm_info->trusted_touch_type, "primary")) {
  152. vm_info->mem_tag = GH_MEM_NOTIFIER_TAG_TOUCH_PRIMARY;
  153. vm_info->irq_label = GH_IRQ_LABEL_TRUSTED_TOUCH_PRIMARY;
  154. } else if (!strcmp(vm_info->trusted_touch_type, "secondary")) {
  155. vm_info->mem_tag = GH_MEM_NOTIFIER_TAG_TOUCH_SECONDARY;
  156. vm_info->irq_label = GH_IRQ_LABEL_TRUSTED_TOUCH_SECONDARY;
  157. }
  158. return 0;
  159. }
  160. static void qts_destroy_vm_info(struct qts_data *qts_data)
  161. {
  162. kfree(qts_data->vm_info->iomem_sizes);
  163. kfree(qts_data->vm_info->iomem_bases);
  164. kfree(qts_data->vm_info);
  165. }
  166. static void qts_vm_deinit(struct qts_data *qts_data)
  167. {
  168. if (qts_data->vm_info->mem_cookie)
  169. gh_mem_notifier_unregister(qts_data->vm_info->mem_cookie);
  170. qts_destroy_vm_info(qts_data);
  171. }
  172. static int qts_trusted_touch_get_vm_state(struct qts_data *qts_data)
  173. {
  174. return atomic_read(&qts_data->vm_info->vm_state);
  175. }
  176. static void qts_trusted_touch_set_vm_state(struct qts_data *qts_data,
  177. int state)
  178. {
  179. pr_debug("state %d\n", state);
  180. atomic_set(&qts_data->vm_info->vm_state, state);
  181. }
  182. #ifdef CONFIG_ARCH_QTI_VM
  183. static int qts_vm_mem_release(struct qts_data *qts_data);
  184. static void qts_trusted_touch_tvm_vm_mode_disable(struct qts_data *qts_data);
  185. static void qts_trusted_touch_abort_tvm(struct qts_data *qts_data);
  186. static void qts_trusted_touch_event_notify(struct qts_data *qts_data, int event);
  187. static void qts_irq_enable(struct qts_data *qts_data, bool en)
  188. {
  189. if (en) {
  190. if (qts_data->irq_disabled) {
  191. pr_debug("qts irq enable\n");
  192. enable_irq(qts_data->irq);
  193. qts_data->irq_disabled = false;
  194. }
  195. } else {
  196. if (!qts_data->irq_disabled) {
  197. pr_debug("qts irq disable\n");
  198. disable_irq_nosync(qts_data->irq);
  199. qts_data->irq_disabled = true;
  200. }
  201. }
  202. }
  203. static irqreturn_t qts_irq_handler(int irq, void *data)
  204. {
  205. struct qts_data *qts_data = data;
  206. if (!mutex_trylock(&qts_data->transition_lock))
  207. return IRQ_HANDLED;
  208. qts_data->vendor_ops.irq_handler(irq, qts_data->vendor_data);
  209. mutex_unlock(&qts_data->transition_lock);
  210. return IRQ_HANDLED;
  211. }
  212. static int qts_irq_registration(struct qts_data *qts_data)
  213. {
  214. int ret = 0;
  215. qts_data->irq_gpio_flags = IRQF_TRIGGER_RISING;
  216. pr_debug("irq:%d, flag:%x\n", qts_data->irq, qts_data->irq_gpio_flags);
  217. ret = request_threaded_irq(qts_data->irq, NULL, qts_irq_handler,
  218. qts_data->irq_gpio_flags | IRQF_ONESHOT,
  219. QTS_NAME, qts_data);
  220. if (ret != 0)
  221. pr_err("request_threaded_irq failed\n");
  222. if (ret == 0)
  223. qts_irq_enable(qts_data, false);
  224. return ret;
  225. }
  226. void qts_trusted_touch_tvm_i2c_failure_report(struct qts_data *qts_data)
  227. {
  228. pr_warn("initiating trusted touch abort due to i2c failure\n");
  229. qts_trusted_touch_abort_handler(qts_data, TRUSTED_TOUCH_EVENT_I2C_FAILURE);
  230. }
  231. static void qts_trusted_touch_reset_gpio_toggle(struct qts_data *qts_data)
  232. {
  233. void __iomem *base;
  234. if (qts_data->bus_type != QTS_BUS_TYPE_I2C)
  235. return;
  236. base = ioremap(TOUCH_RESET_GPIO_BASE, TOUCH_RESET_GPIO_SIZE);
  237. writel_relaxed(0x1, base + TOUCH_RESET_GPIO_OFFSET);
  238. /* wait until toggle to finish*/
  239. wmb();
  240. writel_relaxed(0x0, base + TOUCH_RESET_GPIO_OFFSET);
  241. /* wait until toggle to finish*/
  242. wmb();
  243. iounmap(base);
  244. }
  245. static void qts_trusted_touch_intr_gpio_toggle(struct qts_data *qts_data,
  246. bool enable)
  247. {
  248. void __iomem *base;
  249. u32 val;
  250. if (qts_data->bus_type != QTS_BUS_TYPE_I2C)
  251. return;
  252. base = ioremap(TOUCH_INTR_GPIO_BASE, TOUCH_INTR_GPIO_SIZE);
  253. val = readl_relaxed(base + TOUCH_RESET_GPIO_OFFSET);
  254. if (enable) {
  255. val |= BIT(0);
  256. writel_relaxed(val, base + TOUCH_INTR_GPIO_OFFSET);
  257. /* wait until toggle to finish*/
  258. wmb();
  259. } else {
  260. val &= ~BIT(0);
  261. writel_relaxed(val, base + TOUCH_INTR_GPIO_OFFSET);
  262. /* wait until toggle to finish*/
  263. wmb();
  264. }
  265. iounmap(base);
  266. }
  267. static int qts_sgl_cmp(const void *a, const void *b)
  268. {
  269. struct gh_sgl_entry *left = (struct gh_sgl_entry *)a;
  270. struct gh_sgl_entry *right = (struct gh_sgl_entry *)b;
  271. return (left->ipa_base - right->ipa_base);
  272. }
  273. static int qts_vm_compare_sgl_desc(struct gh_sgl_desc *expected,
  274. struct gh_sgl_desc *received)
  275. {
  276. int idx;
  277. if (expected->n_sgl_entries != received->n_sgl_entries)
  278. return -E2BIG;
  279. sort(received->sgl_entries, received->n_sgl_entries,
  280. sizeof(received->sgl_entries[0]), qts_sgl_cmp, NULL);
  281. sort(expected->sgl_entries, expected->n_sgl_entries,
  282. sizeof(expected->sgl_entries[0]), qts_sgl_cmp, NULL);
  283. for (idx = 0; idx < expected->n_sgl_entries; idx++) {
  284. struct gh_sgl_entry *left = &expected->sgl_entries[idx];
  285. struct gh_sgl_entry *right = &received->sgl_entries[idx];
  286. if ((left->ipa_base != right->ipa_base) ||
  287. (left->size != right->size)) {
  288. pr_err("sgl mismatch: left_base:%d right base:%d left size:%d right size:%d\n",
  289. left->ipa_base, right->ipa_base, left->size, right->size);
  290. return -EINVAL;
  291. }
  292. }
  293. return 0;
  294. }
  295. static int qts_vm_handle_vm_hardware(struct qts_data *qts_data)
  296. {
  297. int rc = 0;
  298. if (atomic_read(&qts_data->delayed_tvm_probe_pending)) {
  299. rc = qts_irq_registration(qts_data);
  300. if (rc) {
  301. pr_err("irq registration failure on TVM!\n");
  302. return rc;
  303. }
  304. atomic_set(&qts_data->delayed_tvm_probe_pending, 0);
  305. }
  306. qts_irq_enable(qts_data, true);
  307. qts_trusted_touch_set_vm_state(qts_data, TVM_INTERRUPT_ENABLED);
  308. return rc;
  309. }
  310. static void qts_trusted_touch_tvm_vm_mode_enable(struct qts_data *qts_data)
  311. {
  312. struct gh_sgl_desc *sgl_desc, *expected_sgl_desc;
  313. struct gh_acl_desc *acl_desc;
  314. struct irq_data *irq_data;
  315. int rc = 0;
  316. int irq = 0;
  317. mutex_lock(&qts_data->transition_lock);
  318. if (qts_trusted_touch_get_vm_state(qts_data) != TVM_ALL_RESOURCES_LENT_NOTIFIED) {
  319. pr_info("All lend notifications not received\n");
  320. qts_trusted_touch_event_notify(qts_data,
  321. TRUSTED_TOUCH_EVENT_NOTIFICATIONS_PENDING);
  322. mutex_unlock(&qts_data->transition_lock);
  323. return;
  324. }
  325. if (qts_data->vendor_ops.pre_le_tui_enable)
  326. qts_data->vendor_ops.pre_le_tui_enable(qts_data->vendor_data);
  327. acl_desc = qts_vm_get_acl(GH_TRUSTED_VM);
  328. if (IS_ERR(acl_desc)) {
  329. pr_err("failed to populated acl data:rc=%d\n", PTR_ERR(acl_desc));
  330. goto accept_fail;
  331. }
  332. sgl_desc = gh_rm_mem_accept(qts_data->vm_info->vm_mem_handle,
  333. GH_RM_MEM_TYPE_IO,
  334. GH_RM_TRANS_TYPE_LEND,
  335. GH_RM_MEM_ACCEPT_VALIDATE_ACL_ATTRS |
  336. GH_RM_MEM_ACCEPT_VALIDATE_LABEL |
  337. GH_RM_MEM_ACCEPT_DONE, TRUSTED_TOUCH_MEM_LABEL,
  338. acl_desc, NULL, NULL, 0);
  339. if (IS_ERR_OR_NULL(sgl_desc)) {
  340. pr_err("failed to do mem accept :rc=%d\n", PTR_ERR(sgl_desc));
  341. goto acl_fail;
  342. }
  343. qts_trusted_touch_set_vm_state(qts_data, TVM_IOMEM_ACCEPTED);
  344. /* Initiate session on tvm */
  345. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  346. rc = pm_runtime_get_sync(qts_data->client->adapter->dev.parent);
  347. else
  348. rc = pm_runtime_get_sync(qts_data->spi->master->dev.parent);
  349. if (rc < 0) {
  350. pr_err("failed to get sync rc:%d\n", rc);
  351. goto acl_fail;
  352. }
  353. qts_trusted_touch_set_vm_state(qts_data, TVM_I2C_SESSION_ACQUIRED);
  354. expected_sgl_desc = qts_vm_get_sgl(qts_data->vm_info);
  355. if (qts_vm_compare_sgl_desc(expected_sgl_desc, sgl_desc)) {
  356. pr_err("IO sg list does not match\n");
  357. goto sgl_cmp_fail;
  358. }
  359. kfree(expected_sgl_desc);
  360. kfree(acl_desc);
  361. irq = gh_irq_accept(qts_data->vm_info->irq_label, -1, IRQ_TYPE_EDGE_RISING);
  362. qts_trusted_touch_intr_gpio_toggle(qts_data, false);
  363. if (irq < 0) {
  364. pr_err("failed to accept irq\n");
  365. goto accept_fail;
  366. }
  367. qts_trusted_touch_set_vm_state(qts_data, TVM_IRQ_ACCEPTED);
  368. irq_data = irq_get_irq_data(irq);
  369. if (!irq_data) {
  370. pr_err("Invalid irq data for trusted touch\n");
  371. goto accept_fail;
  372. }
  373. if (!irq_data->hwirq) {
  374. pr_err("Invalid irq in irq data\n");
  375. goto accept_fail;
  376. }
  377. if (irq_data->hwirq != qts_data->vm_info->hw_irq) {
  378. pr_err("Invalid irq lent\n");
  379. goto accept_fail;
  380. }
  381. pr_debug("irq:returned from accept:%d\n", irq);
  382. qts_data->irq = irq;
  383. rc = qts_vm_handle_vm_hardware(qts_data);
  384. if (rc) {
  385. pr_err("Delayed probe failure on TVM!\n");
  386. goto accept_fail;
  387. }
  388. atomic_set(&qts_data->trusted_touch_enabled, 1);
  389. if (qts_data->vendor_ops.post_le_tui_enable)
  390. qts_data->vendor_ops.post_le_tui_enable(qts_data->vendor_data);
  391. pr_debug("trusted touch enabled\n");
  392. mutex_unlock(&qts_data->transition_lock);
  393. return;
  394. sgl_cmp_fail:
  395. kfree(expected_sgl_desc);
  396. acl_fail:
  397. kfree(acl_desc);
  398. accept_fail:
  399. qts_trusted_touch_abort_handler(qts_data,
  400. TRUSTED_TOUCH_EVENT_ACCEPT_FAILURE);
  401. mutex_unlock(&qts_data->transition_lock);
  402. }
  403. static void qts_vm_irq_on_lend_callback(void *data,
  404. unsigned long notif_type,
  405. enum gh_irq_label label)
  406. {
  407. struct qts_data *qts_data = data;
  408. pr_debug("received irq lend request for label:%d\n", label);
  409. if (qts_trusted_touch_get_vm_state(qts_data) == TVM_IOMEM_LENT_NOTIFIED)
  410. qts_trusted_touch_set_vm_state(qts_data, TVM_ALL_RESOURCES_LENT_NOTIFIED);
  411. else
  412. qts_trusted_touch_set_vm_state(qts_data, TVM_IRQ_LENT_NOTIFIED);
  413. }
  414. static void qts_vm_mem_on_lend_handler(enum gh_mem_notifier_tag tag,
  415. unsigned long notif_type, void *entry_data, void *notif_msg)
  416. {
  417. struct gh_rm_notif_mem_shared_payload *payload;
  418. struct trusted_touch_vm_info *vm_info;
  419. struct qts_data *qts_data;
  420. qts_data = (struct qts_data *)entry_data;
  421. vm_info = qts_data->vm_info;
  422. if (!vm_info) {
  423. pr_err("Invalid vm_info\n");
  424. return;
  425. }
  426. if (notif_type != GH_RM_NOTIF_MEM_SHARED ||
  427. tag != vm_info->mem_tag) {
  428. pr_err("Invalid command passed from rm\n");
  429. return;
  430. }
  431. if (!entry_data || !notif_msg) {
  432. pr_err("Invalid entry data passed from rm\n");
  433. return;
  434. }
  435. payload = (struct gh_rm_notif_mem_shared_payload *)notif_msg;
  436. if (payload->trans_type != GH_RM_TRANS_TYPE_LEND ||
  437. payload->label != TRUSTED_TOUCH_MEM_LABEL) {
  438. pr_err("Invalid label or transaction type\n");
  439. return;
  440. }
  441. vm_info->vm_mem_handle = payload->mem_handle;
  442. pr_debug("received mem lend request with handle:%d\n", vm_info->vm_mem_handle);
  443. if (qts_trusted_touch_get_vm_state(qts_data) == TVM_IRQ_LENT_NOTIFIED)
  444. qts_trusted_touch_set_vm_state(qts_data, TVM_ALL_RESOURCES_LENT_NOTIFIED);
  445. else
  446. qts_trusted_touch_set_vm_state(qts_data, TVM_IOMEM_LENT_NOTIFIED);
  447. }
  448. static int qts_vm_mem_release(struct qts_data *qts_data)
  449. {
  450. int rc = 0;
  451. if (!qts_data->vm_info->vm_mem_handle) {
  452. pr_err("Invalid memory handle\n");
  453. return -EINVAL;
  454. }
  455. rc = gh_rm_mem_release(qts_data->vm_info->vm_mem_handle, 0);
  456. if (rc)
  457. pr_err("VM mem release failed: rc=%d\n", rc);
  458. rc = gh_rm_mem_notify(qts_data->vm_info->vm_mem_handle,
  459. GH_RM_MEM_NOTIFY_OWNER_RELEASED,
  460. qts_data->vm_info->mem_tag, 0);
  461. if (rc)
  462. pr_err("Failed to notify mem release to PVM: rc=%d\n", rc);
  463. pr_debug("vm mem release success\n");
  464. qts_data->vm_info->vm_mem_handle = 0;
  465. return rc;
  466. }
  467. static void qts_trusted_touch_tvm_vm_mode_disable(struct qts_data *qts_data)
  468. {
  469. int rc = 0;
  470. mutex_lock(&qts_data->transition_lock);
  471. if (atomic_read(&qts_data->trusted_touch_abort_status)) {
  472. qts_trusted_touch_abort_tvm(qts_data);
  473. mutex_unlock(&qts_data->transition_lock);
  474. return;
  475. }
  476. if (qts_data->vendor_ops.pre_le_tui_disable)
  477. qts_data->vendor_ops.pre_le_tui_disable(qts_data->vendor_data);
  478. qts_irq_enable(qts_data, false);
  479. qts_trusted_touch_set_vm_state(qts_data, TVM_INTERRUPT_DISABLED);
  480. rc = gh_irq_release(qts_data->vm_info->irq_label);
  481. if (rc) {
  482. pr_err("Failed to release irq rc:%d\n", rc);
  483. goto error;
  484. } else {
  485. qts_trusted_touch_set_vm_state(qts_data, TVM_IRQ_RELEASED);
  486. }
  487. rc = gh_irq_release_notify(qts_data->vm_info->irq_label);
  488. if (rc)
  489. pr_err("Failed to notify release irq rc:%d\n", rc);
  490. pr_debug("vm irq release success\n");
  491. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  492. pm_runtime_put_sync(qts_data->client->adapter->dev.parent);
  493. else
  494. pm_runtime_put_sync(qts_data->spi->master->dev.parent);
  495. qts_trusted_touch_set_vm_state(qts_data, TVM_I2C_SESSION_RELEASED);
  496. rc = qts_vm_mem_release(qts_data);
  497. if (rc) {
  498. pr_err("Failed to release mem rc:%d\n", rc);
  499. goto error;
  500. } else {
  501. qts_trusted_touch_set_vm_state(qts_data, TVM_IOMEM_RELEASED);
  502. }
  503. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_TVM_INIT);
  504. atomic_set(&qts_data->trusted_touch_enabled, 0);
  505. if (qts_data->vendor_ops.post_le_tui_disable)
  506. qts_data->vendor_ops.post_le_tui_disable(qts_data->vendor_data);
  507. pr_debug("trusted touch disabled\n");
  508. mutex_unlock(&qts_data->transition_lock);
  509. return;
  510. error:
  511. qts_trusted_touch_abort_handler(qts_data,
  512. TRUSTED_TOUCH_EVENT_RELEASE_FAILURE);
  513. mutex_unlock(&qts_data->transition_lock);
  514. }
  515. static int qts_handle_trusted_touch_tvm(struct qts_data *qts_data, int value)
  516. {
  517. int err = 0;
  518. switch (value) {
  519. case 0:
  520. if ((atomic_read(&qts_data->trusted_touch_enabled) == 0) &&
  521. (atomic_read(&qts_data->trusted_touch_abort_status) == 0)) {
  522. pr_err("Trusted touch is already disabled\n");
  523. break;
  524. }
  525. if (atomic_read(&qts_data->trusted_touch_mode) ==
  526. TRUSTED_TOUCH_VM_MODE) {
  527. qts_trusted_touch_tvm_vm_mode_disable(qts_data);
  528. } else {
  529. pr_err("Unsupported trusted touch mode\n");
  530. }
  531. break;
  532. case 1:
  533. if (atomic_read(&qts_data->trusted_touch_enabled)) {
  534. pr_err("Trusted touch usecase underway\n");
  535. err = -EBUSY;
  536. break;
  537. }
  538. if (atomic_read(&qts_data->trusted_touch_mode) ==
  539. TRUSTED_TOUCH_VM_MODE) {
  540. qts_trusted_touch_tvm_vm_mode_enable(qts_data);
  541. } else {
  542. pr_err("Unsupported trusted touch mode\n");
  543. }
  544. break;
  545. default:
  546. pr_err("unsupported value: %lu\n", value);
  547. err = -EINVAL;
  548. break;
  549. }
  550. return err;
  551. }
  552. static void qts_trusted_touch_abort_tvm(struct qts_data *qts_data)
  553. {
  554. int rc = 0;
  555. int vm_state = qts_trusted_touch_get_vm_state(qts_data);
  556. if (vm_state >= TRUSTED_TOUCH_TVM_STATE_MAX) {
  557. pr_err("invalid tvm driver state: %d\n", vm_state);
  558. return;
  559. }
  560. switch (vm_state) {
  561. case TVM_INTERRUPT_ENABLED:
  562. qts_irq_enable(qts_data, false);
  563. case TVM_IRQ_ACCEPTED:
  564. case TVM_INTERRUPT_DISABLED:
  565. rc = gh_irq_release(qts_data->vm_info->irq_label);
  566. if (rc)
  567. pr_err("Failed to release irq rc:%d\n", rc);
  568. rc = gh_irq_release_notify(qts_data->vm_info->irq_label);
  569. if (rc)
  570. pr_err("Failed to notify irq release rc:%d\n", rc);
  571. case TVM_I2C_SESSION_ACQUIRED:
  572. case TVM_IOMEM_ACCEPTED:
  573. case TVM_IRQ_RELEASED:
  574. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  575. pm_runtime_put_sync(qts_data->client->adapter->dev.parent);
  576. else
  577. pm_runtime_put_sync(qts_data->spi->master->dev.parent);
  578. case TVM_I2C_SESSION_RELEASED:
  579. rc = qts_vm_mem_release(qts_data);
  580. if (rc)
  581. pr_err("Failed to release mem rc:%d\n", rc);
  582. case TVM_IOMEM_RELEASED:
  583. case TVM_ALL_RESOURCES_LENT_NOTIFIED:
  584. case TRUSTED_TOUCH_TVM_INIT:
  585. case TVM_IRQ_LENT_NOTIFIED:
  586. case TVM_IOMEM_LENT_NOTIFIED:
  587. atomic_set(&qts_data->trusted_touch_enabled, 0);
  588. }
  589. atomic_set(&qts_data->trusted_touch_abort_status, 0);
  590. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_TVM_INIT);
  591. }
  592. #else
  593. static void qts_bus_put(struct qts_data *qts_data);
  594. static int qts_enable_reg(struct qts_data *qts_data, bool enable);
  595. static void qts_trusted_touch_abort_pvm(struct qts_data *qts_data)
  596. {
  597. int rc = 0;
  598. int vm_state = qts_trusted_touch_get_vm_state(qts_data);
  599. if (vm_state >= TRUSTED_TOUCH_PVM_STATE_MAX) {
  600. pr_err("Invalid driver state: %d\n", vm_state);
  601. return;
  602. }
  603. switch (vm_state) {
  604. case PVM_IRQ_RELEASE_NOTIFIED:
  605. case PVM_ALL_RESOURCES_RELEASE_NOTIFIED:
  606. case PVM_IRQ_LENT:
  607. case PVM_IRQ_LENT_NOTIFIED:
  608. rc = gh_irq_reclaim(qts_data->vm_info->irq_label);
  609. if (rc)
  610. pr_err("failed to reclaim irq on pvm rc:%d\n", rc);
  611. case PVM_IRQ_RECLAIMED:
  612. case PVM_IOMEM_LENT:
  613. case PVM_IOMEM_LENT_NOTIFIED:
  614. case PVM_IOMEM_RELEASE_NOTIFIED:
  615. rc = gh_rm_mem_reclaim(qts_data->vm_info->vm_mem_handle, 0);
  616. if (rc)
  617. pr_err("failed to reclaim iomem on pvm rc:%d\n", rc);
  618. qts_data->vm_info->vm_mem_handle = 0;
  619. case PVM_IOMEM_RECLAIMED:
  620. case PVM_INTERRUPT_DISABLED:
  621. if (qts_data->vendor_ops.enable_touch_irq)
  622. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, true);
  623. case PVM_I2C_RESOURCE_ACQUIRED:
  624. case PVM_INTERRUPT_ENABLED:
  625. qts_bus_put(qts_data);
  626. case TRUSTED_TOUCH_PVM_INIT:
  627. case PVM_I2C_RESOURCE_RELEASED:
  628. atomic_set(&qts_data->trusted_touch_enabled, 0);
  629. atomic_set(&qts_data->trusted_touch_transition, 0);
  630. }
  631. atomic_set(&qts_data->trusted_touch_abort_status, 0);
  632. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  633. }
  634. static int qts_clk_prepare_enable(struct qts_data *qts_data)
  635. {
  636. int ret;
  637. ret = clk_prepare_enable(qts_data->iface_clk);
  638. if (ret) {
  639. pr_err("error on clk_prepare_enable(iface_clk):%d\n", ret);
  640. return ret;
  641. }
  642. ret = clk_prepare_enable(qts_data->core_clk);
  643. if (ret) {
  644. clk_disable_unprepare(qts_data->iface_clk);
  645. pr_err("error clk_prepare_enable(core_clk):%d\n", ret);
  646. }
  647. return ret;
  648. }
  649. static void qts_clk_disable_unprepare(struct qts_data *qts_data)
  650. {
  651. clk_disable_unprepare(qts_data->core_clk);
  652. clk_disable_unprepare(qts_data->iface_clk);
  653. }
  654. static int qts_bus_get(struct qts_data *qts_data)
  655. {
  656. int rc = 0;
  657. struct device *dev = NULL;
  658. if (qts_data->schedule_suspend)
  659. cancel_work_sync(&qts_data->suspend_work);
  660. if (qts_data->schedule_resume)
  661. cancel_work_sync(&qts_data->resume_work);
  662. reinit_completion(&qts_data->trusted_touch_powerdown);
  663. qts_enable_reg(qts_data, true);
  664. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  665. dev = qts_data->client->adapter->dev.parent;
  666. else
  667. dev = qts_data->spi->master->dev.parent;
  668. mutex_lock(&qts_data->qts_clk_io_ctrl_mutex);
  669. rc = pm_runtime_get_sync(dev);
  670. if (rc >= 0 && qts_data->core_clk != NULL &&
  671. qts_data->iface_clk != NULL) {
  672. rc = qts_clk_prepare_enable(qts_data);
  673. if (rc)
  674. pm_runtime_put_sync(dev);
  675. }
  676. mutex_unlock(&qts_data->qts_clk_io_ctrl_mutex);
  677. return rc;
  678. }
  679. static void qts_bus_put(struct qts_data *qts_data)
  680. {
  681. struct device *dev = NULL;
  682. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  683. dev = qts_data->client->adapter->dev.parent;
  684. else
  685. dev = qts_data->spi->master->dev.parent;
  686. mutex_lock(&qts_data->qts_clk_io_ctrl_mutex);
  687. if (qts_data->core_clk != NULL && qts_data->iface_clk != NULL)
  688. qts_clk_disable_unprepare(qts_data);
  689. pm_runtime_put_sync(dev);
  690. mutex_unlock(&qts_data->qts_clk_io_ctrl_mutex);
  691. complete(&qts_data->trusted_touch_powerdown);
  692. qts_enable_reg(qts_data, false);
  693. }
  694. static struct gh_notify_vmid_desc *qts_vm_get_vmid(gh_vmid_t vmid)
  695. {
  696. struct gh_notify_vmid_desc *vmid_desc;
  697. vmid_desc = kzalloc(offsetof(struct gh_notify_vmid_desc,
  698. vmid_entries[1]), GFP_KERNEL);
  699. if (!vmid_desc)
  700. return ERR_PTR(ENOMEM);
  701. vmid_desc->n_vmid_entries = 1;
  702. vmid_desc->vmid_entries[0].vmid = vmid;
  703. return vmid_desc;
  704. }
  705. static void qts_trusted_touch_pvm_vm_mode_disable(struct qts_data *qts_data)
  706. {
  707. int rc = 0;
  708. atomic_set(&qts_data->trusted_touch_transition, 1);
  709. if (atomic_read(&qts_data->trusted_touch_abort_status)) {
  710. qts_trusted_touch_abort_pvm(qts_data);
  711. return;
  712. }
  713. if (qts_trusted_touch_get_vm_state(qts_data) != PVM_ALL_RESOURCES_RELEASE_NOTIFIED)
  714. pr_debug("all release notifications are not received yet\n");
  715. if (qts_data->vendor_ops.pre_la_tui_disable)
  716. qts_data->vendor_ops.pre_la_tui_disable(qts_data->vendor_data);
  717. rc = gh_rm_mem_reclaim(qts_data->vm_info->vm_mem_handle, 0);
  718. if (rc) {
  719. pr_err("Trusted touch VM mem reclaim failed rc:%d\n", rc);
  720. goto error;
  721. }
  722. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_RECLAIMED);
  723. qts_data->vm_info->vm_mem_handle = 0;
  724. pr_debug("vm mem reclaim success!\n");
  725. rc = gh_irq_reclaim(qts_data->vm_info->irq_label);
  726. if (rc) {
  727. pr_err("failed to reclaim irq on pvm rc:%d\n", rc);
  728. goto error;
  729. }
  730. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_RECLAIMED);
  731. pr_debug("vm irq reclaim success!\n");
  732. if (qts_data->vendor_ops.enable_touch_irq)
  733. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, true);
  734. qts_trusted_touch_set_vm_state(qts_data, PVM_INTERRUPT_ENABLED);
  735. qts_bus_put(qts_data);
  736. atomic_set(&qts_data->trusted_touch_transition, 0);
  737. qts_trusted_touch_set_vm_state(qts_data, PVM_I2C_RESOURCE_RELEASED);
  738. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  739. atomic_set(&qts_data->trusted_touch_enabled, 0);
  740. if (qts_data->vendor_ops.post_la_tui_disable)
  741. qts_data->vendor_ops.post_la_tui_disable(qts_data->vendor_data);
  742. pr_debug("trusted touch disabled\n");
  743. return;
  744. error:
  745. qts_trusted_touch_abort_handler(qts_data,
  746. TRUSTED_TOUCH_EVENT_RECLAIM_FAILURE);
  747. }
  748. static void qts_vm_irq_on_release_callback(void *data,
  749. unsigned long notif_type,
  750. enum gh_irq_label label)
  751. {
  752. struct qts_data *qts_data = data;
  753. if (notif_type != GH_RM_NOTIF_VM_IRQ_RELEASED) {
  754. pr_err("invalid notification type\n");
  755. return;
  756. }
  757. if (qts_trusted_touch_get_vm_state(qts_data) == PVM_IOMEM_RELEASE_NOTIFIED)
  758. qts_trusted_touch_set_vm_state(qts_data, PVM_ALL_RESOURCES_RELEASE_NOTIFIED);
  759. else
  760. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_RELEASE_NOTIFIED);
  761. }
  762. static void qts_vm_mem_on_release_handler(enum gh_mem_notifier_tag tag,
  763. unsigned long notif_type, void *entry_data, void *notif_msg)
  764. {
  765. struct gh_rm_notif_mem_released_payload *release_payload;
  766. struct trusted_touch_vm_info *vm_info;
  767. struct qts_data *qts_data;
  768. qts_data = (struct qts_data *)entry_data;
  769. vm_info = qts_data->vm_info;
  770. if (!vm_info) {
  771. pr_err("Invalid vm_info\n");
  772. return;
  773. }
  774. if (notif_type != GH_RM_NOTIF_MEM_RELEASED) {
  775. pr_err("Invalid notification type\n");
  776. return;
  777. }
  778. if (tag != vm_info->mem_tag) {
  779. pr_err("Invalid tag\n");
  780. return;
  781. }
  782. if (!entry_data || !notif_msg) {
  783. pr_err("Invalid data or notification message\n");
  784. return;
  785. }
  786. release_payload = (struct gh_rm_notif_mem_released_payload *)notif_msg;
  787. if (release_payload->mem_handle != vm_info->vm_mem_handle) {
  788. pr_err("Invalid mem handle detected\n");
  789. return;
  790. }
  791. if (qts_trusted_touch_get_vm_state(qts_data) == PVM_IRQ_RELEASE_NOTIFIED)
  792. qts_trusted_touch_set_vm_state(qts_data, PVM_ALL_RESOURCES_RELEASE_NOTIFIED);
  793. else
  794. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_RELEASE_NOTIFIED);
  795. }
  796. static int qts_vm_mem_lend(struct qts_data *qts_data)
  797. {
  798. struct gh_acl_desc *acl_desc;
  799. struct gh_sgl_desc *sgl_desc;
  800. struct gh_notify_vmid_desc *vmid_desc;
  801. gh_memparcel_handle_t mem_handle;
  802. gh_vmid_t trusted_vmid;
  803. int rc = 0;
  804. acl_desc = qts_vm_get_acl(GH_TRUSTED_VM);
  805. if (IS_ERR(acl_desc)) {
  806. pr_err("Failed to get acl of IO memories for Trusted touch\n");
  807. rc = PTR_ERR(acl_desc);
  808. return rc;
  809. }
  810. sgl_desc = qts_vm_get_sgl(qts_data->vm_info);
  811. if (IS_ERR(sgl_desc)) {
  812. pr_err("Failed to get sgl of IO memories for Trusted touch\n");
  813. rc = PTR_ERR(sgl_desc);
  814. goto sgl_error;
  815. }
  816. rc = gh_rm_mem_lend(GH_RM_MEM_TYPE_IO, 0, TRUSTED_TOUCH_MEM_LABEL,
  817. acl_desc, sgl_desc, NULL, &mem_handle);
  818. if (rc) {
  819. pr_err("Failed to lend IO memories for Trusted touch rc:%d\n", rc);
  820. goto error;
  821. }
  822. pr_debug("vm mem lend success\n");
  823. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_LENT);
  824. gh_rm_get_vmid(GH_TRUSTED_VM, &trusted_vmid);
  825. vmid_desc = qts_vm_get_vmid(trusted_vmid);
  826. rc = gh_rm_mem_notify(mem_handle, GH_RM_MEM_NOTIFY_RECIPIENT_SHARED,
  827. qts_data->vm_info->mem_tag, vmid_desc);
  828. if (rc) {
  829. pr_err("Failed to notify mem lend to hypervisor rc:%d\n", rc);
  830. goto vmid_error;
  831. }
  832. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_LENT_NOTIFIED);
  833. qts_data->vm_info->vm_mem_handle = mem_handle;
  834. vmid_error:
  835. kfree(vmid_desc);
  836. error:
  837. kfree(sgl_desc);
  838. sgl_error:
  839. kfree(acl_desc);
  840. return rc;
  841. }
  842. static int qts_trusted_touch_pvm_vm_mode_enable(struct qts_data *qts_data)
  843. {
  844. int rc = 0;
  845. struct trusted_touch_vm_info *vm_info = qts_data->vm_info;
  846. atomic_set(&qts_data->trusted_touch_transition, 1);
  847. mutex_lock(&qts_data->transition_lock);
  848. if (qts_data->suspended) {
  849. pr_err("Invalid power state for operation\n");
  850. atomic_set(&qts_data->trusted_touch_transition, 0);
  851. rc = -EPERM;
  852. goto error;
  853. }
  854. if (qts_data->vendor_ops.pre_la_tui_enable)
  855. qts_data->vendor_ops.pre_la_tui_enable(qts_data->vendor_data);
  856. /* i2c session start and resource acquire */
  857. if (qts_bus_get(qts_data) < 0) {
  858. pr_err("qts_bus_get failed\n");
  859. rc = -EIO;
  860. goto error;
  861. }
  862. qts_trusted_touch_set_vm_state(qts_data, PVM_I2C_RESOURCE_ACQUIRED);
  863. if (qts_data->vendor_ops.enable_touch_irq)
  864. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, false);
  865. qts_trusted_touch_set_vm_state(qts_data, PVM_INTERRUPT_DISABLED);
  866. rc = qts_vm_mem_lend(qts_data);
  867. if (rc) {
  868. pr_err("Failed to lend memory\n");
  869. goto abort_handler;
  870. }
  871. pr_debug("vm mem lend success\n");
  872. if (atomic_read(&qts_data->delayed_pvm_probe_pending)) {
  873. if (qts_data->vendor_ops.get_irq_num)
  874. qts_data->irq = qts_data->vendor_ops.get_irq_num(qts_data->vendor_data);
  875. atomic_set(&qts_data->delayed_tvm_probe_pending, 0);
  876. }
  877. rc = gh_irq_lend_v2(vm_info->irq_label, vm_info->vm_name,
  878. qts_data->irq, &qts_vm_irq_on_release_callback, qts_data);
  879. if (rc) {
  880. pr_err("Failed to lend irq\n");
  881. goto abort_handler;
  882. }
  883. pr_debug("vm irq lend success for irq:%d\n", qts_data->irq);
  884. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_LENT);
  885. rc = gh_irq_lend_notify(vm_info->irq_label);
  886. if (rc) {
  887. pr_err("Failed to notify irq\n");
  888. goto abort_handler;
  889. }
  890. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_LENT_NOTIFIED);
  891. if (qts_data->vendor_ops.post_la_tui_enable)
  892. qts_data->vendor_ops.post_la_tui_enable(qts_data->vendor_data);
  893. mutex_unlock(&qts_data->transition_lock);
  894. atomic_set(&qts_data->trusted_touch_transition, 0);
  895. atomic_set(&qts_data->trusted_touch_enabled, 1);
  896. pr_debug("trusted touch enabled\n");
  897. return rc;
  898. abort_handler:
  899. qts_trusted_touch_abort_handler(qts_data, TRUSTED_TOUCH_EVENT_LEND_FAILURE);
  900. error:
  901. mutex_unlock(&qts_data->transition_lock);
  902. return rc;
  903. }
  904. static int qts_handle_trusted_touch_pvm(struct qts_data *qts_data, int value)
  905. {
  906. int err = 0;
  907. switch (value) {
  908. case 0:
  909. if (atomic_read(&qts_data->trusted_touch_enabled) == 0 &&
  910. (atomic_read(&qts_data->trusted_touch_abort_status) == 0)) {
  911. pr_err("Trusted touch is already disabled\n");
  912. break;
  913. }
  914. if (atomic_read(&qts_data->trusted_touch_mode) ==
  915. TRUSTED_TOUCH_VM_MODE) {
  916. qts_trusted_touch_pvm_vm_mode_disable(qts_data);
  917. } else {
  918. pr_err("Unsupported trusted touch mode\n");
  919. }
  920. break;
  921. case 1:
  922. if (atomic_read(&qts_data->trusted_touch_enabled)) {
  923. pr_err("Trusted touch usecase underway\n");
  924. err = -EBUSY;
  925. break;
  926. }
  927. if (atomic_read(&qts_data->trusted_touch_mode) ==
  928. TRUSTED_TOUCH_VM_MODE) {
  929. err = qts_trusted_touch_pvm_vm_mode_enable(qts_data);
  930. } else {
  931. pr_err("Unsupported trusted touch mode\n");
  932. }
  933. break;
  934. default:
  935. pr_err("unsupported value: %lu\n", value);
  936. err = -EINVAL;
  937. break;
  938. }
  939. return err;
  940. }
  941. #endif
  942. static void qts_trusted_touch_event_notify(struct qts_data *qts_data, int event)
  943. {
  944. atomic_set(&qts_data->trusted_touch_event, event);
  945. sysfs_notify(&qts_data->dev->kobj, NULL, "trusted_touch_event");
  946. }
  947. static void qts_trusted_touch_abort_handler(struct qts_data *qts_data, int error)
  948. {
  949. atomic_set(&qts_data->trusted_touch_abort_status, error);
  950. pr_info("TUI session aborted with failure:%d\n", error);
  951. qts_trusted_touch_event_notify(qts_data, error);
  952. #ifdef CONFIG_ARCH_QTI_VM
  953. pr_info("Resetting touch controller\n");
  954. if (qts_trusted_touch_get_vm_state(qts_data) >= TVM_IOMEM_ACCEPTED &&
  955. error == TRUSTED_TOUCH_EVENT_I2C_FAILURE) {
  956. pr_info("Resetting touch controller\n");
  957. qts_trusted_touch_reset_gpio_toggle(qts_data);
  958. }
  959. #endif
  960. }
  961. static int qts_vm_init(struct qts_data *qts_data)
  962. {
  963. int rc = 0;
  964. struct trusted_touch_vm_info *vm_info;
  965. void *mem_cookie;
  966. rc = qts_populate_vm_info(qts_data);
  967. if (rc) {
  968. pr_err("Cannot setup vm pipeline\n");
  969. rc = -EINVAL;
  970. goto fail;
  971. }
  972. vm_info = qts_data->vm_info;
  973. #ifdef CONFIG_ARCH_QTI_VM
  974. mem_cookie = gh_mem_notifier_register(vm_info->mem_tag,
  975. qts_vm_mem_on_lend_handler, qts_data);
  976. if (!mem_cookie) {
  977. pr_err("Failed to register on lend mem notifier\n");
  978. rc = -EINVAL;
  979. goto init_fail;
  980. }
  981. vm_info->mem_cookie = mem_cookie;
  982. rc = gh_irq_wait_for_lend_v2(vm_info->irq_label, GH_PRIMARY_VM,
  983. &qts_vm_irq_on_lend_callback, qts_data);
  984. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_TVM_INIT);
  985. #else
  986. mem_cookie = gh_mem_notifier_register(vm_info->mem_tag,
  987. qts_vm_mem_on_release_handler, qts_data);
  988. if (!mem_cookie) {
  989. pr_err("Failed to register on release mem notifier\n");
  990. rc = -EINVAL;
  991. goto init_fail;
  992. }
  993. vm_info->mem_cookie = mem_cookie;
  994. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  995. #endif
  996. return rc;
  997. init_fail:
  998. qts_vm_deinit(qts_data);
  999. fail:
  1000. return rc;
  1001. }
  1002. static void qts_dt_parse_trusted_touch_info(struct qts_data *qts_data)
  1003. {
  1004. struct device_node *np = qts_data->dev->of_node;
  1005. int rc = 0;
  1006. const char *selection;
  1007. const char *environment;
  1008. rc = of_property_read_string(np, "qts,trusted-touch-mode", &selection);
  1009. if (rc) {
  1010. pr_err("No trusted touch mode selection made\n");
  1011. atomic_set(&qts_data->trusted_touch_mode,
  1012. TRUSTED_TOUCH_MODE_NONE);
  1013. return;
  1014. }
  1015. if (!strcmp(selection, "vm_mode")) {
  1016. atomic_set(&qts_data->trusted_touch_mode,
  1017. TRUSTED_TOUCH_VM_MODE);
  1018. pr_debug("Selected trusted touch mode to VM mode\n");
  1019. } else {
  1020. atomic_set(&qts_data->trusted_touch_mode,
  1021. TRUSTED_TOUCH_MODE_NONE);
  1022. pr_err("Invalid trusted_touch mode\n");
  1023. }
  1024. rc = of_property_read_string(np, "qts,touch-environment",
  1025. &environment);
  1026. if (rc)
  1027. pr_err("No trusted touch mode environment\n");
  1028. qts_data->touch_environment = environment;
  1029. qts_data->tui_supported = true;
  1030. pr_debug("Trusted touch environment:%s\n", qts_data->touch_environment);
  1031. }
  1032. static void qts_trusted_touch_init(struct qts_data *qts_data)
  1033. {
  1034. int rc = 0;
  1035. atomic_set(&qts_data->trusted_touch_initialized, 0);
  1036. qts_dt_parse_trusted_touch_info(qts_data);
  1037. if (atomic_read(&qts_data->trusted_touch_mode) == TRUSTED_TOUCH_MODE_NONE)
  1038. return;
  1039. init_completion(&qts_data->trusted_touch_powerdown);
  1040. /* Get clocks */
  1041. qts_data->core_clk = devm_clk_get(qts_data->dev->parent, "m-ahb");
  1042. if (IS_ERR(qts_data->core_clk)) {
  1043. qts_data->core_clk = NULL;
  1044. pr_err("core_clk is not defined\n");
  1045. }
  1046. qts_data->iface_clk = devm_clk_get(qts_data->dev->parent, "se-clk");
  1047. if (IS_ERR(qts_data->iface_clk)) {
  1048. qts_data->iface_clk = NULL;
  1049. pr_err("iface_clk is not defined\n");
  1050. }
  1051. if (atomic_read(&qts_data->trusted_touch_mode) ==
  1052. TRUSTED_TOUCH_VM_MODE) {
  1053. rc = qts_vm_init(qts_data);
  1054. if (rc)
  1055. pr_err("Failed to init VM\n");
  1056. }
  1057. atomic_set(&qts_data->trusted_touch_initialized, 1);
  1058. }
  1059. static bool qts_ts_is_primary(struct kobject *kobj)
  1060. {
  1061. char *path = NULL;
  1062. if (!kobj)
  1063. return true;
  1064. path = kobject_get_path(kobj, GFP_KERNEL);
  1065. if (strstr(path, "primary"))
  1066. return true;
  1067. else
  1068. return false;
  1069. }
  1070. static ssize_t trusted_touch_enable_show(struct kobject *kobj, struct kobj_attribute *attr,
  1071. char *buf)
  1072. {
  1073. struct qts_data *qts_data;
  1074. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1075. qts_data = &qts_data_entries->info[idx];
  1076. return scnprintf(buf, PAGE_SIZE, "%d",
  1077. atomic_read(&qts_data->trusted_touch_enabled));
  1078. }
  1079. static ssize_t trusted_touch_enable_store(struct kobject *kobj, struct kobj_attribute *attr,
  1080. const char *buf, size_t count)
  1081. {
  1082. struct qts_data *qts_data;
  1083. unsigned long value;
  1084. int err = 0;
  1085. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1086. if (count > 2)
  1087. return -EINVAL;
  1088. err = kstrtoul(buf, 10, &value);
  1089. if (err != 0)
  1090. return err;
  1091. qts_data = &qts_data_entries->info[idx];
  1092. if (!atomic_read(&qts_data->trusted_touch_initialized))
  1093. return -EIO;
  1094. #ifdef CONFIG_ARCH_QTI_VM
  1095. err = qts_handle_trusted_touch_tvm(qts_data, value);
  1096. if (err) {
  1097. pr_err("Failed to handle trusted touch in tvm\n");
  1098. return -EINVAL;
  1099. }
  1100. #else
  1101. err = qts_handle_trusted_touch_pvm(qts_data, value);
  1102. if (err) {
  1103. pr_err("Failed to handle trusted touch in pvm\n");
  1104. return -EINVAL;
  1105. }
  1106. #endif
  1107. err = count;
  1108. return err;
  1109. }
  1110. static ssize_t trusted_touch_event_show(struct kobject *kobj, struct kobj_attribute *attr,
  1111. char *buf)
  1112. {
  1113. struct qts_data *qts_data;
  1114. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1115. qts_data = &qts_data_entries->info[idx];
  1116. return scnprintf(buf, PAGE_SIZE, "%d",
  1117. atomic_read(&qts_data->trusted_touch_event));
  1118. }
  1119. static ssize_t trusted_touch_event_store(struct kobject *kobj, struct kobj_attribute *attr,
  1120. const char *buf, size_t count)
  1121. {
  1122. struct qts_data *qts_data;
  1123. unsigned long value;
  1124. int err = 0;
  1125. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1126. if (count > 2)
  1127. return -EINVAL;
  1128. err = kstrtoul(buf, 10, &value);
  1129. if (err != 0)
  1130. return err;
  1131. qts_data = &qts_data_entries->info[idx];
  1132. if (!atomic_read(&qts_data->trusted_touch_initialized))
  1133. return -EIO;
  1134. if (value)
  1135. return -EIO;
  1136. atomic_set(&qts_data->trusted_touch_event, value);
  1137. return count;
  1138. }
  1139. static ssize_t trusted_touch_type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
  1140. {
  1141. struct qts_data *qts_data;
  1142. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1143. qts_data = &qts_data_entries->info[idx];
  1144. return scnprintf(buf, PAGE_SIZE, "%s", qts_data->vm_info->trusted_touch_type);
  1145. }
  1146. static ssize_t trusted_touch_device_path_show(struct kobject *kobj,
  1147. struct kobj_attribute *attr, char *buf)
  1148. {
  1149. struct qts_data *qts_data;
  1150. char *path = NULL;
  1151. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1152. qts_data = &qts_data_entries->info[idx];
  1153. if (qts_data && qts_data->dev)
  1154. path = kobject_get_path(&qts_data->dev->kobj, GFP_KERNEL);
  1155. return scnprintf(buf, PAGE_SIZE, "%s", path ? path : "");
  1156. }
  1157. static struct kobj_attribute trusted_touch_enable_attr =
  1158. __ATTR(trusted_touch_enable, 0664, trusted_touch_enable_show, trusted_touch_enable_store);
  1159. static struct kobj_attribute trusted_touch_event_attr =
  1160. __ATTR(trusted_touch_event, 0664, trusted_touch_event_show, trusted_touch_event_store);
  1161. static struct kobj_attribute trusted_touch_type_attr =
  1162. __ATTR(trusted_touch_type, 0664, trusted_touch_type_show, NULL);
  1163. static struct kobj_attribute trusted_touch_device_path_attr =
  1164. __ATTR(trusted_touch_device_path, 0444, trusted_touch_device_path_show, NULL);
  1165. static struct attribute *qts_attributes[] = {
  1166. &trusted_touch_enable_attr.attr,
  1167. &trusted_touch_event_attr.attr,
  1168. &trusted_touch_type_attr.attr,
  1169. &trusted_touch_device_path_attr.attr,
  1170. NULL,
  1171. };
  1172. static struct attribute_group qts_attribute_group = {
  1173. .attrs = qts_attributes,
  1174. };
  1175. static int qts_create_sysfs(struct qts_data *qts_data)
  1176. {
  1177. int ret = 0;
  1178. struct kobject *qts_kobj;
  1179. struct kobject *client_kobj;
  1180. qts_kobj = &qts_data_entries->qts_kset->kobj;
  1181. if (qts_data->client_type == QTS_CLIENT_PRIMARY_TOUCH) {
  1182. client_kobj = kobject_create_and_add("primary", qts_kobj);
  1183. if (!client_kobj) {
  1184. pr_err("primary kobject_create_and_add failed\n");
  1185. return -ENOMEM;
  1186. }
  1187. ret = sysfs_create_group(client_kobj, &qts_attribute_group);
  1188. if (ret) {
  1189. pr_err("[EX]: sysfs_create_group() failed!!\n");
  1190. sysfs_remove_group(client_kobj, &qts_attribute_group);
  1191. return -ENOMEM;
  1192. }
  1193. } else if (qts_data->client_type == QTS_CLIENT_SECONDARY_TOUCH) {
  1194. client_kobj = kobject_create_and_add("secondary", qts_kobj);
  1195. if (!client_kobj) {
  1196. pr_err("secondary kobject_create_and_add failed\n");
  1197. return -ENOMEM;
  1198. }
  1199. ret = sysfs_create_group(client_kobj, &qts_attribute_group);
  1200. if (ret) {
  1201. pr_err("[EX]: sysfs_create_group() failed!!\n");
  1202. sysfs_remove_group(client_kobj, &qts_attribute_group);
  1203. return -ENOMEM;
  1204. }
  1205. }
  1206. pr_debug("sysfs_create_group() succeeded\n");
  1207. return ret;
  1208. }
  1209. static int qts_ts_check_dt(struct device_node *np)
  1210. {
  1211. int i;
  1212. int count;
  1213. struct device_node *node;
  1214. struct drm_panel *panel;
  1215. count = of_count_phandle_with_args(np, "panel", NULL);
  1216. if (count <= 0)
  1217. return 0;
  1218. for (i = 0; i < count; i++) {
  1219. node = of_parse_phandle(np, "panel", i);
  1220. panel = of_drm_find_panel(node);
  1221. of_node_put(node);
  1222. if (!IS_ERR(panel)) {
  1223. active_panel = panel;
  1224. return 0;
  1225. }
  1226. }
  1227. return PTR_ERR(panel);
  1228. }
  1229. static void qts_power_source_init(struct qts_data *qts_data)
  1230. {
  1231. qts_data->vdd = regulator_get(qts_data->dev, "vdd");
  1232. if (IS_ERR_OR_NULL(qts_data->vdd))
  1233. pr_debug("get vdd regulator failed\n");
  1234. qts_data->avdd = regulator_get(qts_data->dev, "avdd");
  1235. if (IS_ERR_OR_NULL(qts_data->avdd))
  1236. pr_debug("get avdd regulator failed\n");
  1237. }
  1238. #ifndef CONFIG_ARCH_QTI_VM
  1239. static int qts_enable_reg(struct qts_data *qts_data, bool enable)
  1240. {
  1241. int ret = 0;
  1242. if (IS_ERR_OR_NULL(qts_data->vdd)) {
  1243. pr_err("vdd is invalid\n");
  1244. return ret;
  1245. }
  1246. if (enable) {
  1247. ret = regulator_enable(qts_data->vdd);
  1248. if (ret) {
  1249. pr_err("enable vdd regulator failed,ret=%d\n", ret);
  1250. goto error;
  1251. }
  1252. if (!IS_ERR_OR_NULL(qts_data->avdd)) {
  1253. ret = regulator_enable(qts_data->avdd);
  1254. if (ret) {
  1255. pr_err("enable avdd regulator failed,ret=%d\n", ret);
  1256. goto error_avdd_en;
  1257. }
  1258. }
  1259. } else {
  1260. ret = regulator_disable(qts_data->vdd);
  1261. if (ret)
  1262. pr_err("disable vdd regulator failed,ret=%d\n", ret);
  1263. if (!IS_ERR_OR_NULL(qts_data->avdd)) {
  1264. ret = regulator_disable(qts_data->avdd);
  1265. if (ret)
  1266. pr_err("disable avdd regulator failed,ret=%d\n", ret);
  1267. }
  1268. }
  1269. pr_debug("enable %d completed\n", enable);
  1270. return ret;
  1271. error_avdd_en:
  1272. (void)regulator_disable(qts_data->vdd);
  1273. error:
  1274. return ret;
  1275. }
  1276. #endif
  1277. static void qts_ts_suspend(struct qts_data *qts_data)
  1278. {
  1279. int rc = 0;
  1280. if (qts_data->suspended) {
  1281. pr_warn("already in suspend state\n");
  1282. return;
  1283. }
  1284. if (qts_data->tui_supported) {
  1285. if (atomic_read(&qts_data->trusted_touch_transition)
  1286. || atomic_read(&qts_data->trusted_touch_enabled))
  1287. wait_for_completion_interruptible(&qts_data->trusted_touch_powerdown);
  1288. }
  1289. mutex_lock(&qts_data->transition_lock);
  1290. rc = qts_data->vendor_ops.suspend(qts_data->vendor_data);
  1291. if (rc)
  1292. pr_err("suspend failed, rc = %d\n", rc);
  1293. qts_data->suspended = true;
  1294. mutex_unlock(&qts_data->transition_lock);
  1295. }
  1296. static void qts_ts_resume(struct qts_data *qts_data)
  1297. {
  1298. int rc = 0;
  1299. if (!qts_data->suspended) {
  1300. pr_warn("Already in awake state\n");
  1301. return;
  1302. }
  1303. if (qts_data->tui_supported)
  1304. if (atomic_read(&qts_data->trusted_touch_transition))
  1305. wait_for_completion_interruptible(&qts_data->trusted_touch_powerdown);
  1306. mutex_lock(&qts_data->transition_lock);
  1307. rc = qts_data->vendor_ops.resume(qts_data->vendor_data);
  1308. if (rc)
  1309. pr_err("resume failed, rc = %d\n", rc);
  1310. qts_data->suspended = false;
  1311. mutex_unlock(&qts_data->transition_lock);
  1312. }
  1313. static void qts_resume_work(struct work_struct *work)
  1314. {
  1315. struct qts_data *qts_data = container_of(work, struct qts_data,
  1316. resume_work);
  1317. qts_ts_resume(qts_data);
  1318. }
  1319. static void qts_suspend_work(struct work_struct *work)
  1320. {
  1321. struct qts_data *qts_data = container_of(work, struct qts_data,
  1322. suspend_work);
  1323. qts_ts_suspend(qts_data);
  1324. }
  1325. static void qts_panel_notifier_callback(enum panel_event_notifier_tag tag,
  1326. struct panel_event_notification *notification, void *client_data)
  1327. {
  1328. struct qts_data *qts_data = client_data;
  1329. if (!notification) {
  1330. pr_err("Invalid notification\n");
  1331. return;
  1332. }
  1333. pr_debug("Notification type:%d, early_trigger:%d\n",
  1334. notification->notif_type, notification->notif_data.early_trigger);
  1335. switch (notification->notif_type) {
  1336. case DRM_PANEL_EVENT_UNBLANK:
  1337. if (notification->notif_data.early_trigger) {
  1338. pr_debug("resume notification pre commit\n");
  1339. } else {
  1340. if (qts_data->schedule_resume)
  1341. queue_work(qts_data->ts_workqueue, &qts_data->resume_work);
  1342. else
  1343. qts_ts_resume(qts_data);
  1344. }
  1345. break;
  1346. case DRM_PANEL_EVENT_BLANK:
  1347. if (notification->notif_data.early_trigger) {
  1348. if (qts_data->schedule_resume)
  1349. cancel_work_sync(&qts_data->resume_work);
  1350. if (qts_data->schedule_suspend)
  1351. queue_work(qts_data->ts_workqueue, &qts_data->suspend_work);
  1352. else
  1353. qts_ts_suspend(qts_data);
  1354. } else {
  1355. pr_debug("suspend notification post commit\n");
  1356. }
  1357. break;
  1358. case DRM_PANEL_EVENT_BLANK_LP:
  1359. pr_debug("received lp event\n");
  1360. break;
  1361. case DRM_PANEL_EVENT_FPS_CHANGE:
  1362. pr_debug("Received fps change old fps:%d new fps:%d\n",
  1363. notification->notif_data.old_fps,
  1364. notification->notif_data.new_fps);
  1365. break;
  1366. default:
  1367. pr_debug("notification serviced :%d\n",
  1368. notification->notif_type);
  1369. break;
  1370. }
  1371. }
  1372. static void qts_ts_register_for_panel_events(struct qts_data *qts_data)
  1373. {
  1374. void *cookie = NULL;
  1375. if (qts_data->client_type != QTS_CLIENT_PRIMARY_TOUCH) {
  1376. pr_err("Invalid touch type\n");
  1377. return;
  1378. }
  1379. cookie = panel_event_notifier_register(PANEL_EVENT_NOTIFICATION_PRIMARY,
  1380. PANEL_EVENT_NOTIFIER_CLIENT_PRIMARY_TOUCH, qts_data->panel,
  1381. &qts_panel_notifier_callback, qts_data);
  1382. if (!cookie) {
  1383. pr_err("Failed to register for panel events\n");
  1384. return;
  1385. }
  1386. pr_debug("registered for panel notifications panel: 0x%x\n", qts_data->panel);
  1387. qts_data->notifier_cookie = cookie;
  1388. }
  1389. int qts_client_register(struct qts_vendor_data qts_vendor_data)
  1390. {
  1391. struct qts_data *qts_data;
  1392. struct device_node *dp;
  1393. int rc = 0;
  1394. if (!qts_data_entries) {
  1395. pr_debug("QTS client register\n");
  1396. qts_data_entries = kzalloc(sizeof(*qts_data_entries), GFP_KERNEL);
  1397. if (!qts_data_entries) {
  1398. pr_err("mem allocation failed\n");
  1399. return -EPROBE_DEFER;
  1400. }
  1401. mutex_init(&qts_data_entries->qts_data_entries_lock);
  1402. qts_data_entries->qts_kset = kset_create_and_add("qts", NULL, kernel_kobj);
  1403. if (!qts_data_entries->qts_kset) {
  1404. pr_err("qts kset create failed\n");
  1405. return -ENOMEM;
  1406. }
  1407. }
  1408. mutex_lock(&qts_data_entries->qts_data_entries_lock);
  1409. if (qts_vendor_data.bus_type == QTS_BUS_TYPE_I2C)
  1410. dp = qts_vendor_data.client->dev.of_node;
  1411. else
  1412. dp = qts_vendor_data.spi->dev.of_node;
  1413. rc = qts_ts_check_dt(dp);
  1414. if (rc) {
  1415. pr_debug("qts_ts_check_dt failed, rc = %d\n", rc);
  1416. goto qts_register_end;
  1417. }
  1418. pr_debug("QTS client register starts\n");
  1419. qts_data = &qts_data_entries->info[qts_vendor_data.client_type];
  1420. qts_data->client = qts_vendor_data.client;
  1421. qts_data->spi = qts_vendor_data.spi;
  1422. if (qts_vendor_data.bus_type == QTS_BUS_TYPE_I2C)
  1423. qts_data->dev = &qts_data->client->dev;
  1424. else
  1425. qts_data->dev = &qts_data->spi->dev;
  1426. qts_data->bus_type = qts_vendor_data.bus_type;
  1427. qts_data->client_type = qts_vendor_data.client_type;
  1428. qts_data->dp = dp;
  1429. qts_data->vendor_data = qts_vendor_data.vendor_data;
  1430. qts_data->panel = active_panel;
  1431. qts_data->vendor_ops = qts_vendor_data.qts_vendor_ops;
  1432. qts_data->schedule_suspend = qts_vendor_data.schedule_suspend;
  1433. qts_data->schedule_resume = qts_vendor_data.schedule_resume;
  1434. qts_trusted_touch_init(qts_data);
  1435. mutex_init(&(qts_data->qts_clk_io_ctrl_mutex));
  1436. if (qts_data->tui_supported)
  1437. qts_create_sysfs(qts_data);
  1438. mutex_init(&qts_data->transition_lock);
  1439. #ifdef CONFIG_ARCH_QTI_VM
  1440. atomic_set(&qts_data->delayed_tvm_probe_pending, 1);
  1441. goto qts_register_end;
  1442. #else
  1443. atomic_set(&qts_data->delayed_pvm_probe_pending, 1);
  1444. #endif
  1445. qts_power_source_init(qts_data);
  1446. qts_data->ts_workqueue = create_singlethread_workqueue("qts_wq");
  1447. if (!qts_data->ts_workqueue)
  1448. pr_err("create qts workqueue fail\n");
  1449. if (qts_data->ts_workqueue && qts_data->schedule_resume)
  1450. INIT_WORK(&qts_data->resume_work, qts_resume_work);
  1451. if (qts_data->ts_workqueue && qts_data->schedule_suspend)
  1452. INIT_WORK(&qts_data->suspend_work, qts_suspend_work);
  1453. qts_ts_register_for_panel_events(qts_data);
  1454. qts_register_end:
  1455. pr_debug("client register end\n");
  1456. mutex_unlock(&qts_data_entries->qts_data_entries_lock);
  1457. return rc;
  1458. }
  1459. EXPORT_SYMBOL(qts_client_register);