fingerprint_sysfs.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * fingerprint sysfs class
  3. */
  4. #include <linux/module.h>
  5. #include <linux/types.h>
  6. #include <linux/init.h>
  7. #include <linux/device.h>
  8. #include <linux/fs.h>
  9. #include <linux/err.h>
  10. struct class *fingerprint_class;
  11. EXPORT_SYMBOL_GPL(fingerprint_class);
  12. /*
  13. * Create sysfs interface
  14. */
  15. static void set_fingerprint_attr(struct device *dev,
  16. struct device_attribute *attributes[])
  17. {
  18. int i;
  19. for (i = 0; attributes[i] != NULL; i++)
  20. if ((device_create_file(dev, attributes[i])) < 0)
  21. pr_err("%s: fail device_create_file"\
  22. "(dev, attributes[%d])\n", __func__, i);
  23. }
  24. int fingerprint_register(struct device *dev, void *drvdata,
  25. struct device_attribute *attributes[], char *name)
  26. {
  27. int ret = 0;
  28. if (!fingerprint_class) {
  29. fingerprint_class = class_create(THIS_MODULE, "fingerprint");
  30. if (IS_ERR(fingerprint_class))
  31. return PTR_ERR(fingerprint_class);
  32. }
  33. dev = device_create(fingerprint_class, NULL, 0, drvdata, "%s", name);
  34. if (IS_ERR(dev)) {
  35. ret = PTR_ERR(dev);
  36. pr_err("%s: device_create failed!"\
  37. "[%d]\n", __func__, ret);
  38. return ret;
  39. }
  40. set_fingerprint_attr(dev, attributes);
  41. return 0;
  42. }
  43. EXPORT_SYMBOL_GPL(fingerprint_register);
  44. void fingerprint_unregister(struct device *dev,
  45. struct device_attribute *attributes[])
  46. {
  47. int i;
  48. for (i = 0; attributes[i] != NULL; i++)
  49. device_remove_file(dev, attributes[i]);
  50. }
  51. EXPORT_SYMBOL_GPL(fingerprint_unregister);
  52. void destroy_fingerprint_class(void)
  53. {
  54. if (fingerprint_class) {
  55. class_destroy(fingerprint_class);
  56. fingerprint_class = NULL;
  57. }
  58. }
  59. EXPORT_SYMBOL_GPL(destroy_fingerprint_class);
  60. static int __init fingerprint_class_init(void)
  61. {
  62. pr_info("%s\n", __func__);
  63. fingerprint_class = class_create(THIS_MODULE, "fingerprint");
  64. if (IS_ERR(fingerprint_class)) {
  65. pr_err("%s, create fingerprint_class is failed.(err=%ld)\n",
  66. __func__, IS_ERR(fingerprint_class));
  67. return PTR_ERR(fingerprint_class);
  68. }
  69. fingerprint_class->dev_uevent = NULL;
  70. return 0;
  71. }
  72. static void __exit fingerprint_class_exit(void)
  73. {
  74. if (fingerprint_class) {
  75. class_destroy(fingerprint_class);
  76. fingerprint_class = NULL;
  77. }
  78. }
  79. subsys_initcall(fingerprint_class_init);
  80. module_exit(fingerprint_class_exit);
  81. MODULE_DESCRIPTION("fingerprint sysfs class");
  82. MODULE_LICENSE("GPL");