linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Simone Piunno <pioppo@ferrara.linux.it>, Greg KH <greg@kroah.com>
Cc: LM Sensors <sensors@stimpy.netroedge.com>,
	"Jonas Munsin" <jmunsin@iki.fi>,
	djg@pdp8.net, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2.6] I2C: Allow it87 pwm reconfiguration
Date: Sat, 15 Jan 2005 16:30:45 +0100	[thread overview]
Message-ID: <20050115163045.2e636632.khali@linux-fr.org> (raw)
In-Reply-To: <g7Idbr9m.1105713630.9207120.khali@localhost>

Quoting myself:

> As soon as you will have confirmed that everything worked as expected,
> Jonas and I will provide a patch adding a pwm polarity reconfiguration
> module parameter for you to test. This should give you access to the
> PWM features of your it87 chip again, but in a safe way for a change
> ;)

Here comes this patch. The new "fix_pwm_polarity" module parameter
allows one to force the it87 chip reconfiguration. This is only
supported in the case the original PWM configuration is suspected to be
bogus, and only if we think that reconfiguring the chip is safe.

I wish to thank Rudolf Marek and Jonas Munsin again for their testing
and review of my code.

Greg, please apply, thanks.

Simone, feel free to test this (on top of 2.6.11-rc1-mm1 for example).


Signed-off-by: Jean Delvare <khali@linux-fr.org>

--- linux-2.6.11-rc1/drivers/i2c/chips/it87.c.orig	2005-01-14 18:37:07.000000000 +0100
+++ linux-2.6.11-rc1/drivers/i2c/chips/it87.c	2005-01-15 15:46:04.000000000 +0100
@@ -106,6 +106,9 @@
 /* Update battery voltage after every reading if true */
 static int update_vbat;
 
+/* Not all BIOSes properly configure the PWM registers */
+static int fix_pwm_polarity;
+
 /* Chip Type */
 
 static u16 chip_type;
@@ -226,6 +229,7 @@
 static int it87_write_value(struct i2c_client *client, u8 register,
 			u8 value);
 static struct it87_data *it87_update_device(struct device *dev);
+static int it87_check_pwm(struct i2c_client *client);
 static void it87_init_client(struct i2c_client *client, struct it87_data *data);
 
 
@@ -720,7 +724,6 @@
 	const char *name = "";
 	int is_isa = i2c_is_isa_adapter(adapter);
 	int enable_pwm_interface;
-	int tmp;
 
 	if (!is_isa && 
 	    !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -824,20 +827,12 @@
 	if ((err = i2c_attach_client(new_client)))
 		goto ERROR2;
 
+	/* Check PWM configuration */
+	enable_pwm_interface = it87_check_pwm(new_client);
+
 	/* Initialize the IT87 chip */
 	it87_init_client(new_client, data);
 
-	/* Some BIOSes fail to correctly configure the IT87 fans. All fans off
-	 * and polarity set to active low is sign that this is the case so we
-	 * disable pwm control to protect the user. */
-	enable_pwm_interface = 1;
-	tmp = it87_read_value(new_client, IT87_REG_FAN_CTL);
-	if ((tmp & 0x87) == 0) {
-		enable_pwm_interface = 0;
-		dev_info(&new_client->dev,
-			"detected broken BIOS defaults, disabling pwm interface");
-	}
-
 	/* Register sysfs hooks */
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
@@ -968,6 +963,56 @@
 		return i2c_smbus_write_byte_data(client, reg, value);
 }
 
