All of lore.kernel.org
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: linux-kernel@vger.kernel.org, sensors@Stimpy.netroedge.com
Cc: aurelien@aurel32.net
Subject: [PATCH] I2C: lm78 driver improvement
Date: Thu, 19 May 2005 06:25:41 +0000	[thread overview]
Message-ID: <11099685942479@kroah.com> (raw)
In-Reply-To: <1109968594850@kroah.com>

ChangeSet 1.2091, 2005/03/02 12:04:28-08:00, aurelien@aurel32.net

[PATCH] I2C: lm78 driver improvement

The following patch against kernel 2.6.11-rc2-mm1 improves the lm78
driver. I used it as a model to port the sis5595 driver to the 2.6
kernel, and I then applied the changes suggested by Jean Delvare on
the sis5595 driver to this one.


Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 drivers/i2c/chips/lm78.c |   53 +++++++++++++++++++++--------------------------
 1 files changed, 24 insertions(+), 29 deletions(-)


diff -Nru a/drivers/i2c/chips/lm78.c b/drivers/i2c/chips/lm78.c
--- a/drivers/i2c/chips/lm78.c	2005-03-04 12:25:31 -08:00
+++ b/drivers/i2c/chips/lm78.c	2005-03-04 12:25:31 -08:00
@@ -81,9 +81,8 @@
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm = 0)
+	if (rpm <= 0)
 		return 255;
-	rpm = SENSORS_LIMIT(rpm, 1, 1000000);
 	return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
@@ -94,15 +93,15 @@
 
 /* TEMP: mC (-128C to +127C)
    REG: 1C/bit, two's complement */
-static inline u8 TEMP_TO_REG(int val)
+static inline s8 TEMP_TO_REG(int val)
 {
 	int nval = SENSORS_LIMIT(val, -128000, 127000) ;
-	return nval<0 ? (nval-500)/1000+0x100 : (nval+500)/1000;
+	return nval<0 ? (nval-500)/1000 : (nval+500)/1000;
 }
 
-static inline int TEMP_FROM_REG(u8 val)
+static inline int TEMP_FROM_REG(s8 val)
 {
-	return (val>=0x80 ? val-0x100 : val) * 1000;
+	return val * 1000;
 }
 
 /* VID: mV
@@ -112,16 +111,6 @@
 	return val=0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
 }
 
-/* ALARMS: chip-specific bitmask
-   REG: (same) */
-#define ALARMS_FROM_REG(val) (val)
-
-/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
-   REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
-static inline u8 DIV_TO_REG(int val)
-{
-	return val=8 ? 3 : val=4 ? 2 : val=1 ? 0 : 1;
-}
 #define DIV_FROM_REG(val) (1 << (val))
 
 /* There are some complications in a module like this. First off, LM78 chips
@@ -157,9 +146,9 @@
 	u8 in_min[7];		/* Register value */
 	u8 fan[3];		/* Register value */
 	u8 fan_min[3];		/* Register value */
-	u8 temp;		/* Register value */
-	u8 temp_over;		/* Register value */
-	u8 temp_hyst;		/* Register value */
+	s8 temp;		/* Register value */
+	s8 temp_over;		/* Register value */
+	s8 temp_hyst;		/* Register value */
 	u8 fan_div[3];		/* Register encoding, shifted right */
 	u8 vid;			/* Register encoding, combined */
 	u16 alarms;		/* Register encoding, combined */
@@ -357,7 +346,17 @@
 			DIV_FROM_REG(data->fan_div[nr]));
 	unsigned long val = simple_strtoul(buf, NULL, 10);
 	int reg = lm78_read_value(client, LM78_REG_VID_FANDIV);
