Merge branch 'bpf-helper-cleanups'
[deliverable/linux.git] / drivers / hwmon / dell-smm-hwmon.c
index 2ac87d553e22f67ebaca32d62fb76375e3d22bdc..acf9c0361d9f7e16f639fbbfeac642b1ca5258b5 100644 (file)
@@ -81,6 +81,7 @@ static bool disallow_fan_type_call;
 #define I8K_HWMON_HAVE_TEMP4   (1 << 3)
 #define I8K_HWMON_HAVE_FAN1    (1 << 4)
 #define I8K_HWMON_HAVE_FAN2    (1 << 5)
+#define I8K_HWMON_HAVE_FAN3    (1 << 6)
 
 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
@@ -139,6 +140,14 @@ static int i8k_smm(struct smm_regs *regs)
        int eax = regs->eax;
        cpumask_var_t old_mask;
 
+#ifdef DEBUG
+       int ebx = regs->ebx;
+       unsigned long duration;
+       ktime_t calltime, delta, rettime;
+
+       calltime = ktime_get();
+#endif
+
        /* SMM requires CPU 0 */
        if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
                return -ENOMEM;
@@ -210,6 +219,15 @@ static int i8k_smm(struct smm_regs *regs)
 out:
        set_cpus_allowed_ptr(current, old_mask);
        free_cpumask_var(old_mask);
+
+#ifdef DEBUG
+       rettime = ktime_get();
+       delta = ktime_sub(rettime, calltime);
+       duration = ktime_to_ns(delta) >> 10;
+       pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x  (took %7lu usecs)\n", eax, ebx,
+               (rc ? 0xffff : regs->eax & 0xffff), duration);
+#endif
+
        return rc;
 }
 
@@ -252,7 +270,7 @@ static int _i8k_get_fan_type(int fan)
 static int i8k_get_fan_type(int fan)
 {
        /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
-       static int types[2] = { INT_MIN, INT_MIN };
+       static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
 
        if (types[fan] == INT_MIN)
                types[fan] = _i8k_get_fan_type(fan);
@@ -719,6 +737,12 @@ static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
                          1);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
                          i8k_hwmon_set_pwm, 1);
+static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
+                         2);
+static SENSOR_DEVICE_ATTR(fan3_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
+                         2);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
+                         i8k_hwmon_set_pwm, 2);
 
 static struct attribute *i8k_attrs[] = {
        &sensor_dev_attr_temp1_input.dev_attr.attr,     /* 0 */
@@ -735,6 +759,9 @@ static struct attribute *i8k_attrs[] = {
        &sensor_dev_attr_fan2_input.dev_attr.attr,      /* 11 */
        &sensor_dev_attr_fan2_label.dev_attr.attr,      /* 12 */
        &sensor_dev_attr_pwm2.dev_attr.attr,            /* 13 */
+       &sensor_dev_attr_fan3_input.dev_attr.attr,      /* 14 */
+       &sensor_dev_attr_fan3_label.dev_attr.attr,      /* 15 */
+       &sensor_dev_attr_pwm3.dev_attr.attr,            /* 16 */
        NULL
 };
 
@@ -742,7 +769,7 @@ static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
                              int index)
 {
        if (disallow_fan_type_call &&
-           (index == 9 || index == 12))
+           (index == 9 || index == 12 || index == 15))
                return 0;
        if (index >= 0 && index <= 1 &&
            !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
@@ -762,6 +789,9 @@ static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
        if (index >= 11 && index <= 13 &&
            !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
                return 0;
+       if (index >= 14 && index <= 16 &&
+           !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
+               return 0;
 
        return attr->mode;
 }
@@ -807,6 +837,13 @@ static int __init i8k_init_hwmon(void)
        if (err >= 0)
                i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
 
+       /* Third fan attributes, if fan status or type is OK */
+       err = i8k_get_fan_status(2);
+       if (err < 0)
+               err = i8k_get_fan_type(2);
+       if (err >= 0)
+               i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
+
        i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
                                                          NULL, i8k_groups);
        if (IS_ERR(i8k_hwmon_dev)) {
This page took 0.031634 seconds and 5 git commands to generate.