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 v3 2/8] gpio: 104-idio-16: Implement get_multiple callback
Date: Wed, 21 Mar 2018 12:04:50 -0400 [thread overview]
Message-ID: <20180321160450.GA21405@sophia> (raw)
In-Reply-To: <CAHp75VcdimgN3u5O5zye2=pXvCkWuZzCf3e0wOQozQoKz7W8yA@mail.gmail.com>
On Wed, Mar 21, 2018 at 05:32:03PM +0200, Andy Shevchenko wrote:
>On Sat, Mar 17, 2018 at 5:50 PM, William Breathitt Gray
><vilhelm.gray@gmail.com> wrote:
>> The ACCES I/O 104-IDIO-16 series of devices provides 16
>> optically-isolated digital inputs accessed via two 8-bit ports. Since
>> eight input lines are acquired on a single port input read, the
>> 104-IDIO-16 GPIO driver may improve multiple input reads by utilizing a
>> get_multiple callback. This patch implements the
>> idio_16_gpio_get_multiple function which serves as the respective
>> get_multiple callback.
>
>> +static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
>> + unsigned long *mask, unsigned long *bits)
>> +{
>> + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
>> +
>> + *bits = 0;
>
>> + if (*mask & 0xFF0000)
>
>GENMASK(23, 16) ?
>
>> + *bits |= (unsigned long)inb(idio16gpio->base + 1) << 16;
>
>Do you need casting?
>
>> + if (*mask & 0xFF000000)
>
>GENMASK(31, 24) ?
>
>Alternative (and for above):
>
>(*mask >> 24) & 0xff
>
>(*mask >> 16) & 0xff
That's a good suggestion since GENMASK would be useful in making it
clear which bits we are actually checking; the literal bitmasks such as
0xFF000000 can be difficult to read at a glance. I'll incorporate
GENMASK into a version 4 release of this patch.
>
>
>> + *bits |= (unsigned long)inb(idio16gpio->base + 5) << 24;
>
>Do you need casting?
The inb function returns a u8, which is typically a typedef of an
unsigned char. Since u8 only guaranteed a range of 8 bits, we require a
cast to unsigned long to guarantee that the left shifted value stays
intact as a 32-bit unsigned value rather than wrap around an 8-bit
unsigned range.
William Breathitt Gray
>
>> +
>> + return 0;
>> +}
>> +
>> static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
>> {
>> struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
>> @@ -244,6 +258,7 @@ static int idio_16_probe(struct device *dev, unsigned int id)
>> idio16gpio->chip.direction_input = idio_16_gpio_direction_input;
>> idio16gpio->chip.direction_output = idio_16_gpio_direction_output;
>> idio16gpio->chip.get = idio_16_gpio_get;
>> + idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple;
>> idio16gpio->chip.set = idio_16_gpio_set;
>> idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
>> idio16gpio->base = base[id];
>> --
>> 2.16.2
>>
>
>
>
>--
>With Best Regards,
>Andy Shevchenko
next prev parent reply other threads:[~2018-03-21 16:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-17 15:49 [PATCH v3 0/8] Implement get_multiple for ACCES and PC/104 drivers William Breathitt Gray
2018-03-17 15:49 ` [PATCH v3 1/8] iio: stx104: Implement get_multiple callback William Breathitt Gray
2018-03-17 18:22 ` Jonathan Cameron
2018-03-17 18:51 ` Andy Shevchenko
2018-03-17 19:15 ` William Breathitt Gray
2018-03-17 15:50 ` [PATCH v3 2/8] gpio: 104-idio-16: " William Breathitt Gray
2018-03-21 15:32 ` Andy Shevchenko
2018-03-21 16:04 ` William Breathitt Gray [this message]
2018-03-17 15:50 ` [PATCH v3 3/8] gpio: pci-idio-16: " William Breathitt Gray
2018-03-21 17:45 ` Andy Shevchenko
2018-03-21 18:49 ` William Breathitt Gray
2018-03-17 15:51 ` [PATCH v3 4/8] gpio: pcie-idio-24: Implement get_multiple/set_multiple callbacks William Breathitt Gray
2018-03-17 15:51 ` [PATCH v3 5/8] gpio: 104-dio-48e: Implement get_multiple callback William Breathitt Gray
2018-03-17 15:51 ` [PATCH v3 6/8] gpio: 104-idi-48: " William Breathitt Gray
2018-03-17 15:51 ` [PATCH v3 7/8] gpio: gpio-mm: " William Breathitt Gray
2018-03-17 15:52 ` [PATCH v3 8/8] gpio: ws16c48: " 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=20180321160450.GA21405@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.