[PATCH 1/2] hwmon: add generic GPIO fan driver

Guenter Roeck
2010-10-19T06:52:21Z

On Mon, Oct 18, 2010 at 04:36:10PM -0400, Simon Guinot wrote:
[ ... ]
> > I don't really understand the value of supporting pwm attributes,
> > since you have to convert those to rpm anyway. Why not just stick
> > with fan1_input and fan1_target ? This would simplify the code a lot.
>
> I don't know very well the hwmon API. I have simply been fooled by the
> sysfs-interface document which claim that fan[1-*]_target only make
> sense for a closed-loop fan. Moreover, I was expecting gpio-fan to be
> compliant with the fancontrol shell script...
>
> But anyway, you are right. I just don't want the pwm interface.
>
Thinking more about this, another option might be to keep using
the pwm interface (for fancontrol), but simplify your code.
Your transitions are currently pwm -> rpm -> ctrl and vice versa.
However, direct conversion pwm -> ctrl should also be possible
and would be much simpler than the two-stage conversion.

To do that, you could map num_speed directly to the pwm range of (0..255).
Something like

pwm = DIV_ROUND_CLOSEST(speed_index * 255, num_speed - 1);
and
speed_index = pwm * (num_speed - 1) / 255;

Then use speed_index to get control value and rpm from the speed table.

Would that make sense ? You could then also provide fan1_target
for direct fan speed control.

Thanks,
Guenter