qts_core.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787
  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("No trusted touch type selection mode\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_info("Irq, iomem are accepted and 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_info("Irq, iomem are released and 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. fallthrough;
  564. case TVM_IRQ_ACCEPTED:
  565. case TVM_INTERRUPT_DISABLED:
  566. rc = gh_irq_release(qts_data->vm_info->irq_label);
  567. if (rc)
  568. pr_err("Failed to release irq rc:%d\n", rc);
  569. rc = gh_irq_release_notify(qts_data->vm_info->irq_label);
  570. if (rc)
  571. pr_err("Failed to notify irq release rc:%d\n", rc);
  572. fallthrough;
  573. case TVM_I2C_SESSION_ACQUIRED:
  574. case TVM_IOMEM_ACCEPTED:
  575. case TVM_IRQ_RELEASED:
  576. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  577. pm_runtime_put_sync(qts_data->client->adapter->dev.parent);
  578. else
  579. pm_runtime_put_sync(qts_data->spi->master->dev.parent);
  580. fallthrough;
  581. case TVM_I2C_SESSION_RELEASED:
  582. rc = qts_vm_mem_release(qts_data);
  583. if (rc)
  584. pr_err("Failed to release mem rc:%d\n", rc);
  585. fallthrough;
  586. case TVM_IOMEM_RELEASED:
  587. case TVM_ALL_RESOURCES_LENT_NOTIFIED:
  588. case TRUSTED_TOUCH_TVM_INIT:
  589. case TVM_IRQ_LENT_NOTIFIED:
  590. case TVM_IOMEM_LENT_NOTIFIED:
  591. atomic_set(&qts_data->trusted_touch_enabled, 0);
  592. }
  593. atomic_set(&qts_data->trusted_touch_abort_status, 0);
  594. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_TVM_INIT);
  595. }
  596. #else
  597. static void qts_bus_put(struct qts_data *qts_data);
  598. static int qts_enable_reg(struct qts_data *qts_data, bool enable);
  599. static void qts_trusted_touch_abort_pvm(struct qts_data *qts_data)
  600. {
  601. int rc = 0;
  602. int vm_state = qts_trusted_touch_get_vm_state(qts_data);
  603. if (vm_state >= TRUSTED_TOUCH_PVM_STATE_MAX) {
  604. pr_err("Invalid driver state: %d\n", vm_state);
  605. return;
  606. }
  607. switch (vm_state) {
  608. case PVM_IRQ_RELEASE_NOTIFIED:
  609. case PVM_ALL_RESOURCES_RELEASE_NOTIFIED:
  610. case PVM_IRQ_LENT:
  611. case PVM_IRQ_LENT_NOTIFIED:
  612. rc = gh_irq_reclaim(qts_data->vm_info->irq_label);
  613. if (rc) {
  614. pr_err("failed to reclaim irq on pvm rc:%d\n", rc);
  615. return;
  616. }
  617. fallthrough;
  618. case PVM_IRQ_RECLAIMED:
  619. case PVM_IOMEM_LENT:
  620. case PVM_IOMEM_LENT_NOTIFIED:
  621. case PVM_IOMEM_RELEASE_NOTIFIED:
  622. rc = gh_rm_mem_reclaim(qts_data->vm_info->vm_mem_handle, 0);
  623. if (rc) {
  624. pr_err("failed to reclaim iomem on pvm rc:%d\n", rc);
  625. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_RELEASE_NOTIFIED);
  626. return;
  627. }
  628. qts_data->vm_info->vm_mem_handle = 0;
  629. fallthrough;
  630. case PVM_IOMEM_RECLAIMED:
  631. case PVM_INTERRUPT_DISABLED:
  632. if (qts_data->vendor_ops.enable_touch_irq)
  633. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, true);
  634. fallthrough;
  635. case PVM_I2C_RESOURCE_ACQUIRED:
  636. case PVM_INTERRUPT_ENABLED:
  637. qts_bus_put(qts_data);
  638. fallthrough;
  639. case TRUSTED_TOUCH_PVM_INIT:
  640. case PVM_I2C_RESOURCE_RELEASED:
  641. atomic_set(&qts_data->trusted_touch_enabled, 0);
  642. atomic_set(&qts_data->trusted_touch_transition, 0);
  643. }
  644. atomic_set(&qts_data->trusted_touch_abort_status, 0);
  645. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  646. }
  647. static int qts_clk_prepare_enable(struct qts_data *qts_data)
  648. {
  649. int ret;
  650. ret = clk_prepare_enable(qts_data->iface_clk);
  651. if (ret) {
  652. pr_err("error on clk_prepare_enable(iface_clk):%d\n", ret);
  653. return ret;
  654. }
  655. ret = clk_prepare_enable(qts_data->core_clk);
  656. if (ret) {
  657. clk_disable_unprepare(qts_data->iface_clk);
  658. pr_err("error clk_prepare_enable(core_clk):%d\n", ret);
  659. }
  660. return ret;
  661. }
  662. static void qts_clk_disable_unprepare(struct qts_data *qts_data)
  663. {
  664. clk_disable_unprepare(qts_data->core_clk);
  665. clk_disable_unprepare(qts_data->iface_clk);
  666. }
  667. static int qts_bus_get(struct qts_data *qts_data)
  668. {
  669. int rc = 0;
  670. struct device *dev = NULL;
  671. if (qts_data->schedule_suspend)
  672. cancel_work_sync(&qts_data->suspend_work);
  673. if (qts_data->schedule_resume)
  674. cancel_work_sync(&qts_data->resume_work);
  675. reinit_completion(&qts_data->trusted_touch_powerdown);
  676. qts_enable_reg(qts_data, true);
  677. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  678. dev = qts_data->client->adapter->dev.parent;
  679. else
  680. dev = qts_data->spi->master->dev.parent;
  681. mutex_lock(&qts_data->qts_clk_io_ctrl_mutex);
  682. rc = pm_runtime_get_sync(dev);
  683. if (rc >= 0 && qts_data->core_clk != NULL &&
  684. qts_data->iface_clk != NULL) {
  685. rc = qts_clk_prepare_enable(qts_data);
  686. if (rc)
  687. pm_runtime_put_sync(dev);
  688. }
  689. mutex_unlock(&qts_data->qts_clk_io_ctrl_mutex);
  690. return rc;
  691. }
  692. static void qts_bus_put(struct qts_data *qts_data)
  693. {
  694. struct device *dev = NULL;
  695. if (qts_data->bus_type == QTS_BUS_TYPE_I2C)
  696. dev = qts_data->client->adapter->dev.parent;
  697. else
  698. dev = qts_data->spi->master->dev.parent;
  699. mutex_lock(&qts_data->qts_clk_io_ctrl_mutex);
  700. if (qts_data->core_clk != NULL && qts_data->iface_clk != NULL)
  701. qts_clk_disable_unprepare(qts_data);
  702. pm_runtime_put_sync(dev);
  703. mutex_unlock(&qts_data->qts_clk_io_ctrl_mutex);
  704. complete(&qts_data->trusted_touch_powerdown);
  705. qts_enable_reg(qts_data, false);
  706. }
  707. static struct gh_notify_vmid_desc *qts_vm_get_vmid(gh_vmid_t vmid)
  708. {
  709. struct gh_notify_vmid_desc *vmid_desc;
  710. vmid_desc = kzalloc(offsetof(struct gh_notify_vmid_desc,
  711. vmid_entries[1]), GFP_KERNEL);
  712. if (!vmid_desc)
  713. return ERR_PTR(ENOMEM);
  714. vmid_desc->n_vmid_entries = 1;
  715. vmid_desc->vmid_entries[0].vmid = vmid;
  716. return vmid_desc;
  717. }
  718. static void qts_trusted_touch_pvm_vm_mode_disable(struct qts_data *qts_data)
  719. {
  720. int rc = 0;
  721. atomic_set(&qts_data->trusted_touch_transition, 1);
  722. if (atomic_read(&qts_data->trusted_touch_abort_status)) {
  723. qts_trusted_touch_abort_pvm(qts_data);
  724. return;
  725. }
  726. if (qts_trusted_touch_get_vm_state(qts_data) != PVM_ALL_RESOURCES_RELEASE_NOTIFIED)
  727. pr_info("all release notifications are not received yet\n");
  728. if (qts_data->vendor_ops.pre_la_tui_disable)
  729. qts_data->vendor_ops.pre_la_tui_disable(qts_data->vendor_data);
  730. rc = gh_rm_mem_reclaim(qts_data->vm_info->vm_mem_handle, 0);
  731. if (rc) {
  732. pr_err("Trusted touch VM mem reclaim failed rc:%d\n", rc);
  733. goto error;
  734. }
  735. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_RECLAIMED);
  736. qts_data->vm_info->vm_mem_handle = 0;
  737. pr_debug("vm mem reclaim success!\n");
  738. rc = gh_irq_reclaim(qts_data->vm_info->irq_label);
  739. if (rc) {
  740. pr_err("failed to reclaim irq on pvm rc:%d\n", rc);
  741. goto error;
  742. }
  743. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_RECLAIMED);
  744. pr_debug("vm irq reclaim success!\n");
  745. if (qts_data->vendor_ops.enable_touch_irq)
  746. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, true);
  747. qts_trusted_touch_set_vm_state(qts_data, PVM_INTERRUPT_ENABLED);
  748. qts_bus_put(qts_data);
  749. atomic_set(&qts_data->trusted_touch_transition, 0);
  750. qts_trusted_touch_set_vm_state(qts_data, PVM_I2C_RESOURCE_RELEASED);
  751. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  752. atomic_set(&qts_data->trusted_touch_enabled, 0);
  753. if (qts_data->vendor_ops.post_la_tui_disable)
  754. qts_data->vendor_ops.post_la_tui_disable(qts_data->vendor_data);
  755. pr_info("Irq, iomem are reclaimed and trusted touch disabled\n");
  756. return;
  757. error:
  758. qts_trusted_touch_abort_handler(qts_data,
  759. TRUSTED_TOUCH_EVENT_RECLAIM_FAILURE);
  760. }
  761. static void qts_vm_irq_on_release_callback(void *data,
  762. unsigned long notif_type,
  763. enum gh_irq_label label)
  764. {
  765. struct qts_data *qts_data = data;
  766. if (notif_type != GH_RM_NOTIF_VM_IRQ_RELEASED) {
  767. pr_err("invalid notification type\n");
  768. return;
  769. }
  770. if (qts_trusted_touch_get_vm_state(qts_data) == PVM_IOMEM_RELEASE_NOTIFIED)
  771. qts_trusted_touch_set_vm_state(qts_data, PVM_ALL_RESOURCES_RELEASE_NOTIFIED);
  772. else
  773. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_RELEASE_NOTIFIED);
  774. }
  775. static void qts_vm_mem_on_release_handler(enum gh_mem_notifier_tag tag,
  776. unsigned long notif_type, void *entry_data, void *notif_msg)
  777. {
  778. struct gh_rm_notif_mem_released_payload *release_payload;
  779. struct trusted_touch_vm_info *vm_info;
  780. struct qts_data *qts_data;
  781. qts_data = (struct qts_data *)entry_data;
  782. vm_info = qts_data->vm_info;
  783. if (!vm_info) {
  784. pr_err("Invalid vm_info\n");
  785. return;
  786. }
  787. if (notif_type != GH_RM_NOTIF_MEM_RELEASED) {
  788. pr_err("Invalid notification type\n");
  789. return;
  790. }
  791. if (tag != vm_info->mem_tag) {
  792. pr_err("Invalid tag\n");
  793. return;
  794. }
  795. if (!entry_data || !notif_msg) {
  796. pr_err("Invalid data or notification message\n");
  797. return;
  798. }
  799. release_payload = (struct gh_rm_notif_mem_released_payload *)notif_msg;
  800. if (release_payload->mem_handle != vm_info->vm_mem_handle) {
  801. pr_err("Invalid mem handle detected\n");
  802. return;
  803. }
  804. if (qts_trusted_touch_get_vm_state(qts_data) == PVM_IRQ_RELEASE_NOTIFIED)
  805. qts_trusted_touch_set_vm_state(qts_data, PVM_ALL_RESOURCES_RELEASE_NOTIFIED);
  806. else
  807. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_RELEASE_NOTIFIED);
  808. }
  809. static int qts_vm_mem_lend(struct qts_data *qts_data)
  810. {
  811. struct gh_acl_desc *acl_desc;
  812. struct gh_sgl_desc *sgl_desc;
  813. struct gh_notify_vmid_desc *vmid_desc;
  814. gh_memparcel_handle_t mem_handle;
  815. gh_vmid_t trusted_vmid;
  816. int rc = 0;
  817. acl_desc = qts_vm_get_acl(GH_TRUSTED_VM);
  818. if (IS_ERR(acl_desc)) {
  819. pr_err("Failed to get acl of IO memories for Trusted touch\n");
  820. rc = PTR_ERR(acl_desc);
  821. return rc;
  822. }
  823. sgl_desc = qts_vm_get_sgl(qts_data->vm_info);
  824. if (IS_ERR(sgl_desc)) {
  825. pr_err("Failed to get sgl of IO memories for Trusted touch\n");
  826. rc = PTR_ERR(sgl_desc);
  827. goto sgl_error;
  828. }
  829. rc = gh_rm_mem_lend(GH_RM_MEM_TYPE_IO, 0, TRUSTED_TOUCH_MEM_LABEL,
  830. acl_desc, sgl_desc, NULL, &mem_handle);
  831. if (rc) {
  832. pr_err("Failed to lend IO memories for Trusted touch rc:%d\n", rc);
  833. goto error;
  834. }
  835. pr_debug("vm mem lend success\n");
  836. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_LENT);
  837. gh_rm_get_vmid(GH_TRUSTED_VM, &trusted_vmid);
  838. vmid_desc = qts_vm_get_vmid(trusted_vmid);
  839. rc = gh_rm_mem_notify(mem_handle, GH_RM_MEM_NOTIFY_RECIPIENT_SHARED,
  840. qts_data->vm_info->mem_tag, vmid_desc);
  841. if (rc) {
  842. pr_err("Failed to notify mem lend to hypervisor rc:%d\n", rc);
  843. goto vmid_error;
  844. }
  845. qts_trusted_touch_set_vm_state(qts_data, PVM_IOMEM_LENT_NOTIFIED);
  846. qts_data->vm_info->vm_mem_handle = mem_handle;
  847. vmid_error:
  848. kfree(vmid_desc);
  849. error:
  850. kfree(sgl_desc);
  851. sgl_error:
  852. kfree(acl_desc);
  853. return rc;
  854. }
  855. static int qts_trusted_touch_pvm_vm_mode_enable(struct qts_data *qts_data)
  856. {
  857. int rc = 0;
  858. struct trusted_touch_vm_info *vm_info = qts_data->vm_info;
  859. atomic_set(&qts_data->trusted_touch_transition, 1);
  860. mutex_lock(&qts_data->transition_lock);
  861. if (qts_data->suspended) {
  862. pr_err("Invalid power state for operation\n");
  863. atomic_set(&qts_data->trusted_touch_transition, 0);
  864. rc = -EPERM;
  865. goto error;
  866. }
  867. if (qts_data->vendor_ops.pre_la_tui_enable)
  868. qts_data->vendor_ops.pre_la_tui_enable(qts_data->vendor_data);
  869. /* i2c session start and resource acquire */
  870. if (qts_bus_get(qts_data) < 0) {
  871. pr_err("qts_bus_get failed\n");
  872. rc = -EIO;
  873. goto error;
  874. }
  875. qts_trusted_touch_set_vm_state(qts_data, PVM_I2C_RESOURCE_ACQUIRED);
  876. if (qts_data->vendor_ops.enable_touch_irq)
  877. qts_data->vendor_ops.enable_touch_irq(qts_data->vendor_data, false);
  878. qts_trusted_touch_set_vm_state(qts_data, PVM_INTERRUPT_DISABLED);
  879. rc = qts_vm_mem_lend(qts_data);
  880. if (rc) {
  881. pr_err("Failed to lend memory\n");
  882. goto abort_handler;
  883. }
  884. pr_debug("vm mem lend success\n");
  885. if (atomic_read(&qts_data->delayed_pvm_probe_pending)) {
  886. if (qts_data->vendor_ops.get_irq_num)
  887. qts_data->irq = qts_data->vendor_ops.get_irq_num(qts_data->vendor_data);
  888. atomic_set(&qts_data->delayed_tvm_probe_pending, 0);
  889. }
  890. rc = gh_irq_lend_v2(vm_info->irq_label, vm_info->vm_name,
  891. qts_data->irq, &qts_vm_irq_on_release_callback, qts_data);
  892. if (rc) {
  893. pr_err("Failed to lend irq\n");
  894. goto abort_handler;
  895. }
  896. pr_debug("vm irq lend success for irq:%d\n", qts_data->irq);
  897. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_LENT);
  898. rc = gh_irq_lend_notify(vm_info->irq_label);
  899. if (rc) {
  900. pr_err("Failed to notify irq\n");
  901. goto abort_handler;
  902. }
  903. qts_trusted_touch_set_vm_state(qts_data, PVM_IRQ_LENT_NOTIFIED);
  904. if (qts_data->vendor_ops.post_la_tui_enable)
  905. qts_data->vendor_ops.post_la_tui_enable(qts_data->vendor_data);
  906. mutex_unlock(&qts_data->transition_lock);
  907. atomic_set(&qts_data->trusted_touch_transition, 0);
  908. atomic_set(&qts_data->trusted_touch_enabled, 1);
  909. pr_info("Irq, iomem are lent and trusted touch enabled\n");
  910. return rc;
  911. abort_handler:
  912. qts_trusted_touch_abort_handler(qts_data, TRUSTED_TOUCH_EVENT_LEND_FAILURE);
  913. error:
  914. mutex_unlock(&qts_data->transition_lock);
  915. return rc;
  916. }
  917. static int qts_handle_trusted_touch_pvm(struct qts_data *qts_data, int value)
  918. {
  919. int err = 0;
  920. switch (value) {
  921. case 0:
  922. if (atomic_read(&qts_data->trusted_touch_enabled) == 0 &&
  923. (atomic_read(&qts_data->trusted_touch_abort_status) == 0)) {
  924. pr_err("Trusted touch is already disabled\n");
  925. break;
  926. }
  927. if (atomic_read(&qts_data->trusted_touch_mode) ==
  928. TRUSTED_TOUCH_VM_MODE) {
  929. qts_trusted_touch_pvm_vm_mode_disable(qts_data);
  930. } else {
  931. pr_err("Unsupported trusted touch mode\n");
  932. }
  933. break;
  934. case 1:
  935. if (atomic_read(&qts_data->trusted_touch_enabled)) {
  936. pr_err("Trusted touch usecase underway\n");
  937. err = -EBUSY;
  938. break;
  939. }
  940. if (atomic_read(&qts_data->trusted_touch_mode) ==
  941. TRUSTED_TOUCH_VM_MODE) {
  942. err = qts_trusted_touch_pvm_vm_mode_enable(qts_data);
  943. } else {
  944. pr_err("Unsupported trusted touch mode\n");
  945. }
  946. break;
  947. default:
  948. pr_err("unsupported value: %lu\n", value);
  949. err = -EINVAL;
  950. break;
  951. }
  952. return err;
  953. }
  954. #endif
  955. static void qts_trusted_touch_event_notify(struct qts_data *qts_data, int event)
  956. {
  957. atomic_set(&qts_data->trusted_touch_event, event);
  958. sysfs_notify(&qts_data->dev->kobj, NULL, "trusted_touch_event");
  959. }
  960. static void qts_trusted_touch_abort_handler(struct qts_data *qts_data, int error)
  961. {
  962. atomic_set(&qts_data->trusted_touch_abort_status, error);
  963. pr_info("TUI session aborted with failure:%d\n", error);
  964. qts_trusted_touch_event_notify(qts_data, error);
  965. #ifdef CONFIG_ARCH_QTI_VM
  966. pr_info("Resetting touch controller\n");
  967. if (qts_trusted_touch_get_vm_state(qts_data) >= TVM_IOMEM_ACCEPTED &&
  968. error == TRUSTED_TOUCH_EVENT_I2C_FAILURE) {
  969. pr_info("Resetting touch controller\n");
  970. qts_trusted_touch_reset_gpio_toggle(qts_data);
  971. }
  972. #endif
  973. }
  974. static int qts_vm_init(struct qts_data *qts_data)
  975. {
  976. int rc = 0;
  977. struct trusted_touch_vm_info *vm_info;
  978. void *mem_cookie;
  979. rc = qts_populate_vm_info(qts_data);
  980. if (rc) {
  981. pr_err("Cannot setup vm pipeline\n");
  982. rc = -EINVAL;
  983. goto fail;
  984. }
  985. vm_info = qts_data->vm_info;
  986. #ifdef CONFIG_ARCH_QTI_VM
  987. mem_cookie = gh_mem_notifier_register(vm_info->mem_tag,
  988. qts_vm_mem_on_lend_handler, qts_data);
  989. if (!mem_cookie) {
  990. pr_err("Failed to register on lend mem notifier\n");
  991. rc = -EINVAL;
  992. goto init_fail;
  993. }
  994. vm_info->mem_cookie = mem_cookie;
  995. rc = gh_irq_wait_for_lend_v2(vm_info->irq_label, GH_PRIMARY_VM,
  996. &qts_vm_irq_on_lend_callback, qts_data);
  997. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_TVM_INIT);
  998. #else
  999. mem_cookie = gh_mem_notifier_register(vm_info->mem_tag,
  1000. qts_vm_mem_on_release_handler, qts_data);
  1001. if (!mem_cookie) {
  1002. pr_err("Failed to register on release mem notifier\n");
  1003. rc = -EINVAL;
  1004. goto init_fail;
  1005. }
  1006. vm_info->mem_cookie = mem_cookie;
  1007. qts_trusted_touch_set_vm_state(qts_data, TRUSTED_TOUCH_PVM_INIT);
  1008. #endif
  1009. return rc;
  1010. init_fail:
  1011. qts_vm_deinit(qts_data);
  1012. fail:
  1013. return rc;
  1014. }
  1015. static void qts_dt_parse_trusted_touch_info(struct qts_data *qts_data)
  1016. {
  1017. struct device_node *np = qts_data->dev->of_node;
  1018. int rc = 0;
  1019. const char *selection;
  1020. const char *environment;
  1021. rc = of_property_read_string(np, "qts,trusted-touch-mode", &selection);
  1022. if (rc) {
  1023. pr_err("No trusted touch mode selection made\n");
  1024. atomic_set(&qts_data->trusted_touch_mode,
  1025. TRUSTED_TOUCH_MODE_NONE);
  1026. return;
  1027. }
  1028. if (!strcmp(selection, "vm_mode")) {
  1029. atomic_set(&qts_data->trusted_touch_mode,
  1030. TRUSTED_TOUCH_VM_MODE);
  1031. pr_debug("Selected trusted touch mode to VM mode\n");
  1032. } else {
  1033. atomic_set(&qts_data->trusted_touch_mode,
  1034. TRUSTED_TOUCH_MODE_NONE);
  1035. pr_err("Invalid trusted_touch mode\n");
  1036. }
  1037. rc = of_property_read_string(np, "qts,touch-environment",
  1038. &environment);
  1039. if (rc)
  1040. pr_err("No trusted touch mode environment\n");
  1041. qts_data->touch_environment = environment;
  1042. qts_data->tui_supported = true;
  1043. pr_debug("Trusted touch environment:%s\n", qts_data->touch_environment);
  1044. }
  1045. static void qts_trusted_touch_init(struct qts_data *qts_data)
  1046. {
  1047. int rc = 0;
  1048. atomic_set(&qts_data->trusted_touch_initialized, 0);
  1049. qts_dt_parse_trusted_touch_info(qts_data);
  1050. if (atomic_read(&qts_data->trusted_touch_mode) == TRUSTED_TOUCH_MODE_NONE)
  1051. return;
  1052. init_completion(&qts_data->trusted_touch_powerdown);
  1053. /* Get clocks */
  1054. qts_data->core_clk = devm_clk_get(qts_data->dev->parent, "m-ahb");
  1055. if (IS_ERR(qts_data->core_clk)) {
  1056. qts_data->core_clk = NULL;
  1057. pr_err("core_clk is not defined\n");
  1058. }
  1059. qts_data->iface_clk = devm_clk_get(qts_data->dev->parent, "se-clk");
  1060. if (IS_ERR(qts_data->iface_clk)) {
  1061. qts_data->iface_clk = NULL;
  1062. pr_err("iface_clk is not defined\n");
  1063. }
  1064. if (atomic_read(&qts_data->trusted_touch_mode) ==
  1065. TRUSTED_TOUCH_VM_MODE) {
  1066. rc = qts_vm_init(qts_data);
  1067. if (rc)
  1068. pr_err("Failed to init VM\n");
  1069. }
  1070. atomic_set(&qts_data->trusted_touch_initialized, 1);
  1071. }
  1072. static bool qts_ts_is_primary(struct kobject *kobj)
  1073. {
  1074. char *path = NULL;
  1075. if (!kobj)
  1076. return true;
  1077. path = kobject_get_path(kobj, GFP_KERNEL);
  1078. if (strstr(path, "primary"))
  1079. return true;
  1080. else
  1081. return false;
  1082. }
  1083. static ssize_t trusted_touch_enable_show(struct kobject *kobj, struct kobj_attribute *attr,
  1084. char *buf)
  1085. {
  1086. struct qts_data *qts_data;
  1087. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1088. qts_data = &qts_data_entries->info[idx];
  1089. return scnprintf(buf, PAGE_SIZE, "%d",
  1090. atomic_read(&qts_data->trusted_touch_enabled));
  1091. }
  1092. static ssize_t trusted_touch_enable_store(struct kobject *kobj, struct kobj_attribute *attr,
  1093. const char *buf, size_t count)
  1094. {
  1095. struct qts_data *qts_data;
  1096. unsigned long value;
  1097. int err = 0;
  1098. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1099. if (count > 2)
  1100. return -EINVAL;
  1101. err = kstrtoul(buf, 10, &value);
  1102. if (err != 0)
  1103. return err;
  1104. qts_data = &qts_data_entries->info[idx];
  1105. if (!atomic_read(&qts_data->trusted_touch_initialized))
  1106. return -EIO;
  1107. pr_info("TUI trusted_touch_enable:%d\n", value);
  1108. #ifdef CONFIG_ARCH_QTI_VM
  1109. err = qts_handle_trusted_touch_tvm(qts_data, value);
  1110. if (err) {
  1111. pr_err("Failed to handle trusted touch in tvm\n");
  1112. return -EINVAL;
  1113. }
  1114. #else
  1115. err = qts_handle_trusted_touch_pvm(qts_data, value);
  1116. if (err) {
  1117. pr_err("Failed to handle trusted touch in pvm\n");
  1118. return -EINVAL;
  1119. }
  1120. #endif
  1121. err = count;
  1122. return err;
  1123. }
  1124. static ssize_t trusted_touch_event_show(struct kobject *kobj, struct kobj_attribute *attr,
  1125. char *buf)
  1126. {
  1127. struct qts_data *qts_data;
  1128. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1129. qts_data = &qts_data_entries->info[idx];
  1130. return scnprintf(buf, PAGE_SIZE, "%d",
  1131. atomic_read(&qts_data->trusted_touch_event));
  1132. }
  1133. static ssize_t trusted_touch_event_store(struct kobject *kobj, struct kobj_attribute *attr,
  1134. const char *buf, size_t count)
  1135. {
  1136. struct qts_data *qts_data;
  1137. unsigned long value;
  1138. int err = 0;
  1139. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1140. if (count > 2)
  1141. return -EINVAL;
  1142. err = kstrtoul(buf, 10, &value);
  1143. if (err != 0)
  1144. return err;
  1145. qts_data = &qts_data_entries->info[idx];
  1146. if (!atomic_read(&qts_data->trusted_touch_initialized))
  1147. return -EIO;
  1148. if (value)
  1149. return -EIO;
  1150. atomic_set(&qts_data->trusted_touch_event, value);
  1151. return count;
  1152. }
  1153. static ssize_t trusted_touch_type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
  1154. {
  1155. struct qts_data *qts_data;
  1156. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1157. qts_data = &qts_data_entries->info[idx];
  1158. return scnprintf(buf, PAGE_SIZE, "%s", qts_data->vm_info->trusted_touch_type);
  1159. }
  1160. static ssize_t trusted_touch_device_path_show(struct kobject *kobj,
  1161. struct kobj_attribute *attr, char *buf)
  1162. {
  1163. struct qts_data *qts_data;
  1164. char *path = NULL;
  1165. u32 idx = qts_ts_is_primary(kobj) ? 0 : 1;
  1166. qts_data = &qts_data_entries->info[idx];
  1167. if (qts_data && qts_data->dev)
  1168. path = kobject_get_path(&qts_data->dev->kobj, GFP_KERNEL);
  1169. return scnprintf(buf, PAGE_SIZE, "%s", path ? path : "");
  1170. }
  1171. static struct kobj_attribute trusted_touch_enable_attr =
  1172. __ATTR(trusted_touch_enable, 0664, trusted_touch_enable_show, trusted_touch_enable_store);
  1173. static struct kobj_attribute trusted_touch_event_attr =
  1174. __ATTR(trusted_touch_event, 0664, trusted_touch_event_show, trusted_touch_event_store);
  1175. static struct kobj_attribute trusted_touch_type_attr =
  1176. __ATTR(trusted_touch_type, 0664, trusted_touch_type_show, NULL);
  1177. static struct kobj_attribute trusted_touch_device_path_attr =
  1178. __ATTR(trusted_touch_device_path, 0444, trusted_touch_device_path_show, NULL);
  1179. static struct attribute *qts_attributes[] = {
  1180. &trusted_touch_enable_attr.attr,
  1181. &trusted_touch_event_attr.attr,
  1182. &trusted_touch_type_attr.attr,
  1183. &trusted_touch_device_path_attr.attr,
  1184. NULL,
  1185. };
  1186. static struct attribute_group qts_attribute_group = {
  1187. .attrs = qts_attributes,
  1188. };
  1189. static int qts_create_sysfs(struct qts_data *qts_data)
  1190. {
  1191. int ret = 0;
  1192. struct kobject *qts_kobj;
  1193. struct kobject *client_kobj;
  1194. qts_kobj = &qts_data_entries->qts_kset->kobj;
  1195. if (qts_data->client_type == QTS_CLIENT_PRIMARY_TOUCH) {
  1196. client_kobj = kobject_create_and_add("primary", qts_kobj);
  1197. if (!client_kobj) {
  1198. pr_err("primary kobject_create_and_add failed\n");
  1199. return -ENOMEM;
  1200. }
  1201. ret = sysfs_create_group(client_kobj, &qts_attribute_group);
  1202. if (ret) {
  1203. pr_err("[EX]: sysfs_create_group() failed!!\n");
  1204. sysfs_remove_group(client_kobj, &qts_attribute_group);
  1205. return -ENOMEM;
  1206. }
  1207. } else if (qts_data->client_type == QTS_CLIENT_SECONDARY_TOUCH) {
  1208. client_kobj = kobject_create_and_add("secondary", qts_kobj);
  1209. if (!client_kobj) {
  1210. pr_err("secondary kobject_create_and_add failed\n");
  1211. return -ENOMEM;
  1212. }
  1213. ret = sysfs_create_group(client_kobj, &qts_attribute_group);
  1214. if (ret) {
  1215. pr_err("[EX]: sysfs_create_group() failed!!\n");
  1216. sysfs_remove_group(client_kobj, &qts_attribute_group);
  1217. return -ENOMEM;
  1218. }
  1219. }
  1220. pr_debug("sysfs_create_group() succeeded\n");
  1221. return ret;
  1222. }
  1223. static int qts_ts_check_dt(struct device_node *np)
  1224. {
  1225. int i;
  1226. int count;
  1227. struct device_node *node;
  1228. struct drm_panel *panel;
  1229. count = of_count_phandle_with_args(np, "panel", NULL);
  1230. if (count <= 0)
  1231. return 0;
  1232. for (i = 0; i < count; i++) {
  1233. node = of_parse_phandle(np, "panel", i);
  1234. panel = of_drm_find_panel(node);
  1235. of_node_put(node);
  1236. if (!IS_ERR(panel)) {
  1237. active_panel = panel;
  1238. return 0;
  1239. }
  1240. }
  1241. return PTR_ERR(panel);
  1242. }
  1243. static void qts_power_source_init(struct qts_data *qts_data)
  1244. {
  1245. qts_data->vdd = regulator_get(qts_data->dev, "vdd");
  1246. if (IS_ERR_OR_NULL(qts_data->vdd))
  1247. pr_debug("get vdd regulator failed\n");
  1248. qts_data->avdd = regulator_get(qts_data->dev, "avdd");
  1249. if (IS_ERR_OR_NULL(qts_data->avdd))
  1250. pr_debug("get avdd regulator failed\n");
  1251. }
  1252. #ifndef CONFIG_ARCH_QTI_VM
  1253. static int qts_enable_reg(struct qts_data *qts_data, bool enable)
  1254. {
  1255. int ret = 0;
  1256. if (IS_ERR_OR_NULL(qts_data->vdd)) {
  1257. pr_err("vdd is invalid\n");
  1258. return ret;
  1259. }
  1260. if (enable) {
  1261. ret = regulator_enable(qts_data->vdd);
  1262. if (ret) {
  1263. pr_err("enable vdd regulator failed,ret=%d\n", ret);
  1264. goto error;
  1265. }
  1266. if (!IS_ERR_OR_NULL(qts_data->avdd)) {
  1267. ret = regulator_enable(qts_data->avdd);
  1268. if (ret) {
  1269. pr_err("enable avdd regulator failed,ret=%d\n", ret);
  1270. goto error_avdd_en;
  1271. }
  1272. }
  1273. } else {
  1274. ret = regulator_disable(qts_data->vdd);
  1275. if (ret)
  1276. pr_err("disable vdd regulator failed,ret=%d\n", ret);
  1277. if (!IS_ERR_OR_NULL(qts_data->avdd)) {
  1278. ret = regulator_disable(qts_data->avdd);
  1279. if (ret)
  1280. pr_err("disable avdd regulator failed,ret=%d\n", ret);
  1281. }
  1282. }
  1283. pr_debug("enable %d completed\n", enable);
  1284. return ret;
  1285. error_avdd_en:
  1286. (void)regulator_disable(qts_data->vdd);
  1287. error:
  1288. return ret;
  1289. }
  1290. #endif
  1291. static void qts_ts_suspend(struct qts_data *qts_data)
  1292. {
  1293. int rc = 0;
  1294. if (qts_data->suspended) {
  1295. pr_warn("already in suspend state\n");
  1296. return;
  1297. }
  1298. if (qts_data->tui_supported) {
  1299. if (atomic_read(&qts_data->trusted_touch_transition)
  1300. || atomic_read(&qts_data->trusted_touch_enabled))
  1301. wait_for_completion_interruptible(&qts_data->trusted_touch_powerdown);
  1302. }
  1303. mutex_lock(&qts_data->transition_lock);
  1304. rc = qts_data->vendor_ops.suspend(qts_data->vendor_data);
  1305. if (rc)
  1306. pr_err("suspend failed, rc = %d\n", rc);
  1307. qts_data->suspended = true;
  1308. mutex_unlock(&qts_data->transition_lock);
  1309. }
  1310. static void qts_ts_resume(struct qts_data *qts_data)
  1311. {
  1312. int rc = 0;
  1313. if (!qts_data->suspended) {
  1314. pr_warn("Already in awake state\n");
  1315. return;
  1316. }
  1317. if (qts_data->tui_supported)
  1318. if (atomic_read(&qts_data->trusted_touch_transition))
  1319. wait_for_completion_interruptible(&qts_data->trusted_touch_powerdown);
  1320. mutex_lock(&qts_data->transition_lock);
  1321. rc = qts_data->vendor_ops.resume(qts_data->vendor_data);
  1322. if (rc)
  1323. pr_err("resume failed, rc = %d\n", rc);
  1324. qts_data->suspended = false;
  1325. mutex_unlock(&qts_data->transition_lock);
  1326. }
  1327. static void qts_resume_work(struct work_struct *work)
  1328. {
  1329. struct qts_data *qts_data = container_of(work, struct qts_data,
  1330. resume_work);
  1331. qts_ts_resume(qts_data);
  1332. }
  1333. static void qts_suspend_work(struct work_struct *work)
  1334. {
  1335. struct qts_data *qts_data = container_of(work, struct qts_data,
  1336. suspend_work);
  1337. qts_ts_suspend(qts_data);
  1338. }
  1339. static void qts_panel_notifier_callback(enum panel_event_notifier_tag tag,
  1340. struct panel_event_notification *notification, void *client_data)
  1341. {
  1342. struct qts_data *qts_data = client_data;
  1343. if (!notification) {
  1344. pr_err("Invalid notification\n");
  1345. return;
  1346. }
  1347. pr_debug("Notification type:%d, early_trigger:%d\n",
  1348. notification->notif_type, notification->notif_data.early_trigger);
  1349. switch (notification->notif_type) {
  1350. case DRM_PANEL_EVENT_UNBLANK:
  1351. if (notification->notif_data.early_trigger) {
  1352. pr_debug("resume notification pre commit\n");
  1353. } else {
  1354. if (qts_data->schedule_resume)
  1355. queue_work(qts_data->ts_workqueue, &qts_data->resume_work);
  1356. else
  1357. qts_ts_resume(qts_data);
  1358. }
  1359. break;
  1360. case DRM_PANEL_EVENT_BLANK:
  1361. if (notification->notif_data.early_trigger) {
  1362. if (qts_data->schedule_resume)
  1363. cancel_work_sync(&qts_data->resume_work);
  1364. if (qts_data->schedule_suspend)
  1365. queue_work(qts_data->ts_workqueue, &qts_data->suspend_work);
  1366. else
  1367. qts_ts_suspend(qts_data);
  1368. } else {
  1369. pr_debug("suspend notification post commit\n");
  1370. }
  1371. break;
  1372. case DRM_PANEL_EVENT_BLANK_LP:
  1373. pr_debug("received lp event\n");
  1374. break;
  1375. case DRM_PANEL_EVENT_FPS_CHANGE:
  1376. pr_debug("Received fps change old fps:%d new fps:%d\n",
  1377. notification->notif_data.old_fps,
  1378. notification->notif_data.new_fps);
  1379. break;
  1380. default:
  1381. pr_debug("notification serviced :%d\n",
  1382. notification->notif_type);
  1383. break;
  1384. }
  1385. }
  1386. static void qts_ts_register_for_panel_events(struct qts_data *qts_data)
  1387. {
  1388. void *cookie = NULL;
  1389. if (qts_data->client_type != QTS_CLIENT_PRIMARY_TOUCH) {
  1390. pr_err("Invalid touch type\n");
  1391. return;
  1392. }
  1393. cookie = panel_event_notifier_register(PANEL_EVENT_NOTIFICATION_PRIMARY,
  1394. PANEL_EVENT_NOTIFIER_CLIENT_PRIMARY_TOUCH, qts_data->panel,
  1395. &qts_panel_notifier_callback, qts_data);
  1396. if (!cookie) {
  1397. pr_err("Failed to register for panel events\n");
  1398. return;
  1399. }
  1400. pr_debug("registered for panel notifications panel: 0x%x\n", qts_data->panel);
  1401. qts_data->notifier_cookie = cookie;
  1402. }
  1403. int qts_client_register(struct qts_vendor_data qts_vendor_data)
  1404. {
  1405. struct qts_data *qts_data;
  1406. struct device_node *dp;
  1407. int rc = 0;
  1408. if (!qts_data_entries) {
  1409. pr_debug("QTS client register\n");
  1410. qts_data_entries = kzalloc(sizeof(*qts_data_entries), GFP_KERNEL);
  1411. if (!qts_data_entries) {
  1412. pr_err("mem allocation failed\n");
  1413. return -EPROBE_DEFER;
  1414. }
  1415. mutex_init(&qts_data_entries->qts_data_entries_lock);
  1416. qts_data_entries->qts_kset = kset_create_and_add("qts", NULL, kernel_kobj);
  1417. if (!qts_data_entries->qts_kset) {
  1418. pr_err("qts kset create failed\n");
  1419. return -ENOMEM;
  1420. }
  1421. }
  1422. mutex_lock(&qts_data_entries->qts_data_entries_lock);
  1423. if (qts_vendor_data.bus_type == QTS_BUS_TYPE_I2C)
  1424. dp = qts_vendor_data.client->dev.of_node;
  1425. else
  1426. dp = qts_vendor_data.spi->dev.of_node;
  1427. rc = qts_ts_check_dt(dp);
  1428. if (rc) {
  1429. pr_debug("qts_ts_check_dt failed, rc = %d\n", rc);
  1430. goto qts_register_end;
  1431. }
  1432. pr_debug("QTS client register starts\n");
  1433. qts_data = &qts_data_entries->info[qts_vendor_data.client_type];
  1434. qts_data->client = qts_vendor_data.client;
  1435. qts_data->spi = qts_vendor_data.spi;
  1436. if (qts_vendor_data.bus_type == QTS_BUS_TYPE_I2C)
  1437. qts_data->dev = &qts_data->client->dev;
  1438. else
  1439. qts_data->dev = &qts_data->spi->dev;
  1440. qts_data->bus_type = qts_vendor_data.bus_type;
  1441. qts_data->client_type = qts_vendor_data.client_type;
  1442. qts_data->dp = dp;
  1443. qts_data->vendor_data = qts_vendor_data.vendor_data;
  1444. qts_data->panel = active_panel;
  1445. qts_data->vendor_ops = qts_vendor_data.qts_vendor_ops;
  1446. qts_data->schedule_suspend = qts_vendor_data.schedule_suspend;
  1447. qts_data->schedule_resume = qts_vendor_data.schedule_resume;
  1448. qts_trusted_touch_init(qts_data);
  1449. mutex_init(&(qts_data->qts_clk_io_ctrl_mutex));
  1450. if (qts_data->tui_supported)
  1451. qts_create_sysfs(qts_data);
  1452. mutex_init(&qts_data->transition_lock);
  1453. #ifdef CONFIG_ARCH_QTI_VM
  1454. atomic_set(&qts_data->delayed_tvm_probe_pending, 1);
  1455. goto qts_register_end;
  1456. #else
  1457. atomic_set(&qts_data->delayed_pvm_probe_pending, 1);
  1458. #endif
  1459. qts_power_source_init(qts_data);
  1460. qts_data->ts_workqueue = create_singlethread_workqueue("qts_wq");
  1461. if (!qts_data->ts_workqueue)
  1462. pr_err("create qts workqueue fail\n");
  1463. if (qts_data->ts_workqueue && qts_data->schedule_resume)
  1464. INIT_WORK(&qts_data->resume_work, qts_resume_work);
  1465. if (qts_data->ts_workqueue && qts_data->schedule_suspend)
  1466. INIT_WORK(&qts_data->suspend_work, qts_suspend_work);
  1467. qts_ts_register_for_panel_events(qts_data);
  1468. qts_register_end:
  1469. pr_debug("client register end\n");
  1470. mutex_unlock(&qts_data_entries->qts_data_entries_lock);
  1471. return rc;
  1472. }
  1473. EXPORT_SYMBOL(qts_client_register);