mbox series

[RFC,0/7] Extend regulator notification support

Message ID cover.1613042245.git.matti.vaittinen@fi.rohmeurope.com
Headers show
Series Extend regulator notification support | expand

Message

Vaittinen, Matti Feb. 11, 2021, 12:33 p.m. UTC
Extend regulator notification support

This is an RFC series for getting feedback on extending the regulator
notification and error flag support. Initial discussion on the topic can
be found here:
https://lore.kernel.org/lkml/6046836e22b8252983f08d5621c35ececb97820d.camel@fi.rohmeurope.com/

This series is built on top of the:
commit 7aa382cfe714 ("regulator: mt6315: Add support for MT6315 regulator")
regulator tree for-5.12 branch + The BD9576MUF support patch series v8
which is not yet in-tree
Here:
https://lore.kernel.org/lkml/cover.1613031055.git.matti.vaittinen@fi.rohmeurope.com/

In a nutshell - the RFC adds:

1. WARNING level events/error flags. (Patch 2)
  Current regulator 'ERROR' event notifications for over/under
  voltage, over current and over temperature are used to indicate
  condition where monitored entity is so badly "off" that it actually
  indicates a hardware error which can not be recovered. The most
  typical hanling for that is believed to be a (graceful)
  system-shutdown. Here we add set of 'WARNING' level flags to allow
  sending notifications to consumers before things are 'that badly off'
  so that consumer drivers can implement recovery-actions.
2. Device-tree properties for specifying limit values. (Patches 1, 4)
  Add limits for above mentioned 'ERROR' and 'WARNING' levels (which
  send notifications to consumers) and also for a 'PROTECTION' level
  (which will be used to immediately shut-down the regulator(s) W/O
  informing consumer drivers. Typically implemented by hardware).
  Property parsing is implemented in regulator core which then calls
  callback operations for limit setting from the IC drivers. A
  warning is emitted if protection is requested by device tree but the
  underlying IC does not support configuring requested protection.
3. Helpers which can be registered by IC. (Patch 3)
  Target is to avoid implementing IRQ handling and IRQ storm protection
  in each IC driver. (Many of the ICs implementin these IRQs do not allow
  masking or acking the IRQ but keep the IRQ asserted for the whole
  duration of problem keeping the processor in IRQ handling loop).

The helper was attempted to be done so it could be used to implement
roughly same logic as is used in qcom-labibb regulator. This means
amongst other things a safety shut-down if IC registers are not readable.
Using these shut-down retry counters are optional. The idea is that the
helper could be also used by simpler ICs which do not provide status
register(s) which can be used to check if error is still active.

ICs which do not have such status register can simply omit the 'renable'
callback (and retry-counts etc) - and helper assumes the situation is Ok
and re-enables IRQ after given time period. If problem persists the
handler is ran again and another notification is sent - but at least the
delay allows processor to avoid IRQ loop.

Patch 6 takes this notification support in use at BD9576MUF.

--

Matti Vaittinen (7):
  dt_bindings: Add protection limit properties
  regulator: add warning flags
  regulator: IRQ based event/error notification helpers
  regulator: add property parsing and callbacks to set protection limits
  dt-bindings: regulator: bd9576 add FET ON-resistance for OCW
  regulator: bd9576: Support error reporting
  regulator: bd9576: Fix the driver name in id table

 .../bindings/regulator/regulator.yaml         |   82 ++
 .../regulator/rohm,bd9576-regulator.yaml      |    5 +
 drivers/regulator/Makefile                    |    2 +-
 drivers/regulator/bd9576-regulator.c          | 1030 ++++++++++++++---
 drivers/regulator/core.c                      |  146 ++-
 drivers/regulator/irq_helpers.c               |  396 +++++++
 drivers/regulator/of_regulator.c              |   58 +
 drivers/regulator/qcom-labibb-regulator.c     |   10 +-
 drivers/regulator/stpmic1_regulator.c         |   17 +-
 include/linux/regulator/consumer.h            |   14 +
 include/linux/regulator/driver.h              |  170 ++-
 include/linux/regulator/machine.h             |   26 +
 12 files changed, 1816 insertions(+), 140 deletions(-)
 create mode 100644 drivers/regulator/irq_helpers.c

