linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rabin Vincent <rabin@rab.in>
To: linux-fbdev@vger.kernel.org
Subject: fb_setcolreg(), CNVT_TOHW() and chan_to_field()
Date: Tue, 25 Oct 2011 07:46:03 +0000	[thread overview]
Message-ID: <20111025073349.GB6027@debian> (raw)

I'm trying to figure out the best way to implement fb_setcolreg() for
FB_VISUAL_TRUECOLOR.

14 or so drivers copy/paste the CNVT_TOHW from skeletonfb.c:

 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
 ...
 red = CNVT_TOHW(red, info->var.red.length);

Another 18 or so drivers copy/paste a chan_to_field() function which has
a straightforward shift:

 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
 {
 	chan &= 0xffff;
 	chan >>= 16 - bf->length;
 	return chan << bf->offset;
 }
 ...
 val = chan_to_field(red, &info->var.red);

Both methods return similar values, except that with CNVT_TOHW() the
extreme values seem to have a smaller range than the other values, while
with the chan_to_field() shift all the values have an equal range.

What's the reason behind choosing one over the other?  Could/should a
common function be provided for all the drivers to use?

             reply	other threads:[~2011-10-25  7:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-25  7:46 Rabin Vincent [this message]
2011-10-25 11:15 ` fb_setcolreg(), CNVT_TOHW() and chan_to_field() Geert Uytterhoeven
2011-10-25 15:25 ` Rabin Vincent

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=20111025073349.GB6027@debian \
    --to=rabin@rab.in \
    --cc=linux-fbdev@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).