Re: [PATCH v3] hwmon: Driver for MAX16065/MAX16066 System Manager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 14 Apr 2011 17:06:10 -0700, Guenter Roeck wrote:
> On Tue, 2011-04-12 at 05:03 -0400, Jean Delvare wrote:
> > On Fri, 8 Apr 2011 21:12:02 -0700, Guenter Roeck wrote:
> > > +
> > > +/* ADC registers have 10 bit resolution. */
> > > +static inline int ADC_TO_MV(int adc, int range)
> > > +{
> > > +     return (adc * range) / 1024;
> > > +}
> > > +
> > > +/*
> > > + * Limit registers have 8 bit resolution and match upper 8 bits of ADC
> > > + * registers.
> > > + */
> > > +static inline int LIMIT_TO_MV(int limit, int range)
> > > +{
> > > +     return DIV_ROUND_CLOSEST(limit * range, 256);
> > > +}
> > 
> > It is inconsistent to use DIV_ROUND_CLOSEST() for displaying limits and
> > not monitored values. This could cause values to look out-of-limits when
> > they aren't, or vice-versa.
> > 
> Any thought on what is better ? Use DIV_ROUND_CLOSEST for both, or
> none ? I tend to none, since the chip does not round either, but I am
> not really sure.

I'd say none. Other drivers tend to only care about rounding when
writing to limits, not reading values or limits.  I seem to understand
that the rationale is that writing limits is a rare operation so we
don't care if it's slightly slower, plus the user doesn't know the
resolution of the chip when writing limit values so it makes sense to
snap to the closest supported value.

-- 
Jean Delvare

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


[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux