All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@impinj.com>
To: "m.felsch@pengutronix.de" <m.felsch@pengutronix.de>
Cc: "linux@roeck-us.net" <linux@roeck-us.net>,
	"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: Tue, 6 Nov 2018 20:50:27 +0000	[thread overview]
Message-ID: <1541537426.30311.271.camel@impinj.com> (raw)
In-Reply-To: <20181105081917.3af4v2c2wejsfnqe@pengutronix.de>

On Mon, 2018-11-05 at 09:19 +0100, Marco Felsch wrote:
> On 18-11-02 23:05, Trent Piepho wrote:
> > On Fri, 2018-11-02 at 07:38 +0100, Marco Felsch wrote:
> > > 
> > > > 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've been spoken about gpio-controllers and AFAIK there are no edge
> > > types. Interrupt-Controller are a different story, as you pointed out
> > > above.
> > 
> > You can use edge triggering with gpios.  Just try writing "rising" or
> > "falling" into /sys/class/gpio/gpioX/edge
> 
> Can we access the gpios trough the sysfs if they are requested by a
> driver?

When I first did the sysfs interface for gpios, you could do that, but
David Brownell wanted it so that you can't access gpios via sysfs if a
driver requested them.  The compromise was that *kernel* code can
explicitly export to sysfs a gpio that is used by a driver (ie. also
requested in kernel code), but you couldn't do it just from userspace.

But that's irrelevant here.  The point is that you can get edge
triggered interrupts on a gpio and if you don't believe me, just try it
for yourself and you'll see it works.  The sysfs interface just
translates into the same calls a kernel driver could make.

> > It's level you can't do sysfs.  The irq masking necessary isn't
> > supported to get it to work in a useful way, i.e. without a live-lock
> > IRQ loop.
> > 
> > But you can in the kernel.
> > 
> > Normal process is to call gpiod_to_irq() and then use standard IRQF
> > flags to select level, edge, etc.
> 
> Currently I using the gpiod_to_irq() function to convert the sense gpio
> into a irq, but I do some magic to determine the edge. I tought there
> might be reasons why there are no edge defines in
> include/dt-bindings/gpio/gpio.h.

Just request the interrupt with IRQF_TRIGGER_RISING and it will work on
almost any SoC.  The reason you see no edge defines with gpio handles
is that edge and level triggering is a interrupt concept, not a gpio
concept.  There are no level triggers defined for gpios either.  The
active low/high flags just define what voltage should be considered
"asserted".  They aren't intended to be related to interrupts.

> Okay, so no polling for the current solution. Let me summarize our
> solution:
>  - no polling (currently)
>  - dt-node specifies a gpio instead of a interrupt
>    -> gpio <-> irq mapping is done by gpiod_to_irq() and fails if gpio
>       doesn't support irq's
>  - more alarms per sensor
> 
> Only one last thing I tought about:
> 
> Using a flat design like you mentioned would lead into a "virtual"
> address conflict, since both sensors are on the same level. I tought
> about i2c/spi/muxes/graph-devices which don't support such "addressing"
> scheme.

You mean a temp alarm and a voltage alarm could both be reg = <1>?  I
don't think anything complains about that.  But it does seem
undesirable.


> hwmon_dev {
> 	compatible = "gpio-alarm";
> 	bat@0 {
> 		reg = <0>;
> 		label = "Battery Pack1 Voltage";
> 		type = "voltage";
> 		alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;

Would have to be <GPIO_ALARM_LCRIT>, <GPIO_ALARM_CRIT>;

I'm not sure if dt bindings prefer symbolic integer constants vs
strings for something which is an enumeration like this.  strings seem
more common to me, e.g. alarm-types = "lcrit", "crit";

> 		alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW
> 				&gpio3 16 GPIO_ACTIVE_LOW>;
> 	};
> 	bat@1 {
> 		reg = <1>;
> 		label = "Battery Pack2 Voltage";
> 		alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> 		alarm-gpios = <&gpio3 9 GPIO_ACTIVE_LOW
> 				&gpio3 1 GPIO_ACTIVE_LOW>;
> 	};
> 	cputemp@0 {
> 		reg = <0>;
> 		label = "CPU Temperature Critical";
> 		type = "temperature";
> 		alarm-type = <GPIO_ALARM_GENRIC>;
> 		alarm-gpios = <&gpio4 17 GPIO_ACTIVE_LOW>;
> 	};
> };
> 
> Where a more structured layout don't have this "issue".
> 
> hwmon_dev {
> 	compatible = "gpio-alarm";
> 
> 	voltage {
> 		bat@0 {
> 			reg = <0>;
> 	 		label = "Battery Pack1 Voltage";
> 			alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> 			alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW
> 					&gpio3 16 GPIO_ACTIVE_LOW>;
> 		};
> 		bat@1 {
> 			reg = <1>;
> 	 		label = "Battery Pack2 Voltage";
> 			alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> 			alarm-gpios = <&gpio3 9 GPIO_ACTIVE_LOW
> 					&gpio3 1 GPIO_ACTIVE_LOW>;
> 		};
> 	};
> 	temperature {
> 		cputemp {
> 			label = "CPU Temperature Critical";
> 			alarm-type = <GPIO_ALARM_GENRIC>;
> 			alarm-gpios = <&gpio4 17 GPIO_ACTIVE_LOW>;
> 		};
> 	};
> };
> 
> We don't have to take this layout, we can also consider about devices:
> 
> hwmon_dev {
> 	compatible = "gpio-alarm";
> 
> 	dev@0 {
> 		reg = <0>;
> 		voltage {
> 			label = "Battery Pack1 Voltage";
> 			alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> 			alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW
> 					&gpio3 16 GPIO_ACTIVE_LOW>;
> 		};
> 		temperature {
> 			label = "Battery Pack1 Temperature Critical";
> 			alarm-type = <GPIO_ALARM_GENRIC>;
> 			alarm-gpios = <&gpio4 17 GPIO_ACTIVE_LOW>;
> 		};
> 	};
> 	dev@1 {
> 		reg = <1>;
> 		temperature {
> 			label = "CPU Temperature Critical";
> 			alarm-type = <GPIO_ALARM_GENRIC>;
> 			alarm-gpios = <&gpio4 19 GPIO_ACTIVE_LOW>;
> 		};
> 	};
> };
> 
> I don't think that is a issue at all, but I don't know the dt
> maintainers opinion of this theme.
> 
> Regards,
> Marco

  reply	other threads:[~2018-11-07  6:17 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
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 [this message]
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=1541537426.30311.271.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 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.