All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/7] Extend regulator notification support
@ 2021-02-11 12:33 Matti Vaittinen
  2021-02-11 12:34 ` [RFC PATCH 1/7] dt_bindings: Add protection limit properties Matti Vaittinen
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Matti Vaittinen @ 2021-02-11 12:33 UTC (permalink / raw)
  To: mazziesaccount, matti.vaittinen
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Matti Vaittinen,
	Andy Gross, Bjorn Andersson, linux-kernel, devicetree,
	linux-power, linux-arm-msm, linux-renesas-soc

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

-- 
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 =] 

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [RFC PATCH 3/7] regulator: IRQ based event/error notification helpers
@ 2021-02-11 18:47 kernel test robot
  0 siblings, 0 replies; 23+ messages in thread
From: kernel test robot @ 2021-02-11 18:47 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 10774 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <3daf0531910c25d8b0da3964778ae2a6c9049d43.1613042245.git.matti.vaittinen@fi.rohmeurope.com>
References: <3daf0531910c25d8b0da3964778ae2a6c9049d43.1613042245.git.matti.vaittinen@fi.rohmeurope.com>
TO: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>, Matti Vaittinen <mazziesaccount@gmail.com>

Hi Matti,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on regulator/for-next]
[also build test WARNING on v5.11-rc7 next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matti-Vaittinen/Extend-regulator-notification-support/20210211-204336
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
config: x86_64-randconfig-m001-20210209 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/regulator/irq_helpers.c:194 regulator_notifier_isr() error: uninitialized symbol 'ret'.

vim +/ret +194 drivers/regulator/irq_helpers.c

1844ad67f3ebe1 Matti Vaittinen 2021-02-11  154  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  155  static irqreturn_t regulator_notifier_isr(int irq, void *data)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  156  {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  157  	struct regulator_irq *h = data;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  158  	struct regulator_irq_desc *d;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  159  	struct regulator_irq_data *rid;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  160  	unsigned long rdev_map = 0;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  161  	int num_rdevs;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  162  	int ret, i, j;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  163  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  164  	d = &h->desc;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  165  	rid = &h->rdata;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  166  	num_rdevs = rid->num_states;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  167  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  168  	if (d->fatal_cnt)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  169  		h->retry_cnt++;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  170  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  171  	/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  172  	 * we spare few cycles by not clearing statuses prior this call.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  173  	 * The IC driver must initialize the status buffers for rdevs
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  174  	 * which it indicates having active events via rdev_map.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  175  	 *
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  176  	 * Maybe we should just to be on a safer side(?)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  177  	 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  178  	if (d->map_event)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  179  		ret = d->map_event(irq, rid, &rdev_map);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  180  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  181  	/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  182  	 * If status reading fails (which is unlikely) we don't ack/disable
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  183  	 * IRQ but just increase fail count and retry when IRQ fires again.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  184  	 * If retry_count exceeds given safety limit we call IC specific die
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  185  	 * handler which can try disabling regulator(s).
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  186  	 *
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  187  	 * If no die handler is given we will just bug() as a last resort.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  188  	 *
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  189  	 * We could try disabling all associated rdevs - but we might shoot
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  190  	 * ourself in the head and leave problematic regulator enabled. So
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  191  	 * if IC has no die-handler populated we just assume the regulator
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  192  	 * can't be disabled.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  193  	 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11 @194  	if (unlikely(ret == REGULATOR_FAILED_RETRY))
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  195  		goto fail_out;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  196  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  197  	h->retry_cnt = 0;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  198  	/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  199  	 * Let's not disable IRQ if there was no status bits for us. We'd
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  200  	 * better leave spurious IRQ handling to genirq
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  201  	 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  202  	if (ret || !rdev_map)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  203  		return IRQ_NONE;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  204  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  205  	/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  206  	 * Some events are bogus if regulator is disabled. Skip such events
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  207  	 * if all relevant regulators are disabled
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  208  	 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  209  	if (d->skip_off) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  210  		int skip = 1;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  211  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  212  		for_each_set_bit(i, &rdev_map, num_rdevs) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  213  			struct regulator_dev *rdev;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  214  			const struct regulator_ops *ops;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  215  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  216  			rdev = rid->states[i].rdev;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  217  			ops = rdev->desc->ops;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  218  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  219  			/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  220  			 * If any of the flagged regulators is enabled we do
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  221  			 * handle this
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  222  			 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  223  			if (ops->is_enabled(rdev)) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  224  				skip = 0;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  225  				break;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  226  			}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  227  		}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  228  		if (skip)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  229  			return IRQ_NONE;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  230  	}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  231  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  232  	/* Disable IRQ if HW keeps line asserted */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  233  	if (d->irq_off_ms)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  234  		disable_irq_nosync(irq);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  235  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  236  	/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  237  	 * IRQ seems to be for us. Let's fire correct notifiers / store error
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  238  	 * flags
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  239  	 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  240  	for_each_set_bit(i, &rdev_map, num_rdevs) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  241  		struct regulator_err_state *stat;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  242  		int len;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  243  		struct regulator_dev *rdev;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  244  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  245  		stat = &rid->states[i];
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  246  		len = sizeof(stat->notifs);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  247  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  248  		rdev = stat->rdev;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  249  		for_each_set_bit(j, &stat->notifs, 8 * len)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  250  			regulator_notifier_call_chain(rdev, 1 << (j - 1), NULL);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  251  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  252  		rdev_flag_err(rdev, stat->errors);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  253  	}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  254  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  255  	if (d->irq_off_ms) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  256  		if (!d->high_prio)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  257  			schedule_delayed_work(&h->isr_work,
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  258  					      msecs_to_jiffies(d->irq_off_ms));
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  259  		else
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  260  			mod_delayed_work(system_highpri_wq,
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  261  					 &h->isr_work,
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  262  					 msecs_to_jiffies(d->irq_off_ms));
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  263  	}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  264  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  265  	return IRQ_HANDLED;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  266  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  267  fail_out:
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  268  	if (d->fatal_cnt && h->retry_cnt > d->fatal_cnt) {
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  269  		if (d->die)
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  270  			ret = d->die(rid);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  271  
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  272  		/*
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  273  		 * If die() failed or was not implemented just BUG() as last
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  274  		 * attemt to save HW.
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  275  		 */
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  276  		BUG_ON(ret);
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  277  	}
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  278  	return IRQ_NONE;
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  279  }
1844ad67f3ebe1 Matti Vaittinen 2021-02-11  280  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 29633 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-03-08  5:35 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-11 12:33 [RFC PATCH 0/7] Extend regulator notification support Matti Vaittinen
2021-02-11 12:34 ` [RFC PATCH 1/7] dt_bindings: Add protection limit properties Matti Vaittinen
2021-03-05 19:30   ` Rob Herring
2021-03-08  5:34     ` Vaittinen, Matti
2021-02-11 12:34 ` [RFC PATCH 2/7] regulator: add warning flags Matti Vaittinen
2021-02-11 12:35 ` [RFC PATCH 3/7] regulator: IRQ based event/error notification helpers Matti Vaittinen
2021-02-11 14:40   ` kernel test robot
2021-02-11 14:40   ` [RFC PATCH] regulator: dev_delayed_work_autocancel() can be static kernel test robot
2021-02-12  9:33   ` [RFC PATCH 3/7] regulator: IRQ based event/error notification helpers Vaittinen, Matti
2021-02-12 13:56     ` Mark Brown
2021-02-15 10:25   ` Vaittinen, Matti
2021-02-15 11:11   ` Dan Carpenter
2021-02-15 11:11     ` Dan Carpenter
2021-02-11 12:35 ` [RFC PATCH 4/7] regulator: add property parsing and callbacks to set protection limits Matti Vaittinen
2021-02-11 14:11   ` kernel test robot
2021-02-12  7:29   ` Matti Vaittinen
2021-02-11 12:35 ` [RFC PATCH 5/7] dt-bindings: regulator: bd9576 add FET ON-resistance for OCW Matti Vaittinen
2021-02-11 14:56   ` Rob Herring
2021-02-17 21:34   ` Rob Herring
2021-02-18  6:15     ` Vaittinen, Matti
2021-02-11 12:36 ` [RFC PATCH 6/7] regulator: bd9576: Support error reporting Matti Vaittinen
2021-02-11 12:36 ` [RFC PATCH 7/7] regulator: bd9576: Fix the driver name in id table Matti Vaittinen
  -- strict thread matches above, loose matches on Subject: below --
2021-02-11 18:47 [RFC PATCH 3/7] regulator: IRQ based event/error notification helpers kernel test robot

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.