glink_interface.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/device.h>
  10. #include <glink_interface.h>
  11. static struct glink_touch_dev *touch_pdev = NULL;
  12. struct touch_channel_ops touch_ops;
  13. void glink_touch_channel_init(void (*fn1)(bool), void (*fn2)(void *data, int len))
  14. {
  15. touch_ops.glink_channel_state = fn1;
  16. touch_ops.rx_msg = fn2;
  17. }
  18. EXPORT_SYMBOL(glink_touch_channel_init);
  19. int glink_touch_tx_msg(void *msg, size_t len)
  20. {
  21. int ret = 0;
  22. if (touch_pdev == NULL || !touch_pdev->chnl_state) {
  23. pr_err("pmsg_device is null, channel is closed\n");
  24. return -ENETRESET;
  25. }
  26. touch_pdev->message = msg;
  27. touch_pdev->message_length = len;
  28. if (touch_pdev->message) {
  29. ret = rpmsg_send(touch_pdev->channel,
  30. touch_pdev->message, touch_pdev->message_length);
  31. if (ret)
  32. pr_err("rpmsg_send failed: %d\n", ret);
  33. }
  34. return ret;
  35. }
  36. EXPORT_SYMBOL(glink_touch_tx_msg);
  37. static int glink_touch_probe(struct rpmsg_device *touch_rpdev)
  38. {
  39. int ret = 0;
  40. void *msg = NULL;
  41. pr_info("%s Start of glink_touch_probe\n", __func__);
  42. touch_pdev = devm_kzalloc(&touch_rpdev->dev, sizeof(*touch_pdev), GFP_KERNEL);
  43. if (!touch_pdev)
  44. return -ENOMEM;
  45. touch_pdev->channel = touch_rpdev->ept;
  46. touch_pdev->dev = &touch_rpdev->dev;
  47. if (touch_pdev->channel == NULL)
  48. return -ENOMEM;
  49. touch_pdev->chnl_state = true;
  50. dev_set_drvdata(&touch_rpdev->dev, touch_pdev);
  51. /* send a callback to slate-MSM touch driver*/
  52. touch_ops.glink_channel_state(true);
  53. if (touch_pdev->message == NULL)
  54. ret = glink_touch_tx_msg(msg, 0);
  55. pr_info("%s End of glink_touch_probe\n", __func__);
  56. return 0;
  57. }
  58. static void glink_touch_remove(struct rpmsg_device *touch_rpdev)
  59. {
  60. touch_pdev->chnl_state = false;
  61. touch_pdev->message = NULL;
  62. dev_dbg(&touch_rpdev->dev, "rpmsg client driver is removed\n");
  63. touch_ops.glink_channel_state(false);
  64. dev_set_drvdata(&touch_rpdev->dev, NULL);
  65. }
  66. static int glink_touch_cb(struct rpmsg_device *touch_rpdev,
  67. void *data, int len, void *priv, u32 src)
  68. {
  69. struct glink_touch_dev *touch_dev =
  70. dev_get_drvdata(&touch_rpdev->dev);
  71. if (!touch_dev)
  72. return -ENODEV;
  73. touch_ops.rx_msg(data, len);
  74. return 0;
  75. }
  76. static const struct rpmsg_device_id glink_touch_driver_id_table[] = {
  77. { "touch-ctrl" },
  78. {},
  79. };
  80. MODULE_DEVICE_TABLE(rpmsg, glink_touch_driver_id_table);
  81. static const struct of_device_id glink_touch_driver_of_match[] = {
  82. { .compatible = "qcom,slatetouch-rpmsg" },
  83. {},
  84. };
  85. static struct rpmsg_driver glink_touch_client = {
  86. .id_table = glink_touch_driver_id_table,
  87. .probe = glink_touch_probe,
  88. .callback = glink_touch_cb,
  89. .remove = glink_touch_remove,
  90. .drv = {
  91. .name = "glink_interface",
  92. .of_match_table = glink_touch_driver_of_match,
  93. },
  94. };
  95. module_rpmsg_driver(glink_touch_client);
  96. MODULE_DESCRIPTION("Interface Driver for MSM TOUCH and RPMSG");
  97. MODULE_LICENSE("GPL v2");