* Re: [lm-sensors] [PATCH 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387
2012-02-22 22:18 [lm-sensors] [PATCH 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387 Nikolaus Schulz
@ 2012-02-23 1:25 ` Guenter Roeck
2012-02-23 18:59 ` Nikolaus Schulz
2012-02-24 22:45 ` Nikolaus Schulz
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2012-02-23 1:25 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 05:18:47PM -0500, Nikolaus Schulz wrote:
> The F75387 stores its temperature hysteresis in a different register than
> the other chips supported by that driver.
>
> Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> ---
> drivers/hwmon/f75375s.c | 36 ++++++++++++++++++++++++++++++------
> 1 files changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
> index 944937c..3b06abf 100644
> --- a/drivers/hwmon/f75375s.c
> +++ b/drivers/hwmon/f75375s.c
> @@ -65,6 +65,7 @@ enum chips { f75373, f75375, f75387 };
> #define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
> #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
> #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
> +#define F75387_REG_TEMP_HYST 0x62
>
> #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
> #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
> @@ -183,23 +184,34 @@ static struct f75375_data *f75375_update_device(struct device *dev)
> struct i2c_client *client = to_i2c_client(dev);
> struct f75375_data *data = i2c_get_clientdata(client);
> int nr;
> + u8 f75387_hyst_reg = 0;
>
> mutex_lock(&data->update_lock);
>
> /* Limit registers cache is refreshed after 60 seconds */
> if (time_after(jiffies, data->last_limits + 60 * HZ)
> || !data->valid) {
> + if (data->kind = f75387)
> + f75387_hyst_reg > + f75375_read8(client, F75387_REG_TEMP_HYST);
> for (nr = 0; nr < 2; nr++) {
> data->temp_high[nr] > f75375_read8(client, F75375_REG_TEMP_HIGH(nr));
> - data->temp_max_hyst[nr] > - f75375_read8(client, F75375_REG_TEMP_HYST(nr));
> data->fan_max[nr] > f75375_read16(client, F75375_REG_FAN_FULL(nr));
> data->fan_min[nr] > f75375_read16(client, F75375_REG_FAN_MIN(nr));
> data->fan_target[nr] > f75375_read16(client, F75375_REG_FAN_EXP(nr));
> + if (data->kind = f75387) {
> + data->temp_max_hyst[nr] > + data->temp_high[nr] -
> + (0xf & f75387_hyst_reg);
I really hate it when people put the constant first, and consider it confusing.
Please change. Besides, you can do the masking above, when f75387_hyst_reg is read.
This way it only needs to be done once.
> + } else {
> + data->temp_max_hyst[nr] > + f75375_read8(client,
> + F75375_REG_TEMP_HYST(nr));
> + }
> }
> for (nr = 0; nr < 4; nr++) {
> data->in_max[nr] > @@ -599,11 +611,23 @@ static ssize_t set_temp_max_hyst(struct device *dev,
> if (err < 0)
> return err;
>
> - val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
> + val = TEMP_TO_REG(val);
> mutex_lock(&data->update_lock);
> - data->temp_max_hyst[nr] = val;
> - f75375_write8(client, F75375_REG_TEMP_HYST(nr),
> - data->temp_max_hyst[nr]);
> + if (data->kind = f75387) {
> + u8 regval;
> + val = SENSORS_LIMIT(val,
> + data->temp_high[nr] - 0xf,
> + data->temp_high[nr]);
> + data->temp_max_hyst[nr] = val;
> + regval = f75375_read8(client, F75387_REG_TEMP_HYST);
> + regval &= 0xf0;
> + regval |= data->temp_high[nr] - val;
> + f75375_write8(client, F75387_REG_TEMP_HYST, regval);
Unless I am missing something, this affects the other hysteresis values as well,
since there is really only a single hysteresis register. If so, you have to set
data->valid to 0 to ensure that temp_max_hyst[] is updated with the next read cycle.
> + } else {
> + val = SENSORS_LIMIT(val, 0, 127);
> + data->temp_max_hyst[nr] = val;
> + f75375_write8(client, F75375_REG_TEMP_HYST(nr), val);
> + }
> mutex_unlock(&data->update_lock);
> return count;
> }
> --
> 1.7.9.1
>
_______________________________________________
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 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387
2012-02-22 22:18 [lm-sensors] [PATCH 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387 Nikolaus Schulz
2012-02-23 1:25 ` Guenter Roeck
@ 2012-02-23 18:59 ` Nikolaus Schulz
2012-02-24 22:45 ` Nikolaus Schulz
2 siblings, 0 replies; 4+ messages in thread
From: Nikolaus Schulz @ 2012-02-23 18:59 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 05:25:44PM -0800, Guenter Roeck wrote:
> On Wed, Feb 22, 2012 at 05:18:47PM -0500, Nikolaus Schulz wrote:
> > The F75387 stores its temperature hysteresis in a different register than
> > the other chips supported by that driver.
> >
> > Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> > ---
> > drivers/hwmon/f75375s.c | 36 ++++++++++++++++++++++++++++++------
> > 1 files changed, 30 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
> > index 944937c..3b06abf 100644
> > --- a/drivers/hwmon/f75375s.c
> > +++ b/drivers/hwmon/f75375s.c
> > @@ -65,6 +65,7 @@ enum chips { f75373, f75375, f75387 };
> > #define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
> > #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
> > #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
> > +#define F75387_REG_TEMP_HYST 0x62
> >
> > #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
> > #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
> > @@ -183,23 +184,34 @@ static struct f75375_data *f75375_update_device(struct device *dev)
> > struct i2c_client *client = to_i2c_client(dev);
> > struct f75375_data *data = i2c_get_clientdata(client);
> > int nr;
> > + u8 f75387_hyst_reg = 0;
> >
> > mutex_lock(&data->update_lock);
> >
> > /* Limit registers cache is refreshed after 60 seconds */
> > if (time_after(jiffies, data->last_limits + 60 * HZ)
> > || !data->valid) {
> > + if (data->kind = f75387)
> > + f75387_hyst_reg > > + f75375_read8(client, F75387_REG_TEMP_HYST);
> > for (nr = 0; nr < 2; nr++) {
> > data->temp_high[nr] > > f75375_read8(client, F75375_REG_TEMP_HIGH(nr));
> > - data->temp_max_hyst[nr] > > - f75375_read8(client, F75375_REG_TEMP_HYST(nr));
> > data->fan_max[nr] > > f75375_read16(client, F75375_REG_FAN_FULL(nr));
> > data->fan_min[nr] > > f75375_read16(client, F75375_REG_FAN_MIN(nr));
> > data->fan_target[nr] > > f75375_read16(client, F75375_REG_FAN_EXP(nr));
> > + if (data->kind = f75387) {
> > + data->temp_max_hyst[nr] > > + data->temp_high[nr] -
> > + (0xf & f75387_hyst_reg);
>
> I really hate it when people put the constant first, and consider it confusing.
> Please change.
Ok.
> Besides, you can do the masking above, when f75387_hyst_reg is read.
> This way it only needs to be done once.
Correct.
I didn't do that because there is also some fan-specific information
encoded in that register, and I am working on code that uses it. But
until that code is posted, the register should be masked beforehand.
I'll update the patch accordingly.
> > + } else {
> > + data->temp_max_hyst[nr] > > + f75375_read8(client,
> > + F75375_REG_TEMP_HYST(nr));
> > + }
> > }
> > for (nr = 0; nr < 4; nr++) {
> > data->in_max[nr] > > @@ -599,11 +611,23 @@ static ssize_t set_temp_max_hyst(struct device *dev,
> > if (err < 0)
> > return err;
> >
> > - val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
> > + val = TEMP_TO_REG(val);
> > mutex_lock(&data->update_lock);
> > - data->temp_max_hyst[nr] = val;
> > - f75375_write8(client, F75375_REG_TEMP_HYST(nr),
> > - data->temp_max_hyst[nr]);
> > + if (data->kind = f75387) {
> > + u8 regval;
> > + val = SENSORS_LIMIT(val,
> > + data->temp_high[nr] - 0xf,
> > + data->temp_high[nr]);
> > + data->temp_max_hyst[nr] = val;
> > + regval = f75375_read8(client, F75387_REG_TEMP_HYST);
> > + regval &= 0xf0;
> > + regval |= data->temp_high[nr] - val;
> > + f75375_write8(client, F75387_REG_TEMP_HYST, regval);
>
> Unless I am missing something, this affects the other hysteresis values as well,
> since there is really only a single hysteresis register.
That's correct.
> If so, you have to set
> data->valid to 0 to ensure that temp_max_hyst[] is updated with the next read cycle.
Good catch!
I will post an updated patch.
> > + } else {
> > + val = SENSORS_LIMIT(val, 0, 127);
> > + data->temp_max_hyst[nr] = val;
> > + f75375_write8(client, F75375_REG_TEMP_HYST(nr), val);
> > + }
> > mutex_unlock(&data->update_lock);
> > return count;
> > }
> > --
> > 1.7.9.1
_______________________________________________
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 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387
2012-02-22 22:18 [lm-sensors] [PATCH 4/6] hwmon: (f75375s) Fix hysteresis register access for the F75387 Nikolaus Schulz
2012-02-23 1:25 ` Guenter Roeck
2012-02-23 18:59 ` Nikolaus Schulz
@ 2012-02-24 22:45 ` Nikolaus Schulz
2 siblings, 0 replies; 4+ messages in thread
From: Nikolaus Schulz @ 2012-02-24 22:45 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 11:18:47PM +0100, Nikolaus Schulz wrote:
> The F75387 stores its temperature hysteresis in a different register than
> the other chips supported by that driver.
>
> Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> ---
> drivers/hwmon/f75375s.c | 36 ++++++++++++++++++++++++++++++------
> 1 files changed, 30 insertions(+), 6 deletions(-)
Oh, stupid me. I have to revoke this patch, because it is simply utter
nonsense. Sorry for that.
The F75387 does indeed use register 0x62 to store a temperature
hysteresis delta, but it applies only to the automatic,
temperature-controlled fan control mode.
The high limit hysteresis temperatures, though, are still stored in
registers 0x29 and 0x2B - here the F75387 is no different from the other
chips supported by this driver.
Nikolaus (grabbing a brown paper bag)
> diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
> index 944937c..3b06abf 100644
> --- a/drivers/hwmon/f75375s.c
> +++ b/drivers/hwmon/f75375s.c
> @@ -65,6 +65,7 @@ enum chips { f75373, f75375, f75387 };
> #define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
> #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
> #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
> +#define F75387_REG_TEMP_HYST 0x62
>
> #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
> #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
> @@ -183,23 +184,34 @@ static struct f75375_data *f75375_update_device(struct device *dev)
> struct i2c_client *client = to_i2c_client(dev);
> struct f75375_data *data = i2c_get_clientdata(client);
> int nr;
> + u8 f75387_hyst_reg = 0;
>
> mutex_lock(&data->update_lock);
>
> /* Limit registers cache is refreshed after 60 seconds */
> if (time_after(jiffies, data->last_limits + 60 * HZ)
> || !data->valid) {
> + if (data->kind = f75387)
> + f75387_hyst_reg > + f75375_read8(client, F75387_REG_TEMP_HYST);
> for (nr = 0; nr < 2; nr++) {
> data->temp_high[nr] > f75375_read8(client, F75375_REG_TEMP_HIGH(nr));
> - data->temp_max_hyst[nr] > - f75375_read8(client, F75375_REG_TEMP_HYST(nr));
> data->fan_max[nr] > f75375_read16(client, F75375_REG_FAN_FULL(nr));
> data->fan_min[nr] > f75375_read16(client, F75375_REG_FAN_MIN(nr));
> data->fan_target[nr] > f75375_read16(client, F75375_REG_FAN_EXP(nr));
> + if (data->kind = f75387) {
> + data->temp_max_hyst[nr] > + data->temp_high[nr] -
> + (0xf & f75387_hyst_reg);
> + } else {
> + data->temp_max_hyst[nr] > + f75375_read8(client,
> + F75375_REG_TEMP_HYST(nr));
> + }
> }
> for (nr = 0; nr < 4; nr++) {
> data->in_max[nr] > @@ -599,11 +611,23 @@ static ssize_t set_temp_max_hyst(struct device *dev,
> if (err < 0)
> return err;
>
> - val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
> + val = TEMP_TO_REG(val);
> mutex_lock(&data->update_lock);
> - data->temp_max_hyst[nr] = val;
> - f75375_write8(client, F75375_REG_TEMP_HYST(nr),
> - data->temp_max_hyst[nr]);
> + if (data->kind = f75387) {
> + u8 regval;
> + val = SENSORS_LIMIT(val,
> + data->temp_high[nr] - 0xf,
> + data->temp_high[nr]);
> + data->temp_max_hyst[nr] = val;
> + regval = f75375_read8(client, F75387_REG_TEMP_HYST);
> + regval &= 0xf0;
> + regval |= data->temp_high[nr] - val;
> + f75375_write8(client, F75387_REG_TEMP_HYST, regval);
> + } else {
> + val = SENSORS_LIMIT(val, 0, 127);
> + data->temp_max_hyst[nr] = val;
> + f75375_write8(client, F75375_REG_TEMP_HYST(nr), val);
> + }
> mutex_unlock(&data->update_lock);
> return count;
> }
> --
> 1.7.9.1
>
>
_______________________________________________
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