fingerprint_sysfs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2017, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include "fingerprint_sysfs.h"
  16. struct class *fingerprint_class;
  17. EXPORT_SYMBOL_GPL(fingerprint_class);
  18. /*
  19. * Create sysfs interface
  20. */
  21. void set_fingerprint_attr(struct device *dev,
  22. struct device_attribute *attributes[])
  23. {
  24. int i;
  25. for (i = 0; attributes[i] != NULL; i++)
  26. if ((device_create_file(dev, attributes[i])) < 0)
  27. pr_err("%s: fail device_create_file! %d\n", __func__, i);
  28. }
  29. int fingerprint_register(struct device *dev, void *drvdata,
  30. struct device_attribute *attributes[], char *name)
  31. {
  32. int ret = 0;
  33. if (!fingerprint_class) {
  34. #if (KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE)
  35. fingerprint_class = class_create("fingerprint");
  36. #else
  37. fingerprint_class = class_create(THIS_MODULE, "fingerprint");
  38. #endif
  39. if (IS_ERR(fingerprint_class))
  40. return PTR_ERR(fingerprint_class);
  41. }
  42. dev = device_create(fingerprint_class, NULL, 0, drvdata, "%s", name);
  43. if (IS_ERR(dev)) {
  44. ret = PTR_ERR(dev);
  45. pr_err("%s: device_create failed! %d\n", __func__, ret);
  46. return ret;
  47. }
  48. set_fingerprint_attr(dev, attributes);
  49. return 0;
  50. }
  51. EXPORT_SYMBOL_GPL(fingerprint_register);
  52. void fingerprint_unregister(struct device *dev,
  53. struct device_attribute *attributes[])
  54. {
  55. int i;
  56. for (i = 0; attributes[i] != NULL; i++)
  57. device_remove_file(dev, attributes[i]);
  58. }
  59. EXPORT_SYMBOL_GPL(fingerprint_unregister);
  60. void destroy_fingerprint_class(void)
  61. {
  62. if (fingerprint_class) {
  63. class_destroy(fingerprint_class);
  64. fingerprint_class = NULL;
  65. }
  66. }
  67. EXPORT_SYMBOL_GPL(destroy_fingerprint_class);
  68. static int __init fingerprint_class_init(void)
  69. {
  70. pr_info("%s\n", __func__);
  71. #if (KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE)
  72. fingerprint_class = class_create("fingerprint");
  73. #else
  74. fingerprint_class = class_create(THIS_MODULE, "fingerprint");
  75. #endif
  76. if (IS_ERR(fingerprint_class)) {
  77. pr_err("%s, create fingerprint_class is failed.(err=%d)\n",
  78. __func__, IS_ERR(fingerprint_class));
  79. return PTR_ERR(fingerprint_class);
  80. }
  81. fingerprint_class->dev_uevent = NULL;
  82. return 0;
  83. }
  84. static void __exit fingerprint_class_exit(void)
  85. {
  86. if (fingerprint_class) {
  87. class_destroy(fingerprint_class);
  88. fingerprint_class = NULL;
  89. }
  90. }
  91. subsys_initcall(fingerprint_class_init);
  92. module_exit(fingerprint_class_exit);
  93. MODULE_DESCRIPTION("fingerprint sysfs class");
  94. MODULE_LICENSE("GPL");