hwmon: (jc42) Simplify hysteresis mask
PATCH 1/2 hwmon: (jc42) Simplify hysteresis mask
Define JC42_CFG_HYST_MASK as the mask _before_ shifting instead of after shifting. This simplifies the current code slightly, and will simplify the code to come even more.
--- drivers/hwmon/jc42.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/hwmon/jc42.c +6 -7
@@ -57,7 +57,7 @@ static const unsigned short normal_i2c[]#define JC42_CFG_EVENT_LOCK (1 << 7)#define JC42_CFG_SHUTDOWN (1 << 8)#define JC42_CFG_HYST_SHIFT 9 -#define JC42_CFG_HYST_MASK 0x03 +#define JC42_CFG_HYST_MASK (0x03 << 9)/* Capabilities */ #define JC42_CAP_RANGE (1 << 2)
@@ -287,8 +287,8 @@ static ssize_t show_temp_crit_hyst(strucreturn PTR_ERR (data); temp =jc42_temp_from_reg (data->temp_crit); - hyst = jc42_hysteresis[(data->config >>JC42_CFG_HYST_SHIFT ) - &JC42_CFG_HYST_MASK ]; + hyst = jc42_hysteresis[(data->config &JC42_CFG_HYST_MASK ) + >>JC42_CFG_HYST_SHIFT ];return sprintf (buf,"%d\n" , temp - hyst); }
@@ -302,8 +302,8 @@ static ssize_t show_temp_max_hyst(structreturn PTR_ERR (data); temp =jc42_temp_from_reg (data->temp_max); - hyst = jc42_hysteresis[(data->config >>JC42_CFG_HYST_SHIFT ) - &JC42_CFG_HYST_MASK ]; + hyst = jc42_hysteresis[(data->config &JC42_CFG_HYST_MASK ) + >>JC42_CFG_HYST_SHIFT ];return sprintf (buf,"%d\n" , temp - hyst); }
@@ -362,8 +362,7 @@ static ssize_t set_temp_crit_hyst(struct }mutex_lock (&data->update_lock); - data->config = (data->config - & ~(JC42_CFG_HYST_MASK <<JC42_CFG_HYST_SHIFT )) + data->config = (data->config & ~JC42_CFG_HYST_MASK ) | (hyst <<JC42_CFG_HYST_SHIFT ); err =i2c_smbus_write_word_swapped (client,JC42_REG_CONFIG , data->config);
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 13 lines · Jean Delvare
Define
JC42_CFG_HYST_MASKas the mask _before_ shifting instead of after shifting. This simplifies the current code slightly, and will simplify the code to come even more.Signed-off-by Jean Delvare <[email protected]>Cc Guenter Roeck <[email protected]>--- drivers/hwmon/jc42.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/hwmon/jc42.c static const unsigned short normal_i2c[] · line 61
Quoted 6 lines
drivers/hwmon/jc42.c +1
-1@@ -57,7 +57,7 @@ static const unsigned short normal_i2c[]#define JC42_CFG_EVENT_LOCK (1 << 7)#define JC42_CFG_SHUTDOWN (1 << 8)#define JC42_CFG_HYST_SHIFT 9 -#define JC42_CFG_HYST_MASK 0x03 +#define JC42_CFG_HYST_MASK (0x03 << 9)
Since we have JC42_CFG_HYST_SHIFT, might as well use it.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Jean Delvare
Define
JC42_CFG_HYST_MASKas the mask _before_ shifting instead of after shifting. This simplifies the current code slightly, and will simplify the code to come even more.Signed-off-by Jean Delvare <[email protected]>Cc Guenter Roeck <[email protected]>--- drivers/hwmon/jc42.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
Quoted 11 lines
drivers/hwmon/jc42.c static const unsigned short normal_i2c[] · line 61
Quoted 9 lines
drivers/hwmon/jc42.c +1
-1@@ -57,7 +57,7 @@ static const unsigned short normal_i2c[]#define JC42_CFG_EVENT_LOCK (1 << 7)#define JC42_CFG_SHUTDOWN (1 << 8)#define JC42_CFG_HYST_SHIFT 9 -#define JC42_CFG_HYST_MASK 0x03 +#define JC42_CFG_HYST_MASK (0x03 << 9)Since we have
JC42_CFG_HYST_SHIFT, might as well use it.
I thought about it but wasn't sure. The two definitions are next to each other, and they are not likely to ever change, so the benefit of using JC42_CFG_HYST_SHIFT in JC42_CFG_HYST_MASK wasn't too obvious. And a copy/paste/forget-to-update error seems less likely to happen with a straight number.
That being said, if you prefer it the other way, feel tree to amend my patch that way, it's your driver after all.
(I can resubmit if you want.)
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 26 lines · Jean Delvare
Hi Guenter,
Quoted 11 lines · Guenter Roeck
Quoted 10 lines · Jean Delvare
Define
JC42_CFG_HYST_MASKas the mask _before_ shifting instead of after shifting. This simplifies the current code slightly, and will simplify the code to come even more.Signed-off-by Jean Delvare <[email protected]>Cc Guenter Roeck <[email protected]>--- drivers/hwmon/jc42.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)Quoted 11 lines
drivers/hwmon/jc42.c static const unsigned short normal_i2c[] · line 61
Quoted 9 lines
drivers/hwmon/jc42.c +1
-1@@ -57,7 +57,7 @@ static const unsigned short normal_i2c[]#define JC42_CFG_EVENT_LOCK (1 << 7)#define JC42_CFG_SHUTDOWN (1 << 8)#define JC42_CFG_HYST_SHIFT 9 -#define JC42_CFG_HYST_MASK 0x03 +#define JC42_CFG_HYST_MASK (0x03 << 9)Since we have
JC42_CFG_HYST_SHIFT, might as well use it.
Quoted 6 lines
I thought about it but wasn't sure. The two definitions are next to each other, and they are not likely to ever change, so the benefit of using
JC42_CFG_HYST_SHIFTinJC42_CFG_HYST_MASKwasn't too obvious. And a copy/paste/forget-to-update error seems less likely to happen with a straight number.
Makes sense. I'll apply as-is.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors