public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: Trent Piepho <tpiepho@impinj.com>,
	"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 08:08:26 -0700	[thread overview]
Message-ID: <20181101150826.GA25346@roeck-us.net> (raw)
In-Reply-To: <20181101145858.iavdll2aqjpd7n6s@pengutronix.de>

On Thu, Nov 01, 2018 at 03:58:58PM +0100, Marco Felsch wrote:
> On 18-11-01 06:02, Guenter Roeck wrote:
> > On 11/1/18 3:40 AM, Marco Felsch wrote:
> > > On 18-10-30 13:11, Guenter Roeck wrote:
> > > > On Tue, Oct 30, 2018 at 07:34:11PM +0000, Trent Piepho wrote:
> > > > > On Tue, 2018-10-30 at 18:00 +0100, Marco Felsch wrote:
> > > > > > On 18-10-30 06:13, Guenter Roeck wrote:
> > > > > > > On 10/30/18 3:47 AM, Marco Felsch wrote:
> > > > > > > > 
> > > > > > hwmon-gpio-simple sounds ok for me.
> > > > > > 
> > > > > > > The most difficult part of such a driver would probably be to define acceptable
> > > > > > > devicetree properties.
> > > > > > 
> > > > > > That's true! One possible solution could be:
> > > > > > 
> > > > > > hwmon_dev {
> > > > > > 	compatible = "hwmon-gpio-simple";
> > > > > > 	name = "gpio-generic-hwmon";
> > > > > > 	update-interval-ms = 100;
> > > > > > 
> > > > > > 	hwmon-gpio-simple,dev@0 {
> > > > > > 		reg = <0>;
> > > > > > 		gpio = <gpio3 15 GPIO_ACTIVE_LOW>;
> > > > > > 		hwmon-gpio-simple,type = "in";
> > > > > > 		hwmon-gpio-simple,report = "crit_alarm";
> > > > > > 	};
> > > > > > 
> > > > > > 	hwmon-gpio-simple,dev@1 {
> > > > > > 		reg = <1>;
> > > > > > 		gpio = <gpio3 19 GPIO_ACTIVE_LOW>;
> > > > > > 		hwmon-gpio-simple,type = "temp";
> > > > > > 		hwmon-gpio-simple,report = "alarm";
> > > > > > 	};
> > > > > > };
> > > > > 
> > > > > Here's some options:
> > > > > 
> > > > > hwmon_dev {
> > > > > 	/* Orthogonal to existing "gpio-fan" binding. */
> > > > > 	compatible = "gpio-alarm";
> > > > > 	/* Standard DT property for GPIO users is [<name>-]gpios */
> > > > > 	alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW>,
> > > > > 	              <&gpio3 19 GPIO_ACTIVE_LOW>;
> > > > > 	/* A <prop>-names property is also a DT standard */
> > > > >          alarm-gpios-names = "in0", "temp0";
> > > > 
> > > > temp1, and it would have to specify which alarm, but, yes, that would
> > > > be better.
> > > > 
> > > > > };
> > > > > 
> > > > > The driver can create hwmon alarm attribute(s) based on the name(s).  I
> > > > > used "alarm" as it seemed to fit the pattern established by the "fan"
> > > > > driver.  Both the gpio-fan and gpio-alarm driver use gpios, but I think
> > > > > considering them one driver for that reason does not make sense.
> > > > > 
> > > > > The names are very Linuxy, something that is not liked in DT bindings.
> > > > > It also doesn't extend well if you need to add more attributes to each
> > > > > alarm.  Here's something that's more like what I did for the gpio-leds
> > > > > binding.
> > > > > 
> > > > > hwmon_dev {
> > > > > 	compatible = "gpio-alarm";
> > > > > 	voltage@0 {
> > > > > 		label = "Battery Voltage Low";
> > > > > 		type = "voltage";
> > > > > 		alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW>;
> > > > > 	};
> > > > > 	cputemp@0 {
> > > > > 		label = "CPU Temperature Critical";
> > > > > 		type = "temperature";
> > > > > 		interrupt-parent = <&gpio3>;
> > > > > 		interrupts = <19 IRQ_TYPE_LEVEL_LOW>;
> > > > > 	};
> > > > 
> > > > Even better, though the type of alarm (generic, min, max, lcrit, crit,
> > > > cap, emergency, fault) is still needed. That needs to be specified by
> > > > some explicit means, not with a label (though having a label is ok).
> > > 
> > > Thanks for your ideas, looks quite nice.
> > > 
> > > > There could also be more than one alarm per sensor (eg in0_lcrit_alarm,
> > > > in0_min_alarm, in0_max_alarm, in0_crit_alarm), all of which would share
> > > > a single label. Something like
> > > > 
> > > > #define GPIO_ALARM_GENERIC	0
> > > > #define GPIO_ALARM_MIN		1
> > > > ...
> > > > 
> > > > 	voltage@0 {
> > > 
> > > 		reg = <0>;
> > > 
> > > I remember that we have to add a reg property if we want to use xyz@0.
> > > 
> > > > 		label = "Battery Voltage";
> > > > 		type = "voltage";
> > > > 		alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> > > > 		alarm-gpios = <&gpio3 15 GPIO_ACTIVE_LOW
> > > > 				&gpio3 16 GPIO_ACTIVE_LOW>;
> > > > 	};
> > > > 
> > > > with some better (acceptable) values for "alarm-type" and the actual fields.
> > > 
> > > Should we use the @<reg> suffix to map it to in<reg>_*_alarm or should
> > > we do something like that:
> > > 
> > > hwmon_dev {
> > > 	compatible = "gpio-alarm";
> > > 
> > > 	voltage {
> > > 		bat@0 {
> > > 			reg = <0>;
> > > 
> > > 	 		label = "Battery Pack1 Voltage";
> > > 			alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> > > 			interrupt-parent = <&gpio3>;
> > > 			interrupts = <15 IRQ_TYPE_LEVEL_LOW>,
> > > 				     <16 IRQ_TYPE_EDGE_RISING>;
> > > 		
> > > 		};
> > > 
> > > 		bat@1 {
> > > 			reg = <1>;
> > > 
> > > 	 		label = "Battery Pack2 Voltage";
> > > 			alarm-type = <GPIO_ALARM_LCRIT, GPIO_ALARM_CRIT>;
> > > 			interrupts-extended = <&gpio3 17 IRQ_TYPE_EDGE_FALLING>,
> > > 					      <&gpio4 18 IRQ_TYPE_EDGE_FALLING>;
> > > 		
> > > 		};
> > > 	};
> > > 
> > > 	temperature {
> > > 		cputemp {
> > > 			label = "CPU Temperature Critical";
> > > 			alarm-type = <GPIO_ALARM_CRIT>;
> > > 			interrupt-parent = <&gpio3>;
> > > 			interrupts = <20 IRQ_TYPE_EDGE_FALLING>;
> > > 		};
> > > 	};
> > > };
> > > 
> > > Now the subnodes imply the type. Since the hwmon-gpio-simple should
> > > work interrupt driven all the time we should replace the alarm-gpios by
> > 
> > Note that this isn't entirely correct: If the gpio pin doesn't support
> > interrupts, the driver would just report the state of the pin.
> 
> Okay, but how do we detect and report a alarm if you won't have a
> (fallback) polling mechanism nor a gpio which doesn't support
> interrupts? Should the user poll the sysfs-entry instead?
> 
Yes. Not different to existing hwmon drivers which don't implement
interrupt handling.

Guenter

  reply	other threads:[~2018-11-02  0:11 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
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 [this message]
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=20181101150826.GA25346@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=m.felsch@pengutronix.de \
    --cc=tpiepho@impinj.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