linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Grönke, Christian" <C.Groenke@infodas.de>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Subject: Re: PMBus driver for FSP/3Y Power device with non-standard VOUT values (LINEAR11 vs LINEAR16)
Date: Thu, 14 Mar 2019 09:22:56 -0700	[thread overview]
Message-ID: <20190314162256.GA21090@roeck-us.net> (raw)
In-Reply-To: <25260e7b0f3d43588253791046440a64@infodas.de>

On Thu, Mar 14, 2019 at 04:08:32PM +0000, Grönke, Christian wrote:
> Hello Guenter,
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Guenter Roeck <groeck7@gmail.com> Im Auftrag von Guenter Roeck
> > Gesendet: Donnerstag, 14. März 2019 04:19
> > An: Grönke, Christian <C.Groenke@infodas.de>
> > Cc: linux-hwmon@vger.kernel.org
> > Betreff: Re: PMBus driver for FSP/3Y Power device with non-standard VOUT
> > values (LINEAR11 vs LINEAR16)
> > 
> > Hi Christian,
> > 
> > On Wed, Mar 13, 2019 at 05:35:38PM +0000, Grönke, Christian wrote:
> > [ ... ]
> > > >
> > > > Our last e-mails overlapped; can you explore what it would take to
> > > > add support for ieee754 half precision floating point ?  We would
> > > > need a new set of conversion functions in the core (ie
> > > > pmbus_reg2data_ieee754 and pmbus_data2reg_ieee754), and your driver
> > > > would have to implement the
> > > > linear11 <-> ieee754 conversion. That may be a bit more work, but it
> > > > would also be cleaner, and it should not affect precision.
> > >
> > > I give it a look tomorrow. If this presents a proper and clean way, to
> > > avoid adding the hack in the generic code it might be worth it.
> > >
> > 
> > Please use the attached patch as starting point. Obviously I could not
> > do much testing, but unit testing returned reasonable results. Note that
> > we don't have to follow the pmbus spec to the letter - it is sufficient
> > to declare the VOUT values to be in ieee754 format for your driver.
> 
> Thanks a lot for the patch. It did indeed help.
> 
> The framework code seemed to work fine. I used your code for the conversion:
>     linear11 -> 'scaled integer' -> ieee754
> It provided a way to test the code and was easy for me as my tries to do
> some other bit magic weren't successful. That means I partly tested the code
> from pmbus_data2reg_ieee754 as my read_word function uses this for the
> conversion. Of course not the module local function...
> 
> I have question wrt to the code:
> [...]
> > +static u16 pmbus_data2reg_ieee754(struct pmbus_data *data,
> > +				  struct pmbus_sensor *sensor, long val) {
> [...]
> > +
> > +	/* Ensure that resulting number is within range */
> > +	if (mantissa > 0x7ff)
> > +		mantissa = 0x7ff;
> > +	else if (mantissa < 0x400)
> > +		mantissa = 0x400;
> 
> Setting the mantissa to 0x400...
> 
> > +	/* Convert to sign, 5 bit exponent, 10 bit mantissa */
> > +	return sign | (mantissa & 0x3ff) | ((exponent << 10) & 0x7c00); }
> 
> ... would mean it is cut to 0 here. I am not sure this is the intention.
> I guess it should be 0x3FF then. Or in case it is supposed to be 0, then
> 'mantissa = 0;' would be easier to understand.
> 

It is supposed to end up being 0 at the end. The valid range is
0x400..0x7ff, where bit 10 represents the '1' in the normalized number.
Bit 10 has to be removed when applying the value to the final ieee754
representation. I thought that was easier to understand than setting
the values to 0x3ff and 0x0 (which would look even more confusing
to the casual reader). I think I'll add a comment at the top
explaining the logic.

Thanks,
Guenter

  reply	other threads:[~2019-03-14 16:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 12:31 PMBus driver for FSP/3Y Power device with non-standard VOUT values (LINEAR11 vs LINEAR16) Grönke, Christian
2019-03-13 15:19 ` Guenter Roeck
2019-03-13 16:20   ` AW: " Grönke, Christian
2019-03-13 16:30     ` Guenter Roeck
2019-03-13 17:35       ` AW: " Grönke, Christian
2019-03-14  3:18         ` Guenter Roeck
2019-03-14 16:08           ` AW: " Grönke, Christian
2019-03-14 16:22             ` Guenter Roeck [this message]
2019-03-14 16:53             ` Guenter Roeck
2019-03-15 10:19               ` AW: " Grönke, Christian
2019-03-15 18:29                 ` Guenter Roeck
2019-03-15 19:38                   ` Guenter Roeck
2019-03-16 15:27                     ` Guenter Roeck
2019-03-13 16:21   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190314162256.GA21090@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=C.Groenke@infodas.de \
    --cc=linux-hwmon@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).