dummy_touch.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/input.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/mod_devicetable.h>
  9. MODULE_DESCRIPTION("QTI dummy touchscreen driver");
  10. MODULE_LICENSE("GPL v2");
  11. #define DEVICE_COMPATIBLE "qti,dummy_ts"
  12. #define DRIVER_NAME "qti_dummy_ts"
  13. static int dummy_touch_probe(struct platform_device *device)
  14. {
  15. struct input_dev *touch_dev = NULL;
  16. int rc;
  17. touch_dev = input_allocate_device();
  18. if (!touch_dev) {
  19. pr_err("%s: input device allocate failed\n", __func__);
  20. return -ENOMEM;
  21. }
  22. touch_dev->name = "qti_dummy_ts";
  23. touch_dev->id.bustype = BUS_VIRTUAL;
  24. touch_dev->evbit[0] = BIT_MASK(EV_KEY);
  25. touch_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
  26. touch_dev->dev.parent = NULL;
  27. rc = input_register_device(touch_dev);
  28. if (rc) {
  29. pr_err("%s: touch device register failed, rc = %d\n", __func__, rc);
  30. input_free_device(touch_dev);
  31. return rc;
  32. }
  33. pr_info("qti_dummy_ts device registered\n");
  34. platform_set_drvdata(device, (void *)touch_dev);
  35. return 0;
  36. }
  37. static int dummy_touch_remove(struct platform_device *device)
  38. {
  39. struct input_dev *touch_dev = NULL;
  40. touch_dev = (struct input_dev *)platform_get_drvdata(device);
  41. if (touch_dev)
  42. input_free_device(touch_dev);
  43. return 0;
  44. }
  45. static const struct of_device_id dummy_touch_id[] = {
  46. {.compatible = DEVICE_COMPATIBLE},
  47. {}
  48. };
  49. static struct platform_driver dummy_touch_driver = {
  50. .driver = {
  51. .name = DRIVER_NAME,
  52. .of_match_table = dummy_touch_id,
  53. },
  54. .probe = dummy_touch_probe,
  55. .remove = dummy_touch_remove,
  56. };
  57. static int __init dummy_touch_init(void)
  58. {
  59. platform_driver_register(&dummy_touch_driver);
  60. return 0;
  61. }
  62. static void __exit dummy_touch_exit(void)
  63. {
  64. platform_driver_unregister(&dummy_touch_driver);
  65. }
  66. late_initcall(dummy_touch_init);
  67. module_exit(dummy_touch_exit);