#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "light_ring.h" extern struct kobject *vfiec_kobj; static struct kobject *led_kobj = NULL; /* ==================== color ==================== */ static ssize_t color_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { static int count = 0; count++; return sprintf(buf, "color_show count=%d\n", count); } static ssize_t color_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { printk("color_store kernel rev:%s\n", buf); return count; } static struct kobj_attribute color_attr = __ATTR(color, 0644, color_show, color_store); /* ==================== mode ==================== */ static ssize_t mode_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { static int count = 0; count++; return sprintf(buf, "mode_show count=%d\n", count); } static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { printk("mode_store kernel rev:%s\n", buf); return count; } static struct kobj_attribute mode_attr = __ATTR(mode, 0644, mode_show, mode_store); /* ==================== 属性组 ==================== */ static struct attribute *led_attrs[] = { &color_attr.attr, &mode_attr.attr, NULL, }; static struct attribute_group led_attr_group = { .attrs = led_attrs, }; int led_init(void) { int ret; /* 创建 /sys/kernel/vfiec/lightring */ led_kobj = kobject_create_and_add("led", vfiec_kobj); if (!led_kobj) { ret = -ENOMEM; } /* 创建属性文件 */ ret = sysfs_create_group(led_kobj, &led_attr_group); if (ret) { pr_err("Failed to create sysfs group: %d\n", ret); } return ret; } void led_exit(void) { sysfs_remove_group(led_kobj, &led_attr_group); kobject_put(led_kobj); }