From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linux PM list <linux-pm@vger.kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Khiem Nguyen <khiem.nguyen.xt@renesas.com>,
Kuninori Morimoto <kuninori.morimoto.gx@gmail.com>,
Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Eduardo Valentin <edubezval@gmail.com>,
Hien Dang <hien.dang.eb@renesas.com>,
Thao Nguyen <thao.nguyen.yb@rvc.renesas.com>
Subject: Re: [PATCHv5 2/5] thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver
Date: Tue, 13 Dec 2016 10:53:05 +0100 [thread overview]
Message-ID: <20161213095305.GA28801@bigcity.dyn.berto.se> (raw)
In-Reply-To: <CAMuHMdVpuWO9Do9VvkVjZoEOCbmd72Gah-d2f4GCZavpo9EGpQ@mail.gmail.com>
Hi Geert,
Thanks for your feedback.
On 2016-12-13 09:19:53 +0100, Geert Uytterhoeven wrote:
> Hi Niklas,
>
> On Mon, Dec 12, 2016 at 3:18 PM, Niklas Söderlund
> <niklas.soderlund@ragnatech.se> wrote:
> > +/*
> > + * Linear approximation for temperature
> > + *
> > + * [reg] = [temp] * a + b => [temp] = ([reg] - b) / a
> > + *
> > + * The constants a and b are calculated using two triplets of int values PTAT
> > + * and THCODE. PTAT and THCODE can either be read from hardware or use hard
> > + * coded values from driver. The formula to calculate a and b are taken from
> > + * BSP and sparsely documented and understood.
> > + *
> > + * Examining the linear formula and the formula used to calculate constants a
> > + * and b while knowing that the span for PTAT and THCODE values are between
> > + * 0x000 and 0xfff the largest integer possible is 0xfff * 0xfff == 0xffe001.
> > + * Integer also needs to be signed so that leaves 7 bits for decimal
> > + * fixed point scaling, which amounts to a decimal scaling factor of 100.
> > + */
> > +
> > +#define SCALE_FACTOR 100
>
> What about using 128 instead?
> Fixed point is much easier with shifts
> (the compiler will turn multiplications in shifts where appropriate).
I tried using binary scaled instead of decimal scaled fixed point but
noticed that the diff I got compared to the original formula which used
decimal scaled (factor 1000) where larger so I picked decimal scaling.
Maybe with feedback from Morimoto-san or Khiem we can switch to binary
scaled number as it should over all increase the accuracy of the
calculations, but then maybe some of the other hard coded constant also
should be updated?
>
> > +#define SCALE_INT(_x) ((_x) * SCALE_FACTOR)
> > +#define SCALE_MUL(_a, _b) (((_a)*(_b)) / SCALE_FACTOR)
> > +#define SCALE_DIV(_a, _b) (((_a)*SCALE_FACTOR)/(_b))
>
> DIV_ROUND_CLOSEST()
Don't DIV_ROUND_CLOSEST() require the divisor to be a positive integer?
tj_2 = SCALE_DIV(SCALE_MUL(SCALE_INT(ptat[1] - ptat[2]), SCALE_INT(137)),
SCALE_INT(ptat[0] - ptat[2])) - SCALE_INT(41);
In this case if ptat[0] < (ptat[2] + 41) the divisor is negative so I
think DIV_ROUND_CLOSEST() can't be used, or am I misunderstanding?
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
--
Regards,
Niklas Söderlund
next prev parent reply other threads:[~2016-12-13 9:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-12 14:18 [PATCHv5 0/5] thermal: add driver for R-Car Gen3 Niklas Söderlund
2016-12-12 14:18 ` [PATCHv5 1/5] thermal: rcar_gen3_thermal: Document the " Niklas Söderlund
2016-12-12 14:18 ` [PATCHv5 2/5] thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver Niklas Söderlund
2016-12-12 21:45 ` Wolfram Sang
2016-12-13 8:25 ` Geert Uytterhoeven
2016-12-13 8:39 ` Wolfram Sang
2016-12-13 10:07 ` Niklas Söderlund
2016-12-13 3:50 ` Eduardo Valentin
2016-12-13 5:38 ` Wolfram Sang
2016-12-13 9:43 ` Niklas Söderlund
2016-12-14 4:38 ` Eduardo Valentin
2016-12-13 8:19 ` Geert Uytterhoeven
2016-12-13 9:53 ` Niklas Söderlund [this message]
2016-12-13 10:09 ` Geert Uytterhoeven
2016-12-12 14:18 ` [PATCHv5 3/5] arm64: dts: r8a7795: Add R-Car Gen3 thermal support Niklas Söderlund
2016-12-12 14:18 ` [PATCHv5 4/5] arm64: dts: r8a7796: " Niklas Söderlund
2016-12-12 14:18 ` [PATCHv5 5/5] thermal: rcar_gen3_thermal: Add delay in .thermal_init on r8a7795 Niklas Söderlund
2016-12-13 3:31 ` Eduardo Valentin
2016-12-13 9:15 ` Niklas Söderlund
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=20161213095305.GA28801@bigcity.dyn.berto.se \
--to=niklas.soderlund@ragnatech.se \
--cc=edubezval@gmail.com \
--cc=geert@linux-m68k.org \
--cc=hien.dang.eb@renesas.com \
--cc=khiem.nguyen.xt@renesas.com \
--cc=kuninori.morimoto.gx@gmail.com \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=thao.nguyen.yb@rvc.renesas.com \
--cc=wsa+renesas@sang-engineering.com \
/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).