Comments

Rob Herring March 5, 2021, 7:30 p.m. UTC | #1
On Thu, Feb 11, 2021 at 02:34:17PM +0200, Matti Vaittinen wrote:
> Support specifying protection/error/warning limits for regulator
> over current, over temperature and over/under voltage.
> 
> Most of the PMICs support only "protection" feature but few
> setups do also support error/warning level indications.
> 
> On many ICs most of the protection limits can't actually be set.
> But for example the ampere limit for over-current protection on ROHM
> BD9576 can be configured - or feature can be completely disabled.
> 
> Provide limit setting for all protections/errors for the sake of
> the completeness and do that using own properties for all so that
> not all users would need to set all levels when only one or few are
> supported.
> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>  .../bindings/regulator/regulator.yaml         | 82 +++++++++++++++++++
>  1 file changed, 82 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/regulator/regulator.yaml b/Documentation/devicetree/bindings/regulator/regulator.yaml
> index 6d0bc9cd4040..47fff75f0554 100644
> --- a/Documentation/devicetree/bindings/regulator/regulator.yaml
> +++ b/Documentation/devicetree/bindings/regulator/regulator.yaml
> @@ -117,6 +117,88 @@ properties:
>      description: Enable over current protection.
>      type: boolean
>  
> +  regulator-over-current-protection-microamp:

Kind of long and 'current' is implied by 'microamp'. Perhaps 
regulator-oc-protection-microamp and similar.

> +    description: Set over current protection limit. This is a limit where
> +      hardware performs emergency shutdown. Zero can be passed to disable
> +      protection and value '1' indicates that protection should be enabled but
> +      limit setting can be omitted.
> +
> +  regulator-over-current-error-microamp:
> +    description: Set over current error limit. This is a limit where part of
> +      the hardware propably is malfunctional and damage prevention is requested.
> +      Zero can be passed to disable error detection and value '1' indicates
> +      that detection should be enabled but limit setting can be omitted.
> +
> +  regulator-over-current-warn-microamp:
> +    description: Set over current warning limit. This is a limit where hardware
> +      is assumed still to be functional but approaching limit where it gets
> +      damaged. Recovery actions should be initiated. Zero can be passed to
> +      disable detection and value '1' indicates that detection should
> +      be enabled but limit setting can be omitted.
> +
> +  regulator-over-voltage-protection-microvolt:
> +    description: Set over voltage protection limit. This is a limit where
> +      hardware performs emergency shutdown. Zero can be passed to disable
> +      protection and value '1' indicates that protection should be enabled but
> +      limit setting can be omitted. Limit is given as microvolt offset from
> +      voltage set to regulator.
> +
> +  regulator-over-voltage-error-microvolt:
> +    description: Set over voltage error limit. This is a limit where part of
> +      the hardware propably is malfunctional and damage prevention is requested
> +      Zero can be passed to disable error detection and value '1' indicates
> +      that detection should be enabled but limit setting can be omitted. Limit
> +      is given as microvolt offset from voltage set to regulator.
> +
> +  regulator-over-voltage-warn-microvolt:
> +    description: Set over voltage warning limit. This is a limit where hardware
> +      is assumed still to be functional but approaching limit where it gets
> +      damaged. Recovery actions should be initiated. Zero can be passed to
> +      disable detection and value '1' indicates that detection should
> +      be enabled but limit setting can be omitted. Limit is given as microvolt
> +      offset from voltage set to regulator.
> +
> +  regulator-under-voltage-protection-microvolt:
> +    description: Set over under voltage protection limit. This is a limit where
> +      hardware performs emergency shutdown. Zero can be passed to disable
> +      protection and value '1' indicates that protection should be enabled but
> +      limit setting can be omitted. Limit is given as microvolt offset from
> +      voltage set to regulator.
> +
> +  regulator-under-voltage-error-microvolt:
> +    description: Set under voltage error limit. This is a limit where part of
> +      the hardware propably is malfunctional and damage prevention is requested
> +      Zero can be passed to disable error detection and value '1' indicates
> +      that detection should be enabled but limit setting can be omitted. Limit
> +      is given as microvolt offset from voltage set to regulator.
> +
> +  regulator-under-voltage-warn-microvolt:
> +    description: Set over under voltage warning limit. This is a limit where
> +      hardware is assumed still to be functional but approaching limit where
> +      it gets damaged. Recovery actions should be initiated. Zero can be passed
> +      to disable detection and value '1' indicates that detection should
> +      be enabled but limit setting can be omitted. Limit is given as microvolt
> +      offset from voltage set to regulator.
> +
> +  regulator-over-temperature-protection-kelvin:
> +    description: Set over temperature protection limit. This is a limit where
> +      hardware performs emergency shutdown. Zero can be passed to disable
> +      protection and value '1' indicates that protection should be enabled but
> +      limit setting can be omitted.
> +
> +  regulator-over-temperature-error-kelvin:
> +    description: Set over temperature error limit. This is a limit where part of
> +      the hardware propably is malfunctional and damage prevention is requested
> +      Zero can be passed to disable error detection and value '1' indicates
> +      that detection should be enabled but limit setting can be omitted.
> +
> +  regulator-over-temperature-warn-kelvin:
> +    description: Set over temperature warning limit. This is a limit where
> +      hardware is assumed still to be functional but approaching limit where it
> +      gets damaged. Recovery actions should be initiated. Zero can be passed to
> +      disable detection and value '1' indicates that detection should
> +      be enabled but limit setting can be omitted.
> +
>    regulator-active-discharge:
>      description: |
>        tristate, enable/disable active discharge of regulators. The values are:
> -- 
> 2.25.4
> 
> 
> -- 
> Matti Vaittinen, Linux device drivers
> ROHM Semiconductors, Finland SWDC
> Kiviharjunlenkki 1E
> 90220 OULU
> FINLAND
> 
> ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
> Simon says - in Latin please.
> ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
> Thanks to Simon Glass for the translation =]
Vaittinen, Matti March 8, 2021, 5:34 a.m. UTC | #2
On Fri, 2021-03-05 at 13:30 -0600, Rob Herring wrote:
> On Thu, Feb 11, 2021 at 02:34:17PM +0200, Matti Vaittinen wrote:

