linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Laxman Dewangan <ldewangan@nvidia.com>,
	linus.walleij@linaro.org, swarren@wwwdotorg.org,
	thierry.reding@gmail.com
Cc: linux-gpio@vger.kernel.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2] gpio: tegra: Implement gpio_get_direction callback
Date: Fri, 29 Apr 2016 18:15:04 +0100	[thread overview]
Message-ID: <57239698.80901@nvidia.com> (raw)
In-Reply-To: <1461947123-18170-1-git-send-email-ldewangan@nvidia.com>


On 29/04/16 17:25, Laxman Dewangan wrote:
> Implement gpio_get_direction() callback for Tegra GPIO.
> The direction is only valid if the pin is configured as
> GPIO. If pin is not configured in GPIO mode then this
> function return error.
> 
> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
> 
> ---
> This patch is based on discussion on series
> Re: [PATCH V5 0/4] gpio: tegra: Cleanups and support for debounce
> From Linus W:
> It would be nice if you also implement .get_direction() which makes
> debugfs and initial reading of the state of the lines more accurate.
> 
> V1->V2:
> - Rearrange the calls to optimise the register access and avoid
>  much indenting based on Stephen's and Jon review.
> 
>  drivers/gpio/gpio-tegra.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index b3ddd92..ec891a27 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -191,6 +191,21 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
>  	return 0;
>  }
>  
> +static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
> +{
> +	struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
> +	u32 pin_mask = BIT(GPIO_BIT(offset));
> +	u32 cnf, oe;
> +
> +	cnf = tegra_gpio_readl(tgi, GPIO_CNF(tgi, offset));
> +	if (!(cnf & pin_mask))
> +		return -EINVAL;
> +
> +	oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset));
> +
> +	return (oe & pin_mask) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
> +}
> +
>  static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
>  				   unsigned int debounce)
>  {
> @@ -575,6 +590,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
>  	tgi->gc.get			= tegra_gpio_get;
>  	tgi->gc.direction_output	= tegra_gpio_direction_output;
>  	tgi->gc.set			= tegra_gpio_set;
> +	tgi->gc.get_direction		= tegra_gpio_get_direction;
>  	tgi->gc.to_irq			= tegra_gpio_to_irq;
>  	tgi->gc.base			= 0;
>  	tgi->gc.ngpio			= tgi->bank_count * 32;

Acked-by: Jon Hunter <jonathanh@nvidia.com>

Cheers
Jon


  parent reply	other threads:[~2016-04-29 17:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 16:25 [PATCH V2] gpio: tegra: Implement gpio_get_direction callback Laxman Dewangan
2016-04-29 16:47 ` Stephen Warren
2016-04-29 17:15 ` Jon Hunter [this message]
2016-04-30 11:16 ` 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=57239698.80901@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=ldewangan@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=swarren@wwwdotorg.org \
    --cc=thierry.reding@gmail.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;
as well as URLs for NNTP newsgroup(s).