linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [libgpiod][PATCH] core: Basic port to uAPI v2
Date: Sat, 3 Oct 2020 00:06:36 +0800	[thread overview]
Message-ID: <20201002160636.GA117143@sol> (raw)
In-Reply-To: <CAHp75VfVDsxHDcnwdO5TL=wx-rB6=cuCWOxj0oP7+kpZvKuH6A@mail.gmail.com>

On Fri, Oct 02, 2020 at 04:48:02PM +0300, Andy Shevchenko wrote:
> On Fri, Oct 2, 2020 at 9:32 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > Port existing implementation from GPIO uAPI v1 to v2.
> > The libgpiod external interface remains unchanged, only the internal
> > implementation switches from uAPI v1 to v2.
> 
> Cool!
> 

Not terribly - I needed a libgpiod-based testbed for my kernel
changes, and this was the easiest way to do it.
By happy coincidence that aligns with the path Bart wants to take for
libgpiod 2.0, so here we are.

> > This is a minimal port - uAPI v2 features are only used where it
> > simplifies the implementation, specifically multiple events on a bulk can
> > now be handled directly by the kernel in a single v2 line request rather
> > than being emulated by multiple v1 event requests.
> 
> ...
> 
> > +       if (config->flags & GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE)
> > +               bias_flags++;
> > +       if (config->flags & GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP)
> > +               bias_flags++;
> > +       if (config->flags & GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN)
> > +               bias_flags++;
> > +       if (bias_flags > 1)
> > +               return false;
> 
> Seems to me like an emulation of hweight(), although I don't know if
> we have in standard libraries such.
> 

Yup, same here, and it was quicker at the time to just write this than go
looking...


> ...
> 
> > -       if (values) {
> > -               for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++)
> > -                       data.values[i] = (uint8_t)!!values[i];
> > +       for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) {
> > +               lines_bitmap_set_bit(&lv.mask, i);
> > +               lines_bitmap_assign_bit(&lv.bits, i, values && values[i]);
> >         }
> 
> Hmm... What about
>        for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++)
>                lines_bitmap_set_bit(&lv.mask, i);
> 
>   if (values) {
>        for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++)
>                lines_bitmap_assign_bit(&lv.bits, i, values[i]);
>   }
> 
> ?
> 

I find mine easier to read.
Yours may be slightly faster though.  And maybe larger?

> ...
> 
> >         /*
> >          * 16 is the maximum number of events the kernel can store in the FIFO
> >          * so we can allocate the buffer on the stack.
> > +        *
> > +        * NOTE: This is no longer strictly true for uAPI v2.  While 16 is
> > +        * the default for single line, a request with multiple lines will
> 
> for a single
> 
> > +        * have a larger buffer.  So need to rethink the allocation here,
> 
> So we (I, ...?) need
> 

The purpose of this patch is to move what work I'd already done on
libgpiod in my tree, in order to test the kernel changes, into Bart's
libgpiod tree, where it can be used as the basis of 2.0 development.

So that note is a reminder for Bart, or whoever gets there first...
But leaving it vague is still grammatically correct.

Cheers,
Kent.

  reply	other threads:[~2020-10-02 16:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02  6:31 [libgpiod][PATCH] core: Basic port to uAPI v2 Kent Gibson
2020-10-02 13:48 ` Andy Shevchenko
2020-10-02 16:06   ` Kent Gibson [this message]
2020-10-05 10:27     ` Bartosz Golaszewski
2020-10-12 10:37 ` Bartosz Golaszewski
2020-10-13  7:08 ` Bartosz Golaszewski
2020-10-13  8:30   ` Kent Gibson
2020-10-14  3:17   ` Kent Gibson
2020-10-14  7:37     ` Bartosz Golaszewski
2020-10-14  8:51       ` Kent Gibson
2020-10-14  8:52         ` Bartosz Golaszewski

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=20201002160636.GA117143@sol \
    --to=warthog618@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-gpio@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).