All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: "Jean Delvare" <jdelvare@suse.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jan C Peters" <jcpeters89@gmail.com>,
	"Thorsten Leemhuis" <fedora@leemhuis.info>,
	"David Santamaría Rogado" <howl.nsp@gmail.com>,
	"Peter Saunderson" <peteasa@gmail.com>,
	"Tolga Cakir" <cevelnet@gmail.com>,
	"Austin S. Hemmelgarn" <ahferroin7@gmail.com>,
	Mario_Limonciello@dell.com,
	"Gabriele Mazzotta" <gabriele.mzt@gmail.com>,
	"Michał Kępień" <kernel@kempniu.pl>,
	"Dakota Whipple" <dakotajaywhipple@gmail.com>,
	"Leon Yu" <leon@leonyu.net>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Pali Rohár" <pali.rohar@gmail.com>
Subject: [PATCH 5/6] hwmon: (dell-smm) Detect fan with index=2
Date: Sat, 18 Jun 2016 00:54:48 +0200	[thread overview]
Message-ID: <1466204089-17030-6-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1466204089-17030-1-git-send-email-pali.rohar@gmail.com>

Some Dell machines (e.g. Dell Precision M3800) have two fans, first with
index=0 and second with index=2. So export also attributes for third fan
device with index=2.

Reported-by: Tolga Cakir <cevelnet@gmail.com>
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
 drivers/hwmon/dell-smm-hwmon.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
index 2ac87d5..571d498 100644
--- a/drivers/hwmon/dell-smm-hwmon.c
+++ b/drivers/hwmon/dell-smm-hwmon.c
@@ -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>");
@@ -252,7 +253,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 +720,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 +742,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 +752,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 +772,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 +820,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)) {
-- 
1.7.9.5


  parent reply	other threads:[~2016-06-17 22:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17 22:54 [PATCH 0/6] dell-smm-hwmon fixes Pali Rohár
2016-06-17 22:54 ` [PATCH 1/6] hwmon: (dell-smm) Fail in ioctl I8K_BIOS_VERSION when bios version is not a number Pali Rohár
2016-06-18 20:00   ` Guenter Roeck
2016-06-17 22:54 ` [PATCH 2/6] hwmon: (dell-smm) Restrict fan control and serial number to CAP_SYS_ADMIN by default Pali Rohár
2016-06-18 20:00   ` Guenter Roeck
2016-06-17 22:54 ` [PATCH 3/6] hwmon: (dell-smm) Disallow fan_type() calls on broken machines Pali Rohár
2016-06-18 20:08   ` Guenter Roeck
2016-06-18 22:46     ` Pali Rohár
2016-06-17 22:54 ` [PATCH 4/6] hwmon: (dell-smm) Cache fan_type() calls and change fan detection Pali Rohár
2016-06-19  0:01   ` Tolga Cakir
2016-06-17 22:54 ` Pali Rohár [this message]
2016-06-19  0:02   ` [PATCH 5/6] hwmon: (dell-smm) Detect fan with index=2 Tolga Cakir
2016-06-17 22:54 ` [PATCH 6/6] hwmon: (dell-smm) In debug mode log duration of SMM calls Pali Rohár
2016-06-18 12:21 ` [PATCH 0/6] dell-smm-hwmon fixes Pali Rohár
2016-06-18 15:13 ` Guenter Roeck
2016-06-18 15:26   ` Pali Rohár
2016-06-18 16:54     ` Guenter Roeck
2016-06-18 22:39       ` Pali Rohár
2016-06-20  9:12         ` Pali Rohár
2016-06-20 13:24           ` Guenter Roeck
2016-06-23 12:16             ` Pali Rohár
2016-06-23 13:51               ` Guenter Roeck
     [not found]       ` <CA+vQ2zCoGhLT2PUUhcuggJ3oE9Z6vfUW=Z1wgm8Ozz3XdnQoxA@mail.gmail.com>
2016-06-18 22:44         ` Pali Rohár
2016-06-22  8:02 ` Michał Kępień

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=1466204089-17030-6-git-send-email-pali.rohar@gmail.com \
    --to=pali.rohar@gmail.com \
    --cc=Mario_Limonciello@dell.com \
    --cc=ahferroin7@gmail.com \
    --cc=cevelnet@gmail.com \
    --cc=dakotajaywhipple@gmail.com \
    --cc=fedora@leemhuis.info \
    --cc=gabriele.mzt@gmail.com \
    --cc=howl.nsp@gmail.com \
    --cc=jcpeters89@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=kernel@kempniu.pl \
    --cc=leon@leonyu.net \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=peteasa@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.