mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Phil Reid <preid@electromag.com.au>
To: Geert Uytterhoeven <geert+renesas@glider.be>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Gabor Juhos <juhosg@openwrt.org>,
	Miguel Gaio <miguel.gaio@efixo.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: 74x164: Implement gpiochip.set_multiple()
Date: Tue, 15 Mar 2016 12:04:17 +0800	[thread overview]
Message-ID: <56E789C1.2070907@electromag.com.au> (raw)
In-Reply-To: <1457968758-22670-1-git-send-email-geert+renesas@glider.be>

On 14/03/2016 11:19 PM, Geert Uytterhoeven wrote:
> This allows to set multiple outputs using a single SPI transfer.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Phil Reid <preid@electromag.com.au>


I do have a general question about GPIO drivers.
pca953x does not update the cached data unless the write operation
was successful. Which I folowed with the implement of set_multiple.
However a number of other drivers update regardless.
eg chip->buffer is updated even if the write_config fails.

What is the preferred approach?

> ---
>   drivers/gpio/gpio-74x164.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
>
> diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
> index c81224ff2dca988b..62291a81c97f7140 100644
> --- a/drivers/gpio/gpio-74x164.c
> +++ b/drivers/gpio/gpio-74x164.c
> @@ -75,6 +75,29 @@ static void gen_74x164_set_value(struct gpio_chip *gc,
>   	mutex_unlock(&chip->lock);
>   }
>
> +static void gen_74x164_set_multiple(struct gpio_chip *gc, unsigned long *mask,
> +				    unsigned long *bits)
> +{
> +	struct gen_74x164_chip *chip = gpiochip_get_data(gc);
> +	unsigned int i, idx, shift;
> +	u8 bank, bankmask;
> +
> +	mutex_lock(&chip->lock);
> +	for (i = 0, bank = chip->registers - 1; i < chip->registers;
> +	     i++, bank--) {
> +		idx = i / sizeof(*mask);
> +		shift = i % sizeof(*mask) * BITS_PER_BYTE;
> +		bankmask = mask[idx] >> shift;
> +		if (!bankmask)
> +			continue;
> +
> +		chip->buffer[bank] &= ~bankmask;
> +		chip->buffer[bank] |= bankmask & (bits[idx] >> shift);
> +	}
> +	__gen_74x164_write_config(chip);
> +	mutex_unlock(&chip->lock);
> +}
> +
>   static int gen_74x164_direction_output(struct gpio_chip *gc,
>   		unsigned offset, int val)
>   {
> @@ -114,6 +137,7 @@ static int gen_74x164_probe(struct spi_device *spi)
>   	chip->gpio_chip.direction_output = gen_74x164_direction_output;
>   	chip->gpio_chip.get = gen_74x164_get_value;
>   	chip->gpio_chip.set = gen_74x164_set_value;
> +	chip->gpio_chip.set_multiple = gen_74x164_set_multiple;
>   	chip->gpio_chip.base = -1;
>
>   	chip->registers = nregs;
>


-- 
Regards
Phil Reid

  reply	other threads:[~2016-03-15  4:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 15:19 Geert Uytterhoeven
2016-03-15  4:04 ` Phil Reid [this message]
2016-03-22 10:56   ` Linus Walleij
2016-03-22 10:54 ` Linus Walleij

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=56E789C1.2070907@electromag.com.au \
    --to=preid@electromag.com.au \
    --cc=geert+renesas@glider.be \
    --cc=gnurou@gmail.com \
    --cc=juhosg@openwrt.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.gaio@efixo.com \
    /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

all inboxes | Powered by JetHome®