Quellcode durchsuchen

修复测试反馈的问题

liu qidong [url ssh://qidong.liu@10.2.90.253:29418/] vor 1 Monat
Ursprung
Commit
141ac735cd
4 geänderte Dateien mit 77 neuen und 12 gelöschten Zeilen
  1. 41 6
      batteryled.c
  2. 15 0
      fan.c
  3. 12 2
      led_heartbeat.c
  4. 9 4
      light_ring.c

+ 41 - 6
batteryled.c

@@ -212,7 +212,7 @@ static ssize_t led_health_store(struct kobject *kobj,
     if (ret < 0)
         return ret;
 
-    if(val == 0x0 || val == 0x1 || val == 0x3)
+    if(val == 0x0 || val == 0x1 || val == 0x2 || val == 0x3 || val == 0x4)
     {
         led_health_val = val;
     }
@@ -251,7 +251,7 @@ static ssize_t led_charge_store(struct kobject *kobj, struct kobj_attribute *att
     if (ret < 0)
         return ret;
 
-    if(val == 0x0 || val == 0x2 || val == 0x4)
+    if(val == 0x0 || val == 0x1 || val == 0x2 || val == 0x3 || val == 0x4)
     {
         led_charge_val = val;
     }
@@ -281,7 +281,10 @@ static void delay_work_func(struct work_struct *work)
 {
     static uint8_t blink_flag = 0;
     uint8_t data = 0;
-
+    // val is led state: off; red; green
+    // val bit meaning:
+    // bit 2-3: health led  bit2-green, bit3-red        blude=green white=red
+    // bit 4-5: charge led  bit4-green, bit5-red
     if(blink_flag == 0)
     {
         //Turn off when flickering
@@ -292,21 +295,37 @@ static void delay_work_func(struct work_struct *work)
         }
         else if(led_health_val == 0x1)
         {
-            data = data | 0x04;
+            data = data | 0x8;
+        }
+        else if(led_health_val == 0x2)
+        {
+            data = data | 0x4;
         }
         else if(led_health_val == 0x3)
         {
             data = data & 0xf3;
         }
+        else if(led_health_val == 0x4)
+        {
+            data = data & 0xf3;
+        }
         
         if(led_charge_val == 0x0)
         {
             data = data & 0xcf;
         }
-        else if(led_charge_val == 0x2)
+        else if(led_charge_val == 0x1)
         {
             data = data | 0x20;
         }
+        else if(led_charge_val == 0x2)
+        {
+            data = data | 0x10;
+        }
+        else if(led_charge_val == 0x3)
+        {
+            data = data & 0xcf;
+        }
         else if(led_charge_val == 0x4)
         {
             data = data & 0xcf;
@@ -322,10 +341,18 @@ static void delay_work_func(struct work_struct *work)
             data = data & 0xf3;
         }
         else if(led_health_val == 0x1)
+        {
+            data = data | 0x08;
+        }
+        else if(led_health_val == 0x2)
         {
             data = data | 0x04;
         }
         else if(led_health_val == 0x3)
+        {
+            data = data | 0x08;
+        }
+        else if(led_health_val == 0x4)
         {
             data = data | 0x04;
         }
@@ -334,13 +361,21 @@ static void delay_work_func(struct work_struct *work)
         {
             data = data & 0xcf;
         }
+        else if(led_charge_val == 0x1)
+        {
+            data = data | 0x20;
+        }
         else if(led_charge_val == 0x2)
+        {
+            data = data | 0x10;
+        }
+        else if(led_charge_val == 0x3)
         {
             data = data | 0x20;
         }
         else if(led_charge_val == 0x4)
         {
-            data = data | 0x20;
+            data = data | 0x10;
         }
     }
     oem_ec_write_ram(2, 0x31, data);

+ 15 - 0
fan.c

@@ -258,6 +258,9 @@ static ssize_t pwm1_store(struct kobject *kobj, struct kobj_attribute *attr,
 		return -EINVAL;
 	mutex_lock(&data->lock);
 
+	if(val > 200)
+		val = 200;
+
 	mode = pwm_mode(data, 0);
 	if (mode == 1)
 	{
@@ -450,6 +453,16 @@ static struct attribute_group fan_attr_group = {
 
 /* ========== 模块初始化 ========== */
 
+static void set_auto_mode(int nr)
+{
+	u8 reg;
+	struct vfiec_data *data = g_data;
+	reg = ec_read_reg(data, IT87_REG_PWM[nr]);
+	reg = 0x80 | (reg & 0x7c) | (nr & 0x03);
+	ec_write_reg(data, IT87_REG_PWM[nr], reg);
+	data->fan_main_ctrl |= BIT(nr);
+	ec_write_reg(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
+}
 int fan_init(void)
 {
 	int err;
@@ -508,6 +521,8 @@ int fan_init(void)
 		goto err_release;
 	}
 
+	set_auto_mode(0);
+	set_auto_mode(1);
 	pr_info("VFIEC hwmon driver loaded, path: /sys/kernel/vfiec/hwmon/\n");
 	return 0;
 

+ 12 - 2
led_heartbeat.c

@@ -244,9 +244,9 @@ static ssize_t led_heartbeat_read(struct file *filp, char __user *buf, size_t co
 static ssize_t led_heartbeat_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
 {
     unsigned char kbuff[3] = {0};
-    if(count > sizeof(kbuff))
+    if(count != sizeof(kbuff))
     {
-        count = sizeof(kbuff);
+        return -EINVAL;
     }
     if (copy_from_user(kbuff, buf, count) != 0)
     {
@@ -257,6 +257,16 @@ static ssize_t led_heartbeat_write(struct file *filp, const char __user *buf, si
     led_blink_flag = kbuff[1];
     led_blink_speed = kbuff[2];
 
+    if(led_color != 0x0 && led_color != 0x40 && led_color != 0x80)
+    {
+        return -EINVAL;
+    }
+
+    if(led_blink_flag != 0x0 && led_blink_flag != 0x1)
+    {
+        return -EINVAL;
+    }
+
     if(led_color == 0x00)
     {
         // off

+ 9 - 4
light_ring.c

@@ -165,6 +165,11 @@ static void delay_work_func(struct work_struct *work)
             {
                 global_dev->lightring->brightness = 100;
             }
+            if(global_dev->lightring->brightness >= global_dev->lightring->max_fade_brightness)
+            {
+                global_dev->lightring->brightness = global_dev->lightring->max_fade_brightness;
+                global_dev->lightring->brightness_index = 0;
+            }
             set_color(global_dev->lightring->color);
         }
 
@@ -456,19 +461,19 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
         time = 3000;
         global_dev->lightring->brightness = 100;
     }
-    else if (strncmp(buf, "fade_slow", 9) == 0)
+    else if (strncmp(buf, "fade_slow", 9) == 0 && global_dev->lightring->max_fade_brightness > 0)
     {
         mode = LIGHT_MODE_FLASH_SLOW;
         time = 60;
         global_dev->lightring->brightness_index = 0;
     }
-    else if (strncmp(buf, "fade_medium", 11) == 0)
+    else if (strncmp(buf, "fade_medium", 11) == 0 && global_dev->lightring->max_fade_brightness > 0)
     {
         mode = LIGHT_MODE_FLASH_MEDIUM;
         time = 40;
         global_dev->lightring->brightness_index = 0;
     }
-    else if (strncmp(buf, "fade_fast", 9) == 0)
+    else if (strncmp(buf, "fade_fast", 9) == 0 && global_dev->lightring->max_fade_brightness > 0)
     {
         mode = LIGHT_MODE_FLASH_FAST;
         time = 20;
@@ -477,7 +482,7 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
     else
     {
         pr_err("Lightring: mode format error\n");
-        return -1;
+        return -EINVAL;
     }
 
     global_dev->lightring->mode = mode;