From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback
Date: Tue, 13 Mar 2018 16:20:27 -0400 [thread overview]
Message-ID: <20180313202027.GA14944@sophia> (raw)
In-Reply-To: <CAHp75Vf9+=rie5oqmAp7yW3_AirGuvBtxGS=6y9UBHzjpvD9ww@mail.gmail.com>
On Tue, Mar 13, 2018 at 06:04:33PM +0200, Andy Shevchenko wrote:
>On Mon, Mar 12, 2018 at 10:49 PM, William Breathitt Gray
><vilhelm.gray@gmail.com> wrote:
>
>> +static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
>> + unsigned long *mask, unsigned long *bits)
>> +{
>
>
>> + /* clear bits array to a clean slate */
>> + for (i = 0; i < chip->ngpio; i += BITS_PER_LONG)
>> + bits[i / BITS_PER_LONG] = 0;
>
>bitmap_clear() or bitmap_zero()
bitmap_zero() would be perfect for this situation. I'll submit a version
2 of this patchset with this change for the various drivers herein.
>
>> + /* get bits are evaluated a gpio register size at a time */
>> + for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
>> + bit_word_offset = i % BITS_PER_LONG;
>> + bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset);
>> + if (!bits_mask) {
>> + /* no get bits in this register so skip to next one */
>> + continue;
>> + }
>
>for_each_set_bit() ?
>
>> + /* store acquired bits */
>> + bits[BIT_WORD(i)] |= port_state << bit_word_offset;
>
>__set_bit()
>__clear_bit()
I'm not sure for_each_set_bit() and __set_bit()/__clear_bit() would be
good for this particular situation since I'm working with the entire
register word (8 bits for this specific device) at a time.
Since I know each register word is 8-bits, I can make 8-bit jumps and
skips rather than evaluating each bit individually. Similarly, it seems
more efficient to store the input 8 bits at a time rather than breaking
it up to individual bits.
However, I do see how all these inline bitwise operations could make it
difficult to follow the code, so perhaps I can break it up across more
lines so that the logic of the loop becomes easier to read.
William Breathitt Gray
>
>We have bitmap API for *ages*. Is it too hard to check?
>
>--
>With Best Regards,
>Andy Shevchenko
next prev parent reply other threads:[~2018-03-13 20:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 20:48 [PATCH 0/8] Implement get_multiple for ACCES and PC104 drivers William Breathitt Gray
2018-03-12 20:48 ` [PATCH 1/8] iio: stx104: Implement get_multiple callback William Breathitt Gray
2018-03-12 20:48 ` [PATCH 2/8] gpio: 104-idio-16: " William Breathitt Gray
2018-03-12 20:49 ` [PATCH 3/8] gpio: pci-idio-16: " William Breathitt Gray
2018-03-13 14:32 ` kbuild test robot
2018-03-13 16:04 ` Andy Shevchenko
2018-03-13 20:20 ` William Breathitt Gray [this message]
2018-03-12 20:49 ` [PATCH 4/8] gpio: pcie-idio-24: " William Breathitt Gray
2018-03-13 14:33 ` kbuild test robot
2018-03-12 20:49 ` [PATCH 5/8] gpio: 104-dio-48e: " William Breathitt Gray
2018-03-12 20:49 ` [PATCH 6/8] gpio: 104-idi-48: " William Breathitt Gray
2018-03-12 20:50 ` [PATCH 7/8] gpio: gpio-mm: " William Breathitt Gray
2018-03-12 20:50 ` [PATCH 8/8] gpio: ws16c48: " William Breathitt Gray
2018-03-13 16:25 ` Andy Shevchenko
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=20180313202027.GA14944@sophia \
--to=vilhelm.gray@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@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).