> > Support specifying protection/error/warning limits for regulator

> > over current, over temperature and over/under voltage.

> > 

> > Most of the PMICs support only "protection" feature but few

> > setups do also support error/warning level indications.

> > 

> > On many ICs most of the protection limits can't actually be set.

> > But for example the ampere limit for over-current protection on

> > ROHM

> > BD9576 can be configured - or feature can be completely disabled.

> > 

> > Provide limit setting for all protections/errors for the sake of

> > the completeness and do that using own properties for all so that

> > not all users would need to set all levels when only one or few are

> > supported.

> > 

> > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>

> > ---

> >  .../bindings/regulator/regulator.yaml         | 82

> > +++++++++++++++++++

> >  1 file changed, 82 insertions(+)

> > 

> > diff --git

> > a/Documentation/devicetree/bindings/regulator/regulator.yaml

> > b/Documentation/devicetree/bindings/regulator/regulator.yaml

> > index 6d0bc9cd4040..47fff75f0554 100644

> > --- a/Documentation/devicetree/bindings/regulator/regulator.yaml

> > +++ b/Documentation/devicetree/bindings/regulator/regulator.yaml

> > @@ -117,6 +117,88 @@ properties:

> >      description: Enable over current protection.

> >      type: boolean

> >  

> > +  regulator-over-current-protection-microamp:

> 

> Kind of long and 'current' is implied by 'microamp'. Perhaps 

> regulator-oc-protection-microamp and similar.


I like this idea but...
 regulator-over-current-protection:                                             
    description: Enable over current protection.                                 
    type: boolean

is an existing property so it kind of makes sense to me to name the
limit setting in a similar way. But I will change it as you suggested
as I don't think this is a big thing.

Br,
	Matti Vaittinen

> 

> > -- 

> > Matti Vaittinen, Linux device drivers

> > ROHM Semiconductors, Finland SWDC

> > Kiviharjunlenkki 1E

> > 90220 OULU

> > FINLAND

> > 

> > ~~~ "I don't think so," said Rene Descartes. Just then he vanished

> > ~~~

> > Simon says - in Latin please.

> > ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~

> > Thanks to Simon Glass for the translation =]