diff mbox

[v3,2/8] gpio: 104-idio-16: Implement get_multiple callback

Message ID 486eb9bad0440ed305a78d9fc990728cbeb7d43e.1521301345.git.vilhelm.gray@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

William Breathitt Gray March 17, 2018, 3:50 p.m. UTC
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.

Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 drivers/gpio/gpio-104-idio-16.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Andy Shevchenko March 21, 2018, 3:32 p.m. UTC | #1
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


> +               *bits |= (unsigned long)inb(idio16gpio->base + 5) << 24;

Do you need casting?

> +
> +       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
>
William Breathitt Gray March 21, 2018, 4:04 p.m. UTC | #2
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
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpio-104-idio-16.c b/drivers/gpio/gpio-104-idio-16.c
index 2f16638a0589..5de5819e5156 100644
--- a/drivers/gpio/gpio-104-idio-16.c
+++ b/drivers/gpio/gpio-104-idio-16.c
@@ -90,6 +90,20 @@  static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset)
 	return !!(inb(idio16gpio->base + 5) & (mask>>8));
 }
 
+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)
+		*bits |= (unsigned long)inb(idio16gpio->base + 1) << 16;
+	if (*mask & 0xFF000000)
+		*bits |= (unsigned long)inb(idio16gpio->base + 5) << 24;
+
+	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];