Skip to content

Commit 09107a5

Browse files
alexandrebelloniLinus Walleij
authored andcommitted
pinctrl: at91-pio4: implement .get_multiple and .set_multiple
Implement .get_multiple and .set_multiple to allow reading or setting multiple pins simultaneously. Pins in the same bank will all be switched at the same time, improving synchronization and performances. Keep the driver future proof by allowing its use on 64bits platforms if they ever appear with this IP and we end up with a mismatch between ATMEL_PIO_NPINS_PER_BANK and BITS_PER_LONG. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Link: https://lore.kernel.org/r/20190918113657.25998-1-alexandre.belloni@bootlin.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 0074a66 commit 09107a5

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎drivers/pinctrl/pinctrl-at91-pio4.c‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,33 @@ static int atmel_gpio_get(struct gpio_chip *chip, unsigned offset)
328328
return !!(reg & BIT(pin->line));
329329
}
330330

331+
static int atmel_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
332+
unsigned long *bits)
333+
{
334+
struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
335+
unsigned int bank;
336+
337+
bitmap_zero(bits, atmel_pioctrl->npins);
338+
339+
for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) {
340+
unsigned int word = bank;
341+
unsigned int offset = 0;
342+
unsigned int reg;
343+
344+
#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
345+
word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK);
346+
offset = bank * ATMEL_PIO_NPINS_PER_BANK % BITS_PER_LONG;
347+
#endif
348+
if (!mask[word])
349+
continue;
350+
351+
reg = atmel_gpio_read(atmel_pioctrl, bank, ATMEL_PIO_PDSR);
352+
bits[word] |= mask[word] & (reg << offset);
353+
}
354+
355+
return 0;
356+
}
357+
331358
static int atmel_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
332359
int value)
333360
{
@@ -358,11 +385,46 @@ static void atmel_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
358385
BIT(pin->line));
359386
}
360387

388+
static void atmel_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask,
389+
unsigned long *bits)
390+
{
391+
struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
392+
unsigned int bank;
393+
394+
for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) {
395+
unsigned int bitmask;
396+
unsigned int word = bank;
397+
398+
/*
399+
* On a 64-bit platform, BITS_PER_LONG is 64 so it is necessary to iterate over
400+
* two 32bit words to handle the whole bitmask
401+
*/
402+
#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
403+
word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK);
404+
#endif
405+
if (!mask[word])
406+
continue;
407+
408+
bitmask = mask[word] & bits[word];
409+
atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_SODR, bitmask);
410+
411+
bitmask = mask[word] & ~bits[word];
412+
atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_CODR, bitmask);
413+
414+
#if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
415+
mask[word] >>= ATMEL_PIO_NPINS_PER_BANK;
416+
bits[word] >>= ATMEL_PIO_NPINS_PER_BANK;
417+
#endif
418+
}
419+
}
420+
361421
static struct gpio_chip atmel_gpio_chip = {
362422
.direction_input = atmel_gpio_direction_input,
363423
.get = atmel_gpio_get,
424+
.get_multiple = atmel_gpio_get_multiple,
364425
.direction_output = atmel_gpio_direction_output,
365426
.set = atmel_gpio_set,
427+
.set_multiple = atmel_gpio_set_multiple,
366428
.to_irq = atmel_gpio_to_irq,
367429
.base = 0,
368430
};

0 commit comments

Comments
 (0)