From: Guenter Roeck <linux@roeck-us.net>
To: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org,
Guenter Roeck <linux@roeck-us.net>,
Jean Delvare <khali@linux-fr.org>
Subject: [PATCH 14/14] i8k: Implement hwmon based fan speed control
Date: Sat, 14 Dec 2013 09:30:21 -0800 [thread overview]
Message-ID: <1387042221-3671-15-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1387042221-3671-1-git-send-email-linux@roeck-us.net>
Fan speed can be set to off, slow, and fast, which can be exported
to userspace through the hwmon ABI as pwm1 / pwm2.
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/char/i8k.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index ce826d9..70c8df2 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -509,6 +509,39 @@ static ssize_t i8k_hwmon_show_fan(struct device *dev,
return sprintf(buf, "%d\n", fan_speed);
}
+static ssize_t i8k_hwmon_show_pwm(struct device *dev,
+ struct device_attribute *devattr,
+ char *buf)
+{
+ int index = to_sensor_dev_attr(devattr)->index;
+ int status;
+
+ status = i8k_get_fan_status(index);
+ if (status < 0)
+ return -EIO;
+ return sprintf(buf, "%d\n", clamp_val(status * 128, 0, 255));
+}
+
+static ssize_t i8k_hwmon_set_pwm(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int index = to_sensor_dev_attr(attr)->index;
+ unsigned long val;
+ int err;
+
+ err = kstrtoul(buf, 10, &val);
+ if (err)
+ return err;
+ val = clamp_val(DIV_ROUND_CLOSEST(val, 128), 0, 2);
+
+ mutex_lock(&i8k_mutex);
+ err = i8k_set_fan(index, val);
+ mutex_unlock(&i8k_mutex);
+
+ return err < 0 ? -EIO : count;
+}
+
static ssize_t i8k_hwmon_show_label(struct device *dev,
struct device_attribute *devattr,
char *buf)
@@ -529,8 +562,12 @@ static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
I8K_FAN_LEFT);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
+ i8k_hwmon_set_pwm, I8K_FAN_LEFT);
static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
I8K_FAN_RIGHT);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
+ i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
@@ -542,9 +579,11 @@ static struct attribute *i8k_attrs[] = {
&sensor_dev_attr_temp3_input.dev_attr.attr, /* 3 */
&sensor_dev_attr_temp4_input.dev_attr.attr, /* 4 */
&sensor_dev_attr_fan1_input.dev_attr.attr, /* 5 */
- &sensor_dev_attr_fan1_label.dev_attr.attr, /* 6 */
- &sensor_dev_attr_fan2_input.dev_attr.attr, /* 7 */
- &sensor_dev_attr_fan2_label.dev_attr.attr, /* 8 */
+ &sensor_dev_attr_pwm1.dev_attr.attr, /* 6 */
+ &sensor_dev_attr_fan1_label.dev_attr.attr, /* 7 */
+ &sensor_dev_attr_fan2_input.dev_attr.attr, /* 8 */
+ &sensor_dev_attr_pwm2.dev_attr.attr, /* 9 */
+ &sensor_dev_attr_fan2_label.dev_attr.attr, /* 10 */
NULL
};
@@ -560,10 +599,10 @@ static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
return 0;
if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
return 0;
- if ((index == 5 || index == 6) &&
+ if (index >= 5 && index <= 7 &&
!(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
return 0;
- if ((index == 7 || index == 8) &&
+ if (index >= 8 && index <= 10 &&
!(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
return 0;
--
1.7.9.7
next prev parent reply other threads:[~2013-12-14 17:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-14 17:30 [PATCH 00/12] i8k patch series Guenter Roeck
2013-12-14 17:30 ` [PATCH 01/14] i8k: Convert to use pr_ functions instead of printk Guenter Roeck
2013-12-14 17:30 ` [PATCH 02/14] i8k: Fix various checkpatch warnings and errors Guenter Roeck
2013-12-14 17:30 ` [PATCH 03/14] i8k: Convert to use to hwmon_device_register_with_groups hwmon API Guenter Roeck
2013-12-14 17:30 ` [PATCH 04/14] i8k: Support additional temperature sensors Guenter Roeck
2013-12-14 17:30 ` [PATCH 05/14] MAINTAINERS: Add myself as i8k maintainer Guenter Roeck
2013-12-14 17:30 ` [PATCH 06/14] i8k: Remove obsolete link to out-of-tree driver Guenter Roeck
2013-12-14 17:30 ` [PATCH 07/14] i8k: Drop driver version number and info message at startup Guenter Roeck
2013-12-14 17:30 ` [PATCH 08/14] i8k: Force SMM to run on CPU 0 Guenter Roeck
2013-12-14 17:30 ` [PATCH 09/14] i8k: Add copyright Guenter Roeck
2013-12-14 17:30 ` [PATCH 10/14] i8k: Add support for Dell Studio laptops Guenter Roeck
2013-12-14 17:30 ` [PATCH 11/14] i8k: Add support for Dell XPS M140 Guenter Roeck
2013-12-14 17:30 ` [PATCH 12/14] i8k: Use driver_data field of dmi_system_id to override fan multiplier Guenter Roeck
2013-12-14 17:30 ` [PATCH 13/14] i8k: Stop reading SMM BIOS version during driver probe Guenter Roeck
2013-12-14 17:30 ` Guenter Roeck [this message]
2013-12-14 17:38 ` [PATCH 00/12] i8k patch series Guenter Roeck
2013-12-14 18:45 ` Arnd Bergmann
2013-12-14 19:03 ` [lm-sensors] " Jean Delvare
2013-12-14 19:50 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1387042221-3671-15-git-send-email-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox