All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal
@ 2012-07-26 12:57 Jean Delvare
  2012-07-26 13:37 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jean Delvare @ 2012-07-26 12:57 UTC (permalink / raw)
  To: lm-sensors

Restoring the configuration register on device removal has the side
effect of also resetting the hysteresis value. This is inconsistent as
the other limits are not reset, only hysteresis. So, following the
principle of least surprise, preserve the hysteresis value when
restoring the configuration register.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Guenter Roeck <linux@roeck-us.net>
---
Note: this would be more readable if JC42_CFG_HYST_MASK was the mask
_before_ shifting instead of after shifting. Guenter, do you want me
to send a separate patch doing that, or do you like it the way it is?

Alternatively we could invert the logic and only restore the
JC42_CFG_SHUTDOWN bit. As this bit and the two hysteresis bits are the
only ones the driver touches, this is equivalent. I don't know if
there is an intent to ever have the jc42 driver touch any other bit in
the configuration register. Guenter, I am leaving the decision up to
you.

 drivers/hwmon/jc42.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

--- linux-3.5.orig/drivers/hwmon/jc42.c	2012-07-25 15:33:28.000000000 +0200
+++ linux-3.5/drivers/hwmon/jc42.c	2012-07-26 14:51:32.609121347 +0200
@@ -535,9 +535,18 @@ static int jc42_remove(struct i2c_client
 	struct jc42_data *data = i2c_get_clientdata(client);
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &jc42_group);
-	if (data->config != data->orig_config)
-		i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
-					     data->orig_config);
+
+	/* Restore original configuration except hysteresis */
+	if ((data->config & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT)) !+	    (data->orig_config &
+	     ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))) {
+		int config = data->orig_config;
+
+		config &= ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT);
+		config |= data->config |
+			  (JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT);
+		i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
+	}
 	return 0;
 }
 


-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal
  2012-07-26 12:57 [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal Jean Delvare
@ 2012-07-26 13:37 ` Guenter Roeck
  2012-07-26 19:59 ` Jean Delvare
  2012-07-26 21:11 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2012-07-26 13:37 UTC (permalink / raw)
  To: lm-sensors

On Thu, Jul 26, 2012 at 02:57:45PM +0200, Jean Delvare wrote:
> Restoring the configuration register on device removal has the side
> effect of also resetting the hysteresis value. This is inconsistent as
> the other limits are not reset, only hysteresis. So, following the
> principle of least surprise, preserve the hysteresis value when
> restoring the configuration register.
> 
> Signed-off-by: Jean Delvare <khali@linux-fr.org>
> Cc: Guenter Roeck <linux@roeck-us.net>

Good catch. Applied.

> ---
> Note: this would be more readable if JC42_CFG_HYST_MASK was the mask
> _before_ shifting instead of after shifting. Guenter, do you want me
> to send a separate patch doing that, or do you like it the way it is?
> 
Please send a patch.

> Alternatively we could invert the logic and only restore the
> JC42_CFG_SHUTDOWN bit. As this bit and the two hysteresis bits are the
> only ones the driver touches, this is equivalent. I don't know if
> there is an intent to ever have the jc42 driver touch any other bit in
> the configuration register. Guenter, I am leaving the decision up to
> you.
> 
Hard to say, though looking into it seems unlikely. But who knows. I would
suggest to keep it generic as you implemented.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal
  2012-07-26 12:57 [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal Jean Delvare
  2012-07-26 13:37 ` Guenter Roeck
@ 2012-07-26 19:59 ` Jean Delvare
  2012-07-26 21:11 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Jean Delvare @ 2012-07-26 19:59 UTC (permalink / raw)
  To: lm-sensors

SGkgR3VlbnRlciwKCk9uIFRodSwgMjYgSnVsIDIwMTIgMDY6Mzc6NTAgLTA3MDAsIEd1ZW50ZXIg
Um9lY2sgd3JvdGU6Cj4gT24gVGh1LCBKdWwgMjYsIDIwMTIgYXQgMDI6NTc6NDVQTSArMDIwMCwg
SmVhbiBEZWx2YXJlIHdyb3RlOgo+ID4gUmVzdG9yaW5nIHRoZSBjb25maWd1cmF0aW9uIHJlZ2lz
dGVyIG9uIGRldmljZSByZW1vdmFsIGhhcyB0aGUgc2lkZQo+ID4gZWZmZWN0IG9mIGFsc28gcmVz
ZXR0aW5nIHRoZSBoeXN0ZXJlc2lzIHZhbHVlLiBUaGlzIGlzIGluY29uc2lzdGVudCBhcwo+ID4g
dGhlIG90aGVyIGxpbWl0cyBhcmUgbm90IHJlc2V0LCBvbmx5IGh5c3RlcmVzaXMuIFNvLCBmb2xs
b3dpbmcgdGhlCj4gPiBwcmluY2lwbGUgb2YgbGVhc3Qgc3VycHJpc2UsIHByZXNlcnZlIHRoZSBo
eXN0ZXJlc2lzIHZhbHVlIHdoZW4KPiA+IHJlc3RvcmluZyB0aGUgY29uZmlndXJhdGlvbiByZWdp
c3Rlci4KPiA+IAo+ID4gU2lnbmVkLW9mZi1ieTogSmVhbiBEZWx2YXJlIDxraGFsaUBsaW51eC1m
ci5vcmc+Cj4gPiBDYzogR3VlbnRlciBSb2VjayA8bGludXhAcm9lY2stdXMubmV0Pgo+IAo+IEdv
b2QgY2F0Y2guIEFwc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gaXMgYW4gaW50ZW50IHRvIGV2ZXIgaGF2
ZSB0aGUgamM0MiBkcml2ZXIgdG91Y2ggYW55IG90aGVyIGJpdCBpbgo+ID4gdGhlIGNvbmZpZ3Vy
YXRpb24gcmVnaXN0ZXIuIEd1ZW50ZXIsIEkgYW0gbGVhdmluZyB0aGUgZGVjaXNpb24gdXAgdG8K
PiA+IHlvdS4KPgo+IEhhcmQgdG8gc2F5LCB0aG91Z2ggbG9va2luZyBpbnRvIGl0IHNlZW1zIHVu
bGlrZWx5LiBCdXQgd2hvIGtub3dzLiBJIHdvdWxkCj4gc3VnZ2VzdCB0byBrZWVwIGl0IGdlbmVy
aWMgYXMgeW91IGltcGxlbWVudGVkLgoKRmluZSB3aXRoIG1lLgoKLS0gCkplYW4gRGVsdmFyZQoK
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29y
cyBtYWlsaW5nIGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0t
c2Vuc29ycy5vcmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal
  2012-07-26 12:57 [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal Jean Delvare
  2012-07-26 13:37 ` Guenter Roeck
  2012-07-26 19:59 ` Jean Delvare
@ 2012-07-26 21:11 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2012-07-26 21:11 UTC (permalink / raw)
  To: lm-sensors

On Thu, Jul 26, 2012 at 09:59:36PM +0200, Jean Delvare wrote:
> Hi Guenter,
> 
> On Thu, 26 Jul 2012 06:37:50 -0700, Guenter Roeck wrote:
> > On Thu, Jul 26, 2012 at 02:57:45PM +0200, Jean Delvare wrote:
> > > Restoring the configuration register on device removal has the side
> > > effect of also resetting the hysteresis value. This is inconsistent as
> > > the other limits are not reset, only hysteresis. So, following the
> > > principle of least surprise, preserve the hysteresis value when
> > > restoring the configuration register.
> > > 
> > > Signed-off-by: Jean Delvare <khali@linux-fr.org>
> > > Cc: Guenter Roeck <linux@roeck-us.net>
> > 
> > Good catch. Applied.
> 
> Doh, please drop it, the patch is buggy. I wrote | where I meant & and
> this hard-codes the hysteresis to -6°C at driver removal if the config
> register changed. I didn't notice during my testing because config
> doesn't change for me. Sorry for the noise.
> 
.... and I didn't notice it wither, and had to look at the code for a while to
find it. Doh as well.

Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-26 21:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-26 12:57 [lm-sensors] [PATCH] hwmon: (jc42) Don't reset hysteresis on device removal Jean Delvare
2012-07-26 13:37 ` Guenter Roeck
2012-07-26 19:59 ` Jean Delvare
2012-07-26 21:11 ` Guenter Roeck

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.