+/* Return 1 if and only if the PWM interface is safe to use */
+static int it87_check_pwm(struct i2c_client *client)
+{
+	/* Some BIOSes fail to correctly configure the IT87 fans. All fans off
+	 * and polarity set to active low is sign that this is the case so we
+	 * disable pwm control to protect the user. */
+	int tmp = it87_read_value(client, IT87_REG_FAN_CTL);
+	if ((tmp & 0x87) == 0) {
+		if (fix_pwm_polarity) {
+			/* The user asks us to attempt a chip reconfiguration.
+			 * This means switching to active high polarity and
+			 * inverting all fan speed values. */
+			int i;
+			u8 pwm[3];
+
+			for (i = 0; i < 3; i++)
+				pwm[i] = it87_read_value(client,
+							 IT87_REG_PWM(i));
+
+			/* If any fan is in automatic pwm mode, the polarity
+			 * might be correct, as suspicious as it seems, so we
+			 * better don't change anything (but still disable the
+			 * PWM interface). */
+			if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
+				dev_info(&client->dev, "Reconfiguring PWM to "
+					 "active high polarity\n");
+				it87_write_value(client, IT87_REG_FAN_CTL,
+						 tmp | 0x87);
+				for (i = 0; i < 3; i++)
+					it87_write_value(client,
+							 IT87_REG_PWM(i),
+							 0x7f & ~pwm[i]);
+				return 1;
+			}
+
+			dev_info(&client->dev, "PWM configuration is "
+				 "too broken to be fixed\n");
+		}
+
+		dev_info(&client->dev, "Detected broken BIOS "
+			 "defaults, disabling PWM interface\n");
+		return 0;
+	} else if (fix_pwm_polarity) {
+		dev_info(&client->dev, "PWM configuration looks "
+			 "sane, won't touch\n");
+	}
+
+	return 1;
+}
+
 /* Called when we have found a new IT87. */
 static void it87_init_client(struct i2c_client *client, struct it87_data *data)
 {
@@ -1128,6 +1173,8 @@
 MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver");
 module_param(update_vbat, bool, 0);
 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
+module_param(fix_pwm_polarity, bool, 0);
+MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
 MODULE_LICENSE("GPL");
 
 module_init(sm_it87_init);

-- 
Jean Delvare
http://khali.linux-fr.org/

  reply	other threads:[~2005-01-15 15:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-08  0:50 2.6.10-mm2: it87 sensor driver stops CPU fan Simone Piunno
2005-01-08  9:34 ` Jean Delvare
2005-01-10 22:41   ` Simone Piunno
2005-01-11  9:26     ` Jean Delvare
2005-01-11 20:24       ` Jonas Munsin
2005-01-11 20:56         ` Jean Delvare
2005-01-11 22:41         ` Greg KH
2005-01-11 21:04       ` Simone Piunno
2005-01-12  9:44         ` Jean Delvare
2005-01-12 22:27       ` Jonas Munsin
2005-01-13 23:29         ` Greg KH
2005-01-14 14:40           ` Jean Delvare
2005-01-15 15:30             ` Jean Delvare [this message]
2005-01-15 17:18               ` [PATCH 2.6] I2C: Allow it87 pwm reconfiguration Simone Piunno
2005-01-19 23:23               ` Greg KH
2005-01-15 15:54             ` 2.6.10-mm2: it87 sensor driver stops CPU fan Simone Piunno
2005-01-15 16:55               ` Jean Delvare
2005-01-16 22:32                 ` Simone Piunno
2005-01-17 19:19                   ` Jean Delvare
2005-01-17 19:37                     ` 2.6 Series Mem Mgmt Chris Bookholt
2005-01-17 19:56                       ` Brian Gerst
2005-01-08 16:20 ` 2.6.10-mm2: it87 sensor driver stops CPU fan Jean Delvare
2005-01-08 19:23   ` Simone Piunno
2005-01-10 19:23     ` Simone Piunno
2005-01-10 19:34       ` Jean Delvare
2005-01-19 20:19         ` Nicolas Pitre
2005-01-19 20:52           ` Jean Delvare
2005-01-19 22:10             ` Nicolas Pitre
2005-01-20 11:08               ` Jean Delvare
2005-01-20 16:01                 ` Nicolas Pitre
2005-01-20 16:28                   ` Jean Delvare
2005-01-20 21:19                     ` Nicolas Pitre
2005-01-21  6:46                       ` Jean Delvare

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=20050115163045.2e636632.khali@linux-fr.org \
    --to=khali@linux-fr.org \
    --cc=djg@pdp8.net \
    --cc=greg@kroah.com \
    --cc=jmunsin@iki.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pioppo@ferrara.linux.it \
    --cc=sensors@stimpy.netroedge.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).