LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux-Arch <linux-arch@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 0/7] Introduce the for_each_set_port_word macro
Date: Sun, 13 May 2018 18:11:45 +0300	[thread overview]
Message-ID: <CAHp75Vf8TLhj07VKeDdvzqHvViHqgRkd6=n2hZR_yY7in52SHA@mail.gmail.com> (raw)
In-Reply-To: <cover.1525785532.git.vilhelm.gray@gmail.com>

On Tue, May 8, 2018 at 4:26 PM, William Breathitt Gray
<vilhelm.gray@gmail.com> wrote:

> While adding GPIO get_multiple/set_multiple callback support for various
> drivers, I noticed a pattern of looping manifesting that would be useful
> standardized as a macro.
>
> This patchset introduces the for_each_set_port_word macro and utilizes
> it in several GPIO drivers. The for_each_set_port_word macro facilitates
> a for-loop syntax that iterates over entire groups of set bits at a
> time.
>
> For example, suppose you would like to iterate over a 16-bit integer 4
> bits at a time, skipping over 4-bit groups with no set bit, where XXXX
> represents the current 4-bit group:
>
>     Example:        1011 1110 0000 1111
>     First loop:     1011 1110 0000 XXXX

>     Second loop:    1011 XXXX 0000 1111

8-bit itteration. Is it correct?

>     Third loop:     XXXX 1110 0000 1111

Looking at the example above I highly recommend to introduce some test
cases for your helper function.

Consider extending lib/test_bitmap.c for this purpose.

>
> Each iteration of the loop returns the next 4-bit group that has at
> least one set bit.
>
> The for_each_set_port_word macro has six parameters:
>
>     * port_word: set to current port word index for the iteration
>     * word_index: set to current bitmap word index for the iteration
>     * word_offset: bits offset of the found port word in the bitmap word
>     * bits: bitmap to search within
>     * size: bitmap size in number of port words
>     * port_size: port word size in number of bits
>
> The port_size argument can be an arbitrary number of bits and is not
> required to be a multiple of 2.
>
> I've called the group of bits a "port word" which may be a confusing
> naming convention; I was afraid calling that them a "group" may be too
> vague. Should a different name be chosen; what would you suggest?
>
> This patchset was rebased on top of the following three commits:
>
>     * commit aaf96e51de11 ("gpio: pci-idio-16: Fix port memory offset for get_multiple callback")
>     * commit 304440aa96c6 ("gpio: pcie-idio-24: Fix port memory offset for get_multiple/set_multiple callbacks")
>     * commit e026646c178d ("gpio: pcie-idio-24: Fix off-by-one error in get_multiple loop")
>
> William Breathitt Gray
>
> William Breathitt Gray (7):
>   bitops: Introduce the for_each_set_port_word macro
>   gpio: 104-dio-48e: Utilize for_each_set_port_word macro
>   gpio: 104-idi-48: Utilize for_each_set_port_word macro
>   gpio: gpio-mm: Utilize for_each_set_port_word macro
>   gpio: ws16c48: Utilize for_each_set_port_word macro
>   gpio: pci-idio-16: Utilize for_each_set_port_word macro
>   gpio: pcie-idio-24: Utilize for_each_set_port_word macro
>
>  drivers/gpio/gpio-104-dio-48e.c   |  67 +++++---------------
>  drivers/gpio/gpio-104-idi-48.c    |  32 ++--------
>  drivers/gpio/gpio-gpio-mm.c       |  67 +++++---------------
>  drivers/gpio/gpio-pci-idio-16.c   |  67 ++++++--------------
>  drivers/gpio/gpio-pcie-idio-24.c  | 102 +++++++++++-------------------
>  drivers/gpio/gpio-ws16c48.c       |  66 +++++--------------
>  include/asm-generic/bitops/find.h |  26 ++++++++
>  include/linux/bitops.h            |   9 +++
>  lib/find_bit.c                    |  28 ++++++++
>  9 files changed, 172 insertions(+), 292 deletions(-)
>
> --
> 2.17.0
>



-- 
With Best Regards,
Andy Shevchenko

  parent reply	other threads:[~2018-05-13 15:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 13:26 William Breathitt Gray
2018-05-08 13:26 ` [PATCH v2 1/7] bitops: " William Breathitt Gray
2018-05-13 15:06   ` Andy Shevchenko
2018-05-14 13:04     ` William Breathitt Gray
2018-05-14 17:08       ` Andy Shevchenko
2018-05-08 13:27 ` [PATCH v2 2/7] gpio: 104-dio-48e: Utilize " William Breathitt Gray
2018-05-08 13:27 ` [PATCH v2 3/7] gpio: 104-idi-48: " William Breathitt Gray
2018-05-08 13:27 ` [PATCH v2 4/7] gpio: gpio-mm: " William Breathitt Gray
2018-05-08 13:27 ` [PATCH v2 5/7] gpio: ws16c48: " William Breathitt Gray
2018-05-08 13:28 ` [PATCH v2 6/7] gpio: pci-idio-16: " William Breathitt Gray
2018-05-08 13:28 ` [PATCH v2 7/7] gpio: pcie-idio-24: " William Breathitt Gray
2018-05-13 15:11 ` Andy Shevchenko [this message]
2018-05-14 12:57   ` [PATCH v2 0/7] Introduce the " William Breathitt Gray

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='CAHp75Vf8TLhj07VKeDdvzqHvViHqgRkd6=n2hZR_yY7in52SHA@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vilhelm.gray@gmail.com \
    --subject='Re: [PATCH v2 0/7] Introduce the for_each_set_port_word macro' \
    /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

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).