Skip to contentSkip to conversation

gpio: max732x: add set_multiple function

PATCH In review Mans Rullgard 2 participants 3 messages Jan 21, 2015 – Jan 30, 2015 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: max732x: add set_multiple function

This adds a set_multiple function to the MAX732x GPIO driver, allowing for performance gains when using gpiod_set_array().

---
 drivers/gpio/gpio-max732x.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/gpio/gpio-max732x.c +25 -3
index f860837..ef7eef8 100644
@@ -210,10 +210,11 @@ static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off)
 	return reg_val & (1u << (off & 0x7));
 }
 
-static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
+static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask,
+				  int val)
 {
 	struct max732x_chip *chip;
-	uint8_t reg_out, mask = 1u << (off & 0x7);
+	uint8_t reg_out;
 	int ret;
 
 	chip = container_of(gc, struct max732x_chip, gpio_chip);
@@ -221,7 +222,7 @@ static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
 	mutex_lock(&chip->lock);
 
 	reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0];
-	reg_out = (val) ? reg_out | mask : reg_out & ~mask;
+	reg_out = (reg_out & ~mask) | (val & mask);
 
 	ret = max732x_writeb(chip, is_group_a(chip, off), reg_out);
 	if (ret < 0)
@@ -236,6 +237,26 @@ out:
 	mutex_unlock(&chip->lock);
 }
 
+static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
+{
+	unsigned base = off & ~0x7;
+	uint8_t mask = 1u << (off & 0x7);
+
+	max732x_gpio_set_mask(gc, base, mask, val << (off & 0x7));
+}
+
+static void max732x_gpio_set_multiple(struct gpio_chip *gc,
+				      unsigned long *mask, unsigned long *bits)
+{
+	unsigned mask_lo = mask[0] & 0xff;
+	unsigned mask_hi = (mask[0] >> 8) & 0xff;
+
+	if (mask_lo)
+		max732x_gpio_set_mask(gc, 0, mask_lo, bits[0] & 0xff);
+	if (mask_hi)
+		max732x_gpio_set_mask(gc, 8, mask_hi, (bits[0] >> 8) & 0xff);
+}
+
 static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
 {
 	struct max732x_chip *chip;
@@ -579,6 +600,7 @@ static int max732x_setup_gpio(struct max732x_chip *chip,
 	if (chip->dir_output) {
 		gc->direction_output = max732x_gpio_direction_output;
 		gc->set = max732x_gpio_set_value;
+		gc->set_multiple = max732x_gpio_set_multiple;
 	}
 	gc->get = max732x_gpio_get_value;
 	gc->can_sleep = true;
Signature · 1 line
2.0.5
#1 lore raw
Quoted 4 lines · Mans Rullgard

This adds a set_multiple function to the MAX732x GPIO driver, allowing for performance gains when using gpiod_set_array().

Patch applied, thanks Måns!
BTW: are you interested in maintaining this driver?

It needs converting to GPIOLIB_IRQCHIP so I'll cook a patch set for this, if you're using IRQs with this driver, can you pls help out testing it? Thanks a lot with sugar on top.

Yours,
Linus Walleij

#2 lore raw
Quoted 5 lines · Linus Walleij
Quoted 3 lines · Mans Rullgard

This adds a set_multiple function to the MAX732x GPIO driver, allowing for performance gains when using gpiod_set_array().

Quoted 8 lines
Quoted 1 line

Patch applied, thanks Måns!
BTW: are you interested in maintaining this driver?

It needs converting to GPIOLIB_IRQCHIP so I'll cook a patch set for this, if you're using IRQs with this driver, can you pls help out testing it? Thanks a lot with sugar on top.

I don't have one with the interrupt line connected, so I can't really help with that.

Signature · 6 lines
Måns Rullgård
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html