public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@impinj.com>
To: "linux@roeck-us.net" <linux@roeck-us.net>,
	"m.felsch@pengutronix.de" <m.felsch@pengutronix.de>
Cc: "dmitry.torokhov@gmail.com" <dmitry.torokhov@gmail.com>,
	"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"jdelvare@suse.com" <jdelvare@suse.com>,
	"kernel@pengutronix.de" <kernel@pengutronix.de>
Subject: Re: [PATCH v2 2/2] hwmon: add generic GPIO brownout support
Date: Thu, 1 Nov 2018 18:21:10 +0000	[thread overview]
Message-ID: <1541096469.30311.166.camel@impinj.com> (raw)
In-Reply-To: <20181101151428.GB25346@roeck-us.net>

On Thu, 2018-11-01 at 08:14 -0700, Guenter Roeck wrote:
> On Thu, Nov 01, 2018 at 03:53:12PM +0100, Marco Felsch wrote:
> > 
> > > 
> > > Isn't that configurable with devicetree flags ? I don't think a driver
> > > should get involved in deciding the active edge.
> > 
> > No, AFAIK we can only specify the active level types for gpios. This
> > made sense to me, because I saw no gpio-controller which support
> > 'edge-level' reporting (however it will be called) currently.

Interrupts types are specific to each interrupt controller, but there
is a standard set of flags that, AFAIK, every Linux controller uses. 
These include IRQ_TYPE_EDGE_BOTH, IRQ_TYPE_EDGE_RISING,
IRQ_TYPE_LEVEL_HIGH, and so on.

So you can support hardware that is inherently edge or level triggered.
 

I have used edge triggered interrupts on GPIO pins on many designs.

From what I remember, most hwmon chips use level triggered signals. 
The general process in the driver:

Level goes to asserted, IRQ handler invoked
Ack interrupt in hwmon chip's alarm register, which usually de-asserts
the alarm line
Set bit in driver state to indicate the alarm attribute should be set
sysfs_notify anything polling the attribute
If alarm line did not de-assert on ack, leave IRQ masked
Sysfs attribute stays set until userspace process acks it (by reading)

The important part here is that the alarm is latched in the driver.  We
don't just report the current alarm status in the attribute.  Otherwise
an alarm could come and go without anyone noticing if they didn't read
the attribute at just the right time.

Put another way, the hwmon alarm attribute means an alarm occurred
since the last time the attribute was reset.  It does not mean the
alarm is currently active.

This also means the driver does not need to continuously track the
alarm status.  Once we detect the first alarm, we don't care what it
does until the alarm status is reset and we need to watch for alarms
again.

If one has something like an op-amp voltage comparator, I think the
driver would register a level interrupt.  It be left masked after the
irq handler notes the alarm, to prevent immediately re-asserting.  This
is normal for level interrupts that can not be de-asserted by an action
of the irq handler.  It would be unmasked on the ack/read of the alarm
attribute.  That would trigger another interrupt if the alarm signal is
still asserted.

If instead, you tried registering for IRQs on both edges, then it's not
reliable.  It's possible for the edges to come in too fast, before the
irq controller or the kernel is ready for them, and then you get out of
sync.

  reply	other threads:[~2018-11-01 18:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29 14:35 [PATCH v2 0/2] Add GPIO brownout detection support Marco Felsch
2018-10-29 14:35 ` [PATCH v2 1/2] dt-binding: hwmon: add gpio-brownout bindings Marco Felsch
2018-10-29 14:35 ` [PATCH v2 2/2] hwmon: add generic GPIO brownout support Marco Felsch
2018-10-29 19:52   ` Guenter Roeck
2018-10-29 21:16     ` Trent Piepho
2018-10-30  1:12       ` Guenter Roeck
2018-10-30 10:47         ` Marco Felsch
2018-10-30 13:13           ` Guenter Roeck
2018-10-30 17:00             ` Marco Felsch
2018-10-30 19:34               ` Trent Piepho
2018-10-30 20:11                 ` Guenter Roeck
2018-11-01 10:40                   ` Marco Felsch
2018-11-01 13:01                     ` Guenter Roeck
2018-11-01 14:53                       ` Marco Felsch
2018-11-01 15:14                         ` Guenter Roeck
2018-11-01 18:21                           ` Trent Piepho [this message]
2018-11-02  6:38                             ` Marco Felsch
2018-11-02 23:05                               ` Trent Piepho
2018-11-05  8:19                                 ` Marco Felsch
2018-11-06 20:50                                   ` Trent Piepho
2018-11-07  9:35                                     ` Marco Felsch
2018-11-07 18:07                                       ` Trent Piepho
2018-11-01 13:02                     ` Guenter Roeck
2018-11-01 14:58                       ` Marco Felsch
2018-11-01 15:08                         ` Guenter Roeck
2018-11-01 17:41                     ` Trent Piepho
2018-11-02  6:48                       ` Marco Felsch
2018-10-30 19:56               ` Guenter Roeck
2018-11-01  9:44                 ` Marco Felsch
2018-10-30 18:54           ` Trent Piepho
2018-10-30 18:49         ` Trent Piepho
2018-10-30 20:13           ` Guenter Roeck

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=1541096469.30311.166.camel@impinj.com \
    --to=tpiepho@impinj.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=m.felsch@pengutronix.de \
    /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