All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Yegor Yefremov <yegorslists@googlemail.com>
Cc: Linux GPIO List <linux-gpio@vger.kernel.org>, brgl@bgdev.pl
Subject: Re: Reading current output value
Date: Wed, 22 Jun 2022 18:26:32 +0800	[thread overview]
Message-ID: <20220622102632.GA37027@sol> (raw)
In-Reply-To: <CAGm1_kvsAir70H41RJ5vzAGeBLBAFByHyR3fWfFeq3RW5O7cBA@mail.gmail.com>

On Wed, Jun 22, 2022 at 09:54:41AM +0200, Yegor Yefremov wrote:
> On a am335x based board I have a GPIO pin that enables/disables power
> of an external device (the bootloader sets this pin to output and 1,
> and the kernel is instructed to not change it). Using kernel
> 5.19.0-rc2 and sysfs interface, I can read the current status as
> follows:
> 
> echo 68 > /sys/class/gpio/export
> cat /sys/class/gpio/gpio68/value
> 
> As a result, I read 1.
> 
> Using gpioget (libgpiod) v1.6.3, the line will be configured to
> "input" and the value is set to 0:
> 
> # gpioget 2 4
> 0
> 
> So, how can I read the state without changing it? I am mostly
> interested in using the kernel userspace API directly.
> 

The API itself supports it, but it isn't exposed in gpioget v1.6.3.
The gpioget in libgpiod master has a --dir-as-is option for exactly
this case, but that hasn't made its way into a libgpiod release yet.
(commit 3a912fbc1e2 tools: gpioget: add new --dir-as-is option for GPO read-back)
Can you try master?

> By the way, setting pin to 0 works but not to 1:
> 
> gpioset 2 4=0 - OK
> gpioset 2 4=1 - no level change
> 

gpioset has to remain running to guarantee the output level.
The pin is probably reverting when gpioset exits.
Try the --mode=wait option.

> sysfs works.
> 

Yes and no.

Cheers,
Kent.

  reply	other threads:[~2022-06-22 10:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  7:54 Reading current output value Yegor Yefremov
2022-06-22 10:26 ` Kent Gibson [this message]
2022-06-22 10:56   ` Andy Shevchenko
2022-06-27 10:37   ` Yegor Yefremov
2022-06-28  4:52     ` Kent Gibson
2022-06-29  2:14       ` Kent Gibson
2022-06-29  7:50         ` Yegor Yefremov
2022-06-29  8:20           ` Kent Gibson

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=20220622102632.GA37027@sol \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    --cc=yegorslists@googlemail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.