led.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/fs.h>
  5. #include <linux/cdev.h>
  6. #include <linux/device.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/slab.h>
  9. #include <linux/pci.h>
  10. #include <linux/i2c.h>
  11. #include <linux/acpi.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/wait.h>
  14. #include <linux/sched.h>
  15. #include <linux/poll.h>
  16. #include <linux/mutex.h>
  17. #include <linux/delay.h>
  18. #include "light_ring.h"
  19. extern struct kobject *vfiec_kobj;
  20. static struct kobject *led_kobj = NULL;
  21. /* ==================== color ==================== */
  22. static ssize_t color_show(struct kobject *kobj, struct kobj_attribute *attr,
  23. char *buf)
  24. {
  25. static int count = 0;
  26. count++;
  27. return sprintf(buf, "color_show count=%d\n", count);
  28. }
  29. static ssize_t color_store(struct kobject *kobj, struct kobj_attribute *attr,
  30. const char *buf, size_t count)
  31. {
  32. printk("color_store kernel rev:%s\n", buf);
  33. return count;
  34. }
  35. static struct kobj_attribute color_attr =
  36. __ATTR(color, 0644, color_show, color_store);
  37. /* ==================== mode ==================== */
  38. static ssize_t mode_show(struct kobject *kobj, struct kobj_attribute *attr,
  39. char *buf)
  40. {
  41. static int count = 0;
  42. count++;
  43. return sprintf(buf, "mode_show count=%d\n", count);
  44. }
  45. static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
  46. const char *buf, size_t count)
  47. {
  48. printk("mode_store kernel rev:%s\n", buf);
  49. return count;
  50. }
  51. static struct kobj_attribute mode_attr =
  52. __ATTR(mode, 0644, mode_show, mode_store);
  53. static struct attribute *led_attrs[] = {
  54. &color_attr.attr,
  55. &mode_attr.attr,
  56. NULL,
  57. };
  58. static struct attribute_group led_attr_group = {
  59. .attrs = led_attrs,
  60. };
  61. int led_init(void)
  62. {
  63. int ret;
  64. /* 创建 /sys/kernel/vfiec/lightring */
  65. led_kobj = kobject_create_and_add("led", vfiec_kobj);
  66. if (!led_kobj)
  67. {
  68. ret = -ENOMEM;
  69. }
  70. ret = sysfs_create_group(led_kobj, &led_attr_group);
  71. if (ret)
  72. {
  73. pr_err("Failed to create sysfs group: %d\n", ret);
  74. }
  75. return ret;
  76. }
  77. void led_exit(void)
  78. {
  79. sysfs_remove_group(led_kobj, &led_attr_group);
  80. kobject_put(led_kobj);
  81. }