-	data->fan_div[nr] = DIV_TO_REG(val);
+	switch (val) {
+	case 1: data->fan_div[nr] = 0; break;
+	case 2: data->fan_div[nr] = 1; break;
+	case 4: data->fan_div[nr] = 2; break;
+	case 8: data->fan_div[nr] = 3; break;
+	default:
+		dev_err(&client->dev, "fan_div value %ld not "
+			"supported. Choose one of 1, 2, 4 or 8!\n", val);
+		return -EINVAL;
+	}
+
 	switch (nr) {
 	case 0:
 		reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
@@ -430,7 +429,7 @@
 static ssize_t show_alarms(struct device *dev, char *buf)
 {
 	struct lm78_data *data = lm78_update_device(dev);
-	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
+	return sprintf(buf, "%u\n", data->alarms);
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
@@ -633,17 +632,15 @@
 {
 	int err;
 
-	/* release ISA region first */
-	if(i2c_is_isa_client(client))
-		release_region(client->addr, LM78_EXTENT);
-
-	/* now it's safe to scrap the rest */
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		    "Client deregistration failed, client not detached.\n");
 		return err;
 	}
 
+	if(i2c_is_isa_client(client))
+		release_region(client->addr, LM78_EXTENT);
+
 	kfree(i2c_get_clientdata(client));
 
 	return 0;
@@ -653,9 +650,7 @@
    We don't want to lock the whole ISA bus, so we lock each client
    separately.
    We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
-   would slow down the LM78 access and should not be necessary. 
-   There are some ugly typecasts here, but the good new is - they should
-   nowhere else be necessary! */
+   would slow down the LM78 access and should not be necessary.  */
 static int lm78_read_value(struct i2c_client *client, u8 reg)
 {
 	int res;


WARNING: multiple messages have this Message-ID (diff)
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, sensors@Stimpy.netroedge.com
Cc: aurelien@aurel32.net
Subject: [PATCH] I2C: lm78 driver improvement
Date: Fri, 4 Mar 2005 12:36:34 -0800	[thread overview]
Message-ID: <11099685942479@kroah.com> (raw)
In-Reply-To: <1109968594850@kroah.com>

ChangeSet 1.2091, 2005/03/02 12:04:28-08:00, aurelien@aurel32.net

[PATCH] I2C: lm78 driver improvement

The following patch against kernel 2.6.11-rc2-mm1 improves the lm78
driver. I used it as a model to port the sis5595 driver to the 2.6
kernel, and I then applied the changes suggested by Jean Delvare on
the sis5595 driver to this one.


Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 drivers/i2c/chips/lm78.c |   53 +++++++++++++++++++++--------------------------
 1 files changed, 24 insertions(+), 29 deletions(-)


diff -Nru a/drivers/i2c/chips/lm78.c b/drivers/i2c/chips/lm78.c
--- a/drivers/i2c/chips/lm78.c	2005-03-04 12:25:31 -08:00
+++ b/drivers/i2c/chips/lm78.c	2005-03-04 12:25:31 -08:00
@@ -81,9 +81,8 @@
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm == 0)
+	if (rpm <= 0)
 		return 255;
-	rpm = SENSORS_LIMIT(rpm, 1, 1000000);
 	return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
@@ -94,15 +93,15 @@
 
 /* TEMP: mC (-128C to +127C)
    REG: 1C/bit, two's complement */
-static inline u8 TEMP_TO_REG(int val)
+static inline s8 TEMP_TO_REG(int val)
 {
 	int nval = SENSORS_LIMIT(val, -128000, 127000) ;
-	return nval<0 ? (nval-500)/1000+0x100 : (nval+500)/1000;
+	return nval<0 ? (nval-500)/1000 : (nval+500)/1000;
 }
 
-static inline int TEMP_FROM_REG(u8 val)
+static inline int TEMP_FROM_REG(s8 val)
 {
-	return (val>=0x80 ? val-0x100 : val) * 1000;
+	return val * 1000;
 }
 
 /* VID: mV
@@ -112,16 +111,6 @@
 	return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
 }
 
-/* ALARMS: chip-specific bitmask
-   REG: (same) */
-#define ALARMS_FROM_REG(val) (val)
-
-/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
-   REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
-static inline u8 DIV_TO_REG(int val)
-{
-	return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
-}
 #define DIV_FROM_REG(val) (1 << (val))
 
 /* There are some complications in a module like this. First off, LM78 chips
@@ -157,9 +146,9 @@
 	u8 in_min[7];		/* Register value */
 	u8 fan[3];		/* Register value */
 	u8 fan_min[3];		/* Register value */
-	u8 temp;		/* Register value */
-	u8 temp_over;		/* Register value */
-	u8 temp_hyst;		/* Register value */
+	s8 temp;		/* Register value */
+	s8 temp_over;		/* Register value */
+	s8 temp_hyst;		/* Register value */
 	u8 fan_div[3];		/* Register encoding, shifted right */
 	u8 vid;			/* Register encoding, combined */
 	u16 alarms;		/* Register encoding, combined */
@@ -357,7 +346,17 @@
 			DIV_FROM_REG(data->fan_div[nr]));
 	unsigned long val = simple_strtoul(buf, NULL, 10);
 	int reg = lm78_read_value(client, LM78_REG_VID_FANDIV);
