ソースを参照

添加ac_power驱动

liu qidong [url ssh://qidong.liu@10.2.90.253:29418/] 3 週間 前
コミット
69927d28e6
2 ファイル変更194 行追加0 行削除
  1. 2 0
      batteryled.c
  2. 192 0
      fan.c

+ 2 - 0
batteryled.c

@@ -378,6 +378,8 @@ free_batteryled_kobj:
 
 void batteryled_exit(void)
 {
+    
+    cancel_delayed_work_sync(&delay_work1);
     sysfs_remove_group(batteryled_kobj, &batteryled_attr_group);
     kobject_put(batteryled_kobj);
 }

+ 192 - 0
fan.c

@@ -58,6 +58,9 @@
 #include <linux/dmi.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
+#include <linux/delay.h>
+
+#include "gpioregs.h"
 
 #define DRVNAME "it87"
 
@@ -569,6 +572,150 @@ static struct kobject *fan_kobj = NULL;
 struct device *dev_it87 = NULL;
 
 
+static int wait_ibf(void)
+{
+    int i = 0;
+    while (inb(EC_CMD_PORT) & EC_IBF)
+    {
+        if (++i > TIMEOUT_LOOPS)
+        {
+            return -1;
+        }
+        udelay(1);
+    }
+    return 0;
+}
+
+static int wait_obf(void)
+{
+    int i = 0;
+    while (!(inb(EC_CMD_PORT) & EC_OBF))
+    {
+        if (++i > TIMEOUT_LOOPS)
+        {
+            return -1;
+        }
+        udelay(1);
+    }
+    return 0;
+}
+
+static int ec_read_ram(uint8_t offset, uint8_t *data)
+{
+    if (wait_ibf() < 0)
+        return -1;
+    outb(CMD_READ_RAM, EC_CMD_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(offset, EC_DATA_PORT);
+
+    if (wait_obf() < 0)
+        return -1;
+    *data = inb(EC_DATA_PORT);
+
+    return 0;
+}
+
+static int ec_write_ram(uint8_t offset, uint8_t data)
+{
+    if (wait_ibf() < 0)
+        return -1;
+    outb(CMD_WRITE_RAM, EC_CMD_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(offset, EC_DATA_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(data, EC_DATA_PORT);
+
+    return 0;
+}
+
+static int oem_ec_read_ram(uint8_t page, uint8_t offset, uint8_t *data)
+{
+    unsigned char WEC, REC;
+    switch(page)
+    {
+        case 0:
+        {
+            WEC = 0x96;
+            REC = 0x95;
+            break;
+        }
+        
+        case 1:
+        {
+            WEC = 0x98;
+            REC = 0x97;
+            break;
+        }
+        
+        default:
+        {
+            WEC = 0x81;
+            REC = 0x80;
+            break;
+        }
+    }    
+    if (wait_ibf() < 0)
+        return -1;
+    outb(REC, EC_CMD_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(offset, EC_DATA_PORT);
+
+    if (wait_obf() < 0)
+        return -1;
+    *data = inb(EC_DATA_PORT);
+
+    return 0;
+}
+
+static int oem_ec_write_ram(uint8_t page, uint8_t offset, uint8_t data)
+{
+    unsigned char WEC, REC;
+    switch(page)
+    {
+        case 0:
+        {
+            WEC = 0x96;
+            REC = 0x95;
+            break;
+        }
+        
+        case 1:
+        {
+            WEC = 0x98;
+            REC = 0x97;
+            break;
+        }
+        
+        default:
+        {
+            WEC = 0x81;
+            REC = 0x80;
+            break;
+        }
+    }
+    if (wait_ibf() < 0)
+        return -1;
+    outb(WEC, EC_CMD_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(offset, EC_DATA_PORT);
+
+    if (wait_ibf() < 0)
+        return -1;
+    outb(data, EC_DATA_PORT);
+
+    return 0;
+}
+
 int vid_from_reg(int val, u8 vrm)
 {
 	int vid;
@@ -3871,6 +4018,49 @@ static ssize_t temp2_input_store(struct kobject *kobj, struct kobj_attribute *at
     return -EINVAL;
 }
 
+
+static ssize_t power_flag_show(struct kobject *kobj, struct kobj_attribute *attr,
+                         char *buf)
+{
+    return -EINVAL;
+	// int nr = 1;
+	// int index = 0;
+	// struct it87_data *data = it87_update_device(dev_it87);
+
+	// return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])/1000);
+}
+
+static ssize_t power_flag_store(struct kobject *kobj, struct kobj_attribute *attr,
+                                 const char *buf, size_t count)
+{
+    return -EINVAL;
+}
+
+
+static ssize_t ac_power_show(struct kobject *kobj, struct kobj_attribute *attr,
+                         char *buf)
+{
+    int ac_power_flag = 0;
+    uint8_t val = 0x00;
+    if (oem_ec_read_ram(2, 0x36, &val) < 0)
+        return -1;
+    ac_power_flag = (val  & 0x03) ? 1 : 0;
+
+	return sprintf(buf, "%d", ac_power_flag);
+}
+
+static ssize_t ac_power_store(struct kobject *kobj, struct kobj_attribute *attr,
+                                 const char *buf, size_t count)
+{
+    return -EINVAL;
+}
+
+static struct kobj_attribute power_flag =
+    __ATTR(power_flag, 0644, power_flag_show, power_flag_store);
+
+static struct kobj_attribute ac_power =
+    __ATTR(ac_power, 0644, ac_power_show, ac_power_store);
+
 static struct kobj_attribute temp1_input =
     __ATTR(temp1_input, 0644, temp1_input_show, temp1_input_store);
 
@@ -3907,6 +4097,8 @@ static struct attribute *fan_attrs[] = {
     &pwm2_enable.attr,
     &temp1_input.attr,
     &temp2_input.attr,
+    &power_flag.attr,
+    &ac_power.attr,
     NULL,
 };