| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/fs.h>
- #include <linux/cdev.h>
- #include <linux/device.h>
- #include <linux/uaccess.h>
- #include <linux/slab.h>
- #include <linux/pci.h>
- #include <linux/i2c.h>
- #include <linux/acpi.h>
- #include <linux/interrupt.h>
- #include <linux/wait.h>
- #include <linux/sched.h>
- #include <linux/poll.h>
- #include <linux/mutex.h>
- #include <linux/delay.h>
- #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);
- }
|