|
@@ -0,0 +1,126 @@
|
|
|
|
|
+#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 *batteryled_kobj;
|
|
|
|
|
+
|
|
|
|
|
+static unsigned int led_charge_val = 0;
|
|
|
|
|
+static unsigned int led_health_val = 0;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/* ==================== max_fade_brightness ==================== */
|
|
|
|
|
+static ssize_t led_health_show(struct kobject *kobj,
|
|
|
|
|
+ struct kobj_attribute *attr,
|
|
|
|
|
+ char *buf)
|
|
|
|
|
+{
|
|
|
|
|
+ return sprintf(buf, "%u\n", led_health_val);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static ssize_t led_health_store(struct kobject *kobj,
|
|
|
|
|
+ struct kobj_attribute *attr,
|
|
|
|
|
+ const char *buf, size_t count)
|
|
|
|
|
+{
|
|
|
|
|
+ u32 val;
|
|
|
|
|
+ int ret;
|
|
|
|
|
+
|
|
|
|
|
+ ret = kstrtou32(buf, 10, &val);
|
|
|
|
|
+ if (ret < 0)
|
|
|
|
|
+ return ret;
|
|
|
|
|
+
|
|
|
|
|
+ led_health_val = val;
|
|
|
|
|
+ pr_info("batteryled: led_health_val %u\n", led_health_val);
|
|
|
|
|
+
|
|
|
|
|
+ return count;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static struct kobj_attribute led_health =
|
|
|
|
|
+ __ATTR(led_health, 0644, led_health_show, led_health_store);
|
|
|
|
|
+
|
|
|
|
|
+/* ==================== mode ==================== */
|
|
|
|
|
+static ssize_t led_charge_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
|
|
|
+ char *buf)
|
|
|
|
|
+{
|
|
|
|
|
+ const char *mode_str;
|
|
|
|
|
+
|
|
|
|
|
+ return sprintf(buf, "%u\n", led_charge_val);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static ssize_t led_charge_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|
|
|
|
+ const char *buf, size_t count)
|
|
|
|
|
+{
|
|
|
|
|
+ u32 val;
|
|
|
|
|
+ int ret;
|
|
|
|
|
+
|
|
|
|
|
+ ret = kstrtou32(buf, 10, &val);
|
|
|
|
|
+ if (ret < 0)
|
|
|
|
|
+ return ret;
|
|
|
|
|
+
|
|
|
|
|
+ led_charge_val = val;
|
|
|
|
|
+ pr_info("batteryled: led_charge_val %u\n", led_charge_val);
|
|
|
|
|
+
|
|
|
|
|
+ return count;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static struct kobj_attribute led_charge =
|
|
|
|
|
+ __ATTR(led_charge, 0644, led_charge_show, led_charge_store);
|
|
|
|
|
+
|
|
|
|
|
+/* ==================== 属性组 ==================== */
|
|
|
|
|
+static struct attribute *batteryled_attrs[] = {
|
|
|
|
|
+ &led_charge.attr,
|
|
|
|
|
+ &led_health.attr,
|
|
|
|
|
+ NULL,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static struct attribute_group batteryled_attr_group = {
|
|
|
|
|
+ .attrs = batteryled_attrs,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+int batteryled_init(void)
|
|
|
|
|
+{
|
|
|
|
|
+ int ret;
|
|
|
|
|
+
|
|
|
|
|
+ /* 创建 /sys/kernel/vfiec/batteryled */
|
|
|
|
|
+ batteryled_kobj = kobject_create_and_add("batteryled", vfiec_kobj);
|
|
|
|
|
+ if (!batteryled_kobj)
|
|
|
|
|
+ {
|
|
|
|
|
+ ret = -ENOMEM;
|
|
|
|
|
+ return ret;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 创建属性文件 */
|
|
|
|
|
+ ret = sysfs_create_group(batteryled_kobj, &batteryled_attr_group);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ {
|
|
|
|
|
+ pr_err("Failed to create sysfs group: %d\n", ret);
|
|
|
|
|
+ goto free_batteryled_kobj;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+free_batteryled_kobj:
|
|
|
|
|
+ kobject_put(batteryled_kobj);
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void batteryled_exit(void)
|
|
|
|
|
+{
|
|
|
|
|
+ sysfs_remove_group(batteryled_kobj, &batteryled_attr_group);
|
|
|
|
|
+ kobject_put(batteryled_kobj);
|
|
|
|
|
+}
|
|
|
|
|
+
|