-	data->fan_div[nr] = DIV_TO_REG(val);
+	switch (val) {
+	case 1: data->fan_div[nr] = 0; break;
+	case 2: data->fan_div[nr] = 1; break;
+	case 4: data->fan_div[nr] = 2; break;
+	case 8: data->fan_div[nr] = 3; break;
+	default:
+		dev_err(&client->dev, "fan_div value %ld not "
+			"supported. Choose one of 1, 2, 4 or 8!\n", val);
+		return -EINVAL;
+	}
+
 	switch (nr) {
 	case 0:
 		reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
@@ -430,7 +429,7 @@
 static ssize_t show_alarms(struct device *dev, char *buf)
 {
 	struct lm78_data *data = lm78_update_device(dev);
-	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
+	return sprintf(buf, "%u\n", data->alarms);
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
@@ -633,17 +632,15 @@
 {
 	int err;
 
-	/* release ISA region first */
-	if(i2c_is_isa_client(client))
-		release_region(client->addr, LM78_EXTENT);
-
-	/* now it's safe to scrap the rest */
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		    "Client deregistration failed, client not detached.\n");
 		return err;
 	}
 
+	if(i2c_is_isa_client(client))
+		release_region(client->addr, LM78_EXTENT);
+
 	kfree(i2c_get_clientdata(client));
 
 	return 0;
@@ -653,9 +650,7 @@
    We don't want to lock the whole ISA bus, so we lock each client
    separately.
    We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
-   would slow down the LM78 access and should not be necessary. 
-   There are some ugly typecasts here, but the good new is - they should
-   nowhere else be necessary! */
+   would slow down the LM78 access and should not be necessary.  */
 static int lm78_read_value(struct i2c_client *client, u8 reg)
 {
 	int res;


  reply	other threads:[~2005-05-19  6:25 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-04 20:35 [BK PATCH] I2C patches for 2.6.11 Greg KH
2005-03-04 20:36 ` [PATCH] I2C: add fscpos chip driver Greg KH
2005-05-19  6:25   ` Greg KH
2005-03-04 20:36   ` [PATCH] I2C: Allow it87 pwm reconfiguration Greg KH
2005-05-19  6:25     ` Greg KH
2005-03-04 20:36     ` [PATCH] I2C: Fix up some build warnings in the fscpos driver Greg KH
2005-05-19  6:25       ` Greg KH
2005-03-04 20:36       ` [PATCH] I2C: Kill i2c_client.id (1/5) Greg KH
2005-05-19  6:25         ` Greg KH
2005-03-04 20:36         ` [PATCH] I2C: Kill i2c_client.id (2/5) Greg KH
2005-05-19  6:25           ` Greg KH
2005-03-04 20:36           ` [PATCH] I2C: Kill i2c_client.id (3/5) Greg KH
2005-05-19  6:25             ` Greg KH
2005-03-04 20:36             ` [PATCH] I2C: Kill i2c_client.id (4/5) Greg KH
2005-05-19  6:25               ` Greg KH
2005-03-04 20:36               ` [PATCH] I2C: Kill i2c_client.id (5/5) Greg KH
2005-05-19  6:25                 ` Greg KH
2005-03-04 20:36                 ` [PATCH] I2C: just delete the id field, let's not delay it any longer Greg KH
2005-05-19  6:25                   ` Greg KH
2005-03-04 20:36                   ` [PATCH] I2C: fix for fscpos voltage values Greg KH
2005-05-19  6:25                     ` Greg KH
2005-03-04 20:36                     ` [PATCH] I2C: i2c-dev namespace cleanup Greg KH
2005-05-19  6:25                       ` Greg KH
2005-03-04 20:36                       ` Greg KH [this message]
2005-05-19  6:25                         ` [PATCH] I2C: lm78 driver improvement Greg KH
2005-03-04 20:36                         ` [PATCH] I2C: Enable w83781d and w83627hf temperature channels Greg KH
2005-03-04 20:36                           ` [PATCH] I2C: Kill unused includes in i2c-sensor-detect.c Greg KH
2005-03-04 20:36                             ` [PATCH] I2C: unnecessary #includes in asb100.c Greg KH
2005-05-19  6:25                               ` Greg KH
2005-03-04 20:36                               ` [PATCH] I2C: lm80 driver improvement Greg KH
2005-05-19  6:25                                 ` Greg KH
2005-03-04 20:36                                 ` [PATCH] i2c-core.c: make some code static Greg KH
2005-05-19  6:25                                   ` Greg KH
2005-03-04 20:36                                   ` [PATCH] I2C: use time_after instead of comparing jiffies Greg KH
2005-03-04 20:36                                     ` [PATCH] I2C: add ST M41T00 I2C RTC chip driver Greg KH
2005-03-04 20:36                                       ` [PATCH] I2C: New chip driver: sis5595 Greg KH
2005-05-19  6:25                                         ` Greg KH
2005-03-04 20:36                                         ` [PATCH] I2C: add Marvell mv64xxx i2c driver Greg KH
2005-03-04 20:36                                           ` [PATCH] I2C: add GL520SM Sensor Chip driver Greg KH
2005-03-04 20:36                                             ` [PATCH] I2C: improve debugging output Greg KH
2005-05-19  6:25                                               ` Greg KH
2005-03-04 20:36                                               ` [PATCH] I2C: Enable I2C_PIIX4 for 64-bit platforms Greg KH
2005-03-04 20:36                                                 ` [PATCH] I2C: fix typo in drivers/i2c/busses/i2c-ixp4xx.c Greg KH
2005-05-19  6:25                                                   ` Greg KH
2005-03-04 20:36                                                   ` [PATCH] I2C i2c-nforce2: add support for nForce4 (patch against 2.6.11-rc4) Greg KH
2005-05-19  6:25                                                     ` [PATCH] I2C i2c-nforce2: add support for nForce4 (patch against Greg KH
2005-03-04 20:36                                                     ` [PATCH] I2C: Remove NULL client checks in rtc8564 driver Greg KH
2005-05-19  6:25                                                       ` Greg KH
2005-03-04 20:36                                                       ` [PATCH] I2C: Make i2c list terminators explicitely unsigned Greg KH
2005-05-19  6:25                                                         ` Greg KH
2005-03-04 20:36                                                         ` [PATCH] I2C: Fix some gcc 4.0 compile failures and warnings Greg KH
2005-05-19  6:25                                                           ` Greg KH
2005-03-04 20:36                                                           ` [PATCH] I2C: S3C2410 missing I2C_CLASS_HWMON Greg KH
2005-05-19  6:25                                                             ` Greg KH
2005-03-04 20:36                                                             ` [PATCH] I2C: minor I2C cleanups Greg KH
2005-05-19  6:25                                                               ` Greg KH
2005-03-04 20:36                                                               ` [PATCH] Add class definition to the elektor bus driver Greg KH
2005-05-19  6:25                                                                 ` Greg KH
2005-03-04 20:36                                                                 ` [PATCH] I2C: saa7146 build fix Greg KH
2005-05-19  6:25                                                                   ` Greg KH
2005-03-04 20:36                                                                   ` [PATCH] I2C: w83627hf needs i2c-isa Greg KH
2005-05-19  6:25                                                                     ` Greg KH
2005-03-04 20:36                                                                     ` [PATCH] I2C: fixed up the i2c-id.h algo ids Greg KH
2005-05-19  6:25                                                                       ` Greg KH
2005-03-04 20:36                                                                       ` [PATCH] I2C: Change of i2c co-maintainer Greg KH
2005-05-19  6:25                                                                         ` Greg KH
2005-03-04 20:36                                                                         ` [PATCH] I2C: Trivial indentation fix in i2c/chips/Kconfig Greg KH
2005-03-04 22:55                                                           ` [PATCH] I2C: Fix some gcc 4.0 compile failures and warnings Mickey Stein
2005-05-19  6:25                                                             ` Mickey Stein
2005-03-04 23:02                                                             ` Greg KH
2005-05-19  6:25                                                               ` Greg KH
2005-03-05  5:57                                 ` [RFQ] Rules for accepting patches into the linux-releases tree Shawn Starr
2005-03-05  6:11                                   ` Randy.Dunlap
2005-03-05 16:33                                   ` Greg KH
2005-03-24  6:39                                 ` [2.6.11.5][BUILD] i2c.h breakage in 2.6.12-rc1 + -mm only Shawn Starr
2005-03-24  8:03                                   ` Greg KH
2005-03-05 11:59 ` [BK PATCH] I2C patches for 2.6.11 Jean Delvare
2005-03-06  6:55   ` Greg KH
2005-03-07  8:50     ` Adrian Bunk
2005-03-08  8:41     ` Domen Puncer

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=11099685942479@kroah.com \
    --to=greg@kroah.com \
    --cc=aurelien@aurel32.net \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.