RFC PATCH 2.6 sysfs names: fscher: change div to ripple
Hi all,
The fcsher and fscpos chips have a 'ripple' prescaler of ripples (pulses) per revolution of the fan.
This small patch changes fscher to match fscpos and is compile tested
--Grant.
--- fscher.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/chips/fscher.c +5 -5
@@ -195,7 +195,7 @@#define sysfs_fan (offset, reg_status, reg_min, reg_ripple, reg_act) \ sysfs_rw_n(pwm, , offset, reg_min) \ sysfs_rw_n(fan, _status, offset, reg_status) \ -sysfs_rw_n(fan, _div , offset, reg_ripple) \ +sysfs_rw_n(fan, _ripple , offset, reg_ripple) \ sysfs_ro_n(fan, _input , offset, reg_act)#define sysfs_temp (offset, reg_status, reg_act) \
@@ -243,7 +243,7 @@ do { \ device_create_file(&client->dev, &dev_attr_fan##offset##_status); \ device_create_file(&client->dev, &dev_attr_pwm##offset); \ - device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ + device_create_file(&client->dev, &dev_attr_fan##offset##_ripple); \ device_create_file(&client->dev, &dev_attr_fan##offset##_input); \ } while (0)
@@ -495,7 +495,7 @@return sprintf (buf,"%u\n" , data->fan_min[FAN_INDEX_FROM_NUM (nr)]); } -static ssize_t set_fan_div (struct i2c_client *client,struct fscher_data *data, +static ssize_t set_fan_ripple (struct i2c_client *client,struct fscher_data *data,const char *buf,size_t count,int nr,int reg) {/* supported values: 2, 4, 8 */
@@ -506,7 +506,7 @@case 4 : v =2 ;break ;case 8 : v =3 ;break ;default : -dev_err (&client->dev,"fan_div value %ld not " +dev_err (&client->dev,"fan_ripple value %ld not " "supported. Choose one of 2, 4 or 8!\n" , v);return -EINVAL ; }
@@ -522,7 +522,7 @@return count; } -static ssize_t show_fan_div (struct fscher_data *data,char *buf,int nr) +static ssize_t show_fan_ripple (struct fscher_data *data,char *buf,int nr) {/* bits 2..7 reserved => mask with 0x03 */ return sprintf (buf,"%u\n" ,1 << (data->fan_ripple[FAN_INDEX_FROM_NUM (nr)] &0x03 ));
Hi Philip,
Quoted 8 lines
But whether it's the same hardware implementation or not, if it has the same effect, then it's the same feature (quack's like a duck => it's a duck).
The fan dividors we're used to seeing are ripple counters on the 22.5kHz clock that divide it down to reduce the clock pulses counted by the gating fan pulses.
Quoted 8 lines
This ripple counter sounds like the same thing, but working on the fan pulses directly rather than on the 22.5kHz clock. So the fan tach signal is slower with a higher divisor.
So the
fan_rippleis the *inverse* of thefan_divvalue, but they have the same net effect, and you can account for the reciprical in the driver. iefan_div= 8/fan_ripple (if the max "ripple" value is 8)
Thanks for the clarification, it all makes sense now, and actually both ways can be seen as similar, you're right. It's really only a matter of whether or not we compensate for the division in the driver. We typically do for fan clock dividers and not in the FSC chips case, but this is more or less arbitrary.
Quoted 3 lines
I've had to deal with 4-pulse per rev fans before and I've done it with 'compute' commands in sensors.conf. It does not need to be in the driver.
Changing the divider (whatever it actually divides) has an impact on the measurable range and accuracy. This might be a good reason to let the driver handle it when the chip does, so that we can get the best from the hardware. Now I agree that the same approach that is currently followed for the regular fan clock dividers could apply in the FSC case as well. I have no strong opinion on this (understatement of me being unable to decide what I think we should do) so any solution that is consistent will be fine with me.
Thanks,
Signature · 1 line
Jean Delvare
A ripple counter is just a simple way of implementing a pulse frequency divider in hardware.
Together with a MUX to select from different bits of the ripple counter, it provides low cost divide by 2, 4, 8, etc.
So a ripple counter is the equivalent to a fan divisor and therefore I would recommend *not* to apply this patch to rename it. Keep the original fan_div name.
If fscpos has a fan_ripple accessor, then *it* should be changed to fan_div, not the other way round.
:v)
Quoted 9 lines · Grant Coady
Hi all,
The fcsher and fscpos chips have a 'ripple' prescaler of ripples (pulses) per revolution of the fan.
This small patch changes fscher to match fscpos and is compile tested
Quoted 10 lines · Grant Coady
Quoted 5 lines · Philip Pokorny
So a ripple counter is the equivalent to a fan divisor and therefore I would recommend *not* to apply this patch to rename it. Keep the original
fan_divname.
Quoted 9 lines
Jean Delvare tells me the thing is different, my request for a tester has gone unanswered thus far, if you have access to one of these chips the test is simple: if changing fan_ripple/fan_div doubles or halves the fan speed reading, then
fan_ripple!=fan_div. That easy!Until somebody provides the answer to that simple test I am assuming
fan_ripple!=fan_div.
Unfortunately, I don't have the hardware either.
But whether it's the same hardware implementation or not, if it has the same effect, then it's the same feature (quack's like a duck => it's a duck).
The fan dividors we're used to seeing are ripple counters on the 22.5kHz clock that divide it down to reduce the clock pulses counted by the gating fan pulses.
This ripple counter sounds like the same thing, but working on the fan pulses directly rather than on the 22.5kHz clock. So the fan tach signal is slower with a higher divisor.
So the fan_ripple is the *inverse* of the fan_div value, but they have the same net effect, and you can account for the reciprical in the driver. ie fan_div = 8/fan_ripple (if the max "ripple" value is 8)
Quoted 10 lines
Quoted 4 lines
If fscpos has a
fan_rippleaccessor, then *it* should be changed tofan_div, not the other way round.Disagree, if you have access to these chips, please perform the test and let me know result, then we can say the datasheet is a poor translation. (pulses <=> ripples struck me as strange translation).
Well, as I said above, the difference could be that one operates on the fan pulses and the other operates on the measuring clock signal.
Quoted 9 lines
The datasheet
_isclear_on defining ripples as 2, 4 or 8 per fan revolution, whereas datasheets for chips with 22.5kHz fan clock divided before -> gated counter _always_ spec the fan as two pulses per revolution.Having the same name for a fundamentally different function would not be useful.
Ahh, but lm_sensors has two goals. One is to make available all the chip functions. The other, is to provide a *consistent abstraction* to user space for those features.
For example, there are several different types of fan speed control algorithms out there. But lm_sensors attempts to fold them all into a common reference model so that user-space tools have to deal with only one model for fan speed control.
Quoted 3 lines
The current different names for the same function is plainly wrong.
Agreed
Quoted 4 lines
(
fanX_pulses_per_rev) --> user-space should have this too, to scale fan speed when they have other than two pulses per rev fans.
I've had to deal with 4-pulse per rev fans before and I've done it with 'compute' commands in sensors.conf. It does not need to be in the driver.
Hi Grant, Philip,
Quoted 3 lines
Quoted 3 lines
So a ripple counter is the equivalent to a fan divisor and therefore I would recommend *not* to apply this patch to rename it. Keep the original
fan_divname.
A ripple counter is indeed equivalent to a fan divisor in the true sense of the term (dividing the fan speed value), but unfortunately the term "fan divisor" was used as a shortcut for "fan clock divider" for so long that using it for something different is now confusing. Using a fanN_div accessor for something else than a fan clock divider should be avoided, so as to not add to the confusion.
The way the Hermes and Poseidon chips deal with fans is very different from what other chips do, and their "ripple" value isn't equivalent to the common "fan clock divider" concept used elsewhere. So using the same accessor name wasn't wise. I am sorry I let it happen in the first place.
Quoted 3 lines
Disagree, if you have access to these chips, please perform the test and let me know result, then we can say the datasheet is a poor translation. (pulses <=> ripples struck me as strange translation).
I've read the Hermes datasheet again and it looks rather clear to me. The pulses <=> ripples relation makes sense, in that the chip will provide the correct fan speed if and only if the ripple counter has been setup to match the fan's pulses per revolution.
Quoted 4 lines
Having the same name for a fundamentally different function would not be useful.
The current different names for the same function is plainly wrong.
The functions are not "fundamentally different", in that both are ways to avoid register overflows by accomodating to different fans. Still, the purpose of the sysfs interface is to be chip-independant, so the current situation is bad.
Quoted 2 lines
(
fanX_pulses_per_rev) --> user-space should have this too, to scale fan speed when they have other than two pulses per rev fans.
Yes, this is how the accessor should be named when the chip supports this functionality. I would have gone for fanN_ppr for something shorter. I think I remember a Linux 2.4 driver using that name already.
At any rate, the name fanN_ripple doesn't sound good to me. The fact that a ripple counter is used is an implementation detail the user doesn't need to know. The sysfs interface should focus on the function rather than the implementation. So the proposed patch doesn't please me, and I would like to see a patch for fscpos to change the name there as well.
Note that such patches can only be accepted in Linux 2.6 if an equivalent patch is provided for libsensors.
Thanks,
--
Jean Delvare
Hi Khali, Philip,
Quoted 1 line · Jean Delvare
I would have gone for
fanN_pprfor something shorter.
I'll do it this way, the long name was for comment :) Any driver may choose to include the fanN_ppr accessor so that correct reading in rpm available from sysfs? Or is that going too far again?
Quoted 3 lines
think I remember a Linux 2.4 driver using that name already.
At any rate, the name
fanN_rippledoesn't sound good to me.
Ripple always struck me as an odd name too.
Quoted 2 lines
Note that such patches can only be accepted in Linux 2.6 if an equivalent patch is provided for libsensors.
I've done that before, do you want the old name kept like last time too?
Cheers,
Grant.
Quoted 3 lines · Philip Pokorny
So a ripple counter is the equivalent to a fan divisor and therefore I would recommend *not* to apply this patch to rename it. Keep the original
fan_divname.
Jean Delvare tells me the thing is different, my request for a tester has gone unanswered thus far, if you have access to one of these chips the test is simple: if changing fan_ripple/fan_div doubles or halves the fan speed reading, then fan_ripple != fan_div. That easy!
Until somebody provides the answer to that simple test I am assuming fan_ripple != fan_div.
Quoted 2 lines
If fscpos has a
fan_rippleaccessor, then *it* should be changed tofan_div, not the other way round.
Disagree, if you have access to these chips, please perform the test and let me know result, then we can say the datasheet is a poor translation. (pulses <=> ripples struck me as strange translation).
The datasheet _is clear_ on defining ripples as 2, 4 or 8 per fan revolution, whereas datasheets for chips with 22.5kHz fan clock divided before -> gated counter _always_ spec the fan as two pulses per revolution.
Having the same name for a fundamentally different function would not be useful.
The current different names for the same function is plainly wrong.
The available evidence to me points to a difference in function, requiring a name change. If you can perform the test confirming this issue then we know the correct name to use.
(fanX_pulses_per_rev) --> user-space should have this too, to scale fan speed when they have other than two pulses per rev fans.
Thanks,
--Grant.
Hi Grant,
Quoted 3 lines
I'll do it this way, the long name was for comment :) Any driver may choose to include the
fanN_ppraccessor so that correct reading in rpm available from sysfs? Or is that going too far again?
Drivers should only expose this interface if it matches a hardware capability. If not, then the conversion belongs to userspace (through libsensors or whatever the user likes).
Quoted 4 lines
Quoted 2 lines
Note that such patches can only be accepted in Linux 2.6 if an equivalent patch is provided for libsensors.
I've done that before, do you want the old name kept like last time too?
It's less sensible for the FSC chips, as there are only a couple users out there. Also, this feature is certainly not much used (most people have 2 pulses per revolution fans anyway). As a matter of fact, libsensors doesn't even point to the correct names for fscher. The fscpos driver has not been in any official Linux 2.6 kernel yet. So I wouldn't bother with compatibility this time in the drivers themselves.
We can support both names for both chips in libsensors though, as the additional cost is very thin (and it is such a mess already anyway...)
Thanks,
--
Jean Delvare
Hi Philip,
Quoted 4 lines · Philip Pokorny
This ripple counter sounds like the same thing, but working on the fan pulses directly rather than on the 22.5kHz clock. So the fan tach signal is slower with a higher divisor.
The main difference is that changing ripple will change fan speed reading, that aspect is different from other chips, thus the variable needs a different name.
The fan speed reading in fscher is defined as 0..255 U/sec. What is
a 'U'? Code comments suggest revs / sec?
Quoted 3 lines
So the
fan_rippleis the *inverse* of thefan_divvalue, but they have the same net effect, and you can account for the reciprical in the driver. iefan_div= 8/fan_ripple (if the max "ripple" value is 8)
Yes, you may do that, but without the chip to test I'd rather just put fsc* fan_div/fan_ripple into a different common name so user land sees it has a different meaning.
Sysfs names project is cleaning up and documenting sysfs naming.
I'm working up to fan speed control :)
Cheers,
--Grant.
Hi Philip, Khali,
On Wed, 27 Apr 2005 23:14:31 +0200, Jean Delvare <[email protected]> wrote:
Philip wrote >>
Quoted 3 lines
Quoted 3 lines
So the
fan_rippleis the *inverse* of thefan_divvalue, but they have the same net effect, and you can account for the reciprical in the driver. iefan_div= 8/fan_ripple (if the max "ripple" value
^^^^^^^^^^^^^^^^^^^^^^-- sorry, I missed significance
Quoted 7 lines
Quoted 1 line
is 8)
Thanks for the clarification, it all makes sense now, and actually both ways can be seen as similar, you're right. It's really only a matter of whether or not we compensate for the division in the driver. We typically do for fan clock dividers and not in the FSC chips case, but this is more or less arbitrary.
. . .
Quoted 3 lines
I have no strong opinion on this (understatement of me being
unable to decide what I think we should do) so any solution that is consistent will be fine with me.
Just looking at the drivers (fscher, pscpos) again, fan speed rpm reading is register_value * 60, so the chip reporting revs / sec.
data sheet gives fan_ripple in 2, 4, 8 =>> fan_div in 8, 4, 2
store (16 / fan_div) to fan_ripple
report (16 / fan_ripple) as fan_div
fan_ripple is internal to driver, not exposed
report (fan_ripple * 60 * fan_rps / 2) for fan speed (no change for 'normal' 2 pps fan with default fan_ripple = 2.
Seems like a safe thing to do, and easier if everything has fan_div which satisfies Philip's earlier point _and_ acts the same as fan_div in other drivers.
Dunno if I'd go put in auto-fan-div without a live tester somewhere :)
I've been somewhat invasive removing an extra macro to expose some indexing trickery and renaming fan_act to fan_rps to match comments.
Expected effect is that chip will report 'default fan_div' as 8 (default fan_ripple is 2) and changing fake fan_div does not change reported fan speed, user will need to scale for fan_pps just like every other driver :)
Comments welcome, a live tester even more so. Changes to fscher don't impact libsensors? no interface change.
If this is acceptable approach I'll change fscpos over -- it has fan_ripple and wdog to change, thus will change interface and need libsensors changed to match, correct?
--Grant.
--- fscher.c | 48 ++++++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 22 deletions(-)
drivers/i2c/chips/fscher.c +26 -22
@@ -145,8 +145,8 @@u8 volt[3 ];/* 12, 5, battery voltage */ u8 temp_act[3 ];/* temperature */ u8 temp_status[3 ];/* status of sensor */ -u8 fan_act[3 ];/* fans revolutions per second */ u8 fan_status[3 ];/* fan status */ +u8 fan_rps[3 ];/* fans revolutions per second */ u8 fan_min[3 ];/* fan min value for rps */ u8 fan_ripple[3 ];/* divider for rps */ };
@@ -427,9 +427,9 @@ data->volt[1 ] =fscher_read_value (client,FSCHER_REG_VOLT_5 ); data->volt[2 ] =fscher_read_value (client,FSCHER_REG_VOLT_BATT ); - data->fan_act[0 ] =fscher_read_value (client,FSCHER_REG_FAN0_ACT ); - data->fan_act[1 ] =fscher_read_value (client,FSCHER_REG_FAN1_ACT ); - data->fan_act[2 ] =fscher_read_value (client,FSCHER_REG_FAN2_ACT ); + data->fan_rps[0 ] =fscher_read_value (client,FSCHER_REG_FAN0_ACT ); + data->fan_rps[1 ] =fscher_read_value (client,FSCHER_REG_FAN1_ACT ); + data->fan_rps[2 ] =fscher_read_value (client,FSCHER_REG_FAN2_ACT ); data->fan_status[0 ] =fscher_read_value (client,FSCHER_REG_FAN0_STATE ); data->fan_status[1 ] =fscher_read_value (client,FSCHER_REG_FAN1_STATE ); data->fan_status[2 ] =fscher_read_value (client,FSCHER_REG_FAN2_STATE );
@@ -455,10 +455,7 @@return data; } - - -#define FAN_INDEX_FROM_NUM (nr) ((nr) - 1) - +/* fans */ static ssize_t set_fan_status (struct i2c_client *client,struct fscher_data *data,const char *buf,size_t count,int nr,int reg) {
@@ -466,7 +463,7 @@unsigned long v =simple_strtoul (buf,NULL ,10 ) &0x04 ;down (&data->update_lock); - data->fan_status[FAN_INDEX_FROM_NUM (nr)] &= ~v; + data->fan_status[nr -1 ] &= ~v;fscher_write_value (client, reg, v);up (&data->update_lock);return count;
@@ -475,7 +472,7 @@static ssize_t show_fan_status (struct fscher_data *data,char *buf,int nr) {/* bits 0..1, 3..7 reserved => mask with 0x04 */ -return sprintf (buf,"%u\n" , data->fan_status[FAN_INDEX_FROM_NUM (nr)] &0x04 ); +return sprintf (buf,"%u\n" , data->fan_status[nr -1 ] &0x04 ); } static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
@@ -484,17 +481,25 @@unsigned long v =simple_strtoul (buf,NULL ,10 );down (&data->update_lock); - data->fan_min[FAN_INDEX_FROM_NUM (nr)] = v >0xff ?0xff : v; -fscher_write_value (client, reg, data->fan_min[FAN_INDEX_FROM_NUM (nr)]); + data->fan_min[nr -1 ] = v >0xff ?0xff : v; +fscher_write_value (client, reg, data->fan_min[nr -1 ]);up (&data->update_lock);return count; }static ssize_t show_pwm (struct fscher_data *data,char *buf,int nr) { -return sprintf (buf,"%u\n" , data->fan_min[FAN_INDEX_FROM_NUM (nr)]); +return sprintf (buf,"%u\n" , data->fan_min[nr -1 ]); } +/* +* We going to tell a little lie to sysfs: pretend we have a fan_div like +* our sibling drivers. +* How? make fan_div 2, 4, 8 =>> fan_ripple 8, 4, 2, 'normalise' fan speed +* store (16 / fan_div) to fan_ripple +* report (16 / fan_ripple) as fan_div +* report (fan_rps * fan_ripple / 2) as fan speed, no change for fan_ripple = 2 +*/ static ssize_t set_fan_div (struct i2c_client *client,struct fscher_data *data,const char *buf,size_t count,int nr,int reg) {
@@ -502,9 +507,9 @@unsigned long v =simple_strtoul (buf,NULL ,10 );switch (v) { -case 2 : v =1 ;break ; +case 8 : v =1 ;break ;case 4 : v =2 ;break ; -case 8 : v =3 ;break ; +case 2 : v =3 ;break ;default :dev_err (&client->dev,"fan_div value %ld not " "supported. Choose one of 2, 4 or 8!\n" , v);
@@ -514,10 +519,10 @@down (&data->update_lock);/* bits 2..7 reserved => mask with 0x03 */ - data->fan_ripple[FAN_INDEX_FROM_NUM (nr)] &= ~0x03 ; - data->fan_ripple[FAN_INDEX_FROM_NUM (nr)] |= v; + data->fan_ripple[nr -1 ] &= ~0x03 ; + data->fan_ripple[nr -1 ] |= v; -fscher_write_value (client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM (nr)]); +fscher_write_value (client, reg, data->fan_ripple[nr -1 ]);up (&data->update_lock);return count; }
@@ -525,14 +530,13 @@static ssize_t show_fan_div (struct fscher_data *data,char *buf,int nr) {/* bits 2..7 reserved => mask with 0x03 */ -return sprintf (buf,"%u\n" ,1 << (data->fan_ripple[FAN_INDEX_FROM_NUM (nr)] &0x03 )); +return sprintf (buf,"%u\n" ,16 / (1 << (data->fan_ripple[nr -1 ] &0x03 ))); } -#define RPM_FROM_REG (val) (val*60) -static ssize_t show_fan_input (struct fscher_data *data,char *buf,int nr) { -return sprintf (buf,"%u\n" ,RPM_FROM_REG (data->fan_act[FAN_INDEX_FROM_NUM (nr)])); +return sprintf (buf,"%u\n" ,60 * data->fan_ripple[nr -1 ] * + data->fan_rps[nr -1 ] /2 ); }