LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/3] Provide event map helper for regulator drivers
@ 2021-11-24  7:16 Matti Vaittinen
  2021-11-24  7:16 ` [PATCH v2 1/3] regulators: Add regulator_err2notif() helper Matti Vaittinen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Matti Vaittinen @ 2021-11-24  7:16 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Liam Girdwood, Mark Brown, Andy Shevchenko,
	linux-kernel

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

This series provides an event map helper for regulator drivers and few
other minor things.

Regulators which provide trivial notification IRQs can use generic IRQ
mapper. Trivial in this context means the IRQ only informs one type of
event, for one regulator.

I did these changes for a new ROHM PMIC - which unfortunately requires
(hopefully only) one more HW revision before it is good to go. So there
is no rush with merging the first two patches - but I decided to send
them as they might lower the barrier of using the notifications with
some non ROHM ICs. Please use your best judgement whether to include
them at this phase or not.

The last patch is a fix for IRQ helper removing an unused struct member
and I think it should be merged no matter what is the fate of the
previous patches.

The series is based on regulator/for-next

---

Matti Vaittinen (3):
  regulators: Add regulator_err2notif() helper
  regulators: irq_helper: Provide helper for trivial IRQ notifications
  regulator: Drop unnecessary struct member

 drivers/regulator/irq_helpers.c  | 41 +++++++++++++++++++++++++++++++-
 include/linux/regulator/driver.h | 37 +++++++++++++++++++++++++++-
 2 files changed, 76 insertions(+), 2 deletions(-)

-- 
2.31.1


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v2 1/3] regulators: Add regulator_err2notif() helper
  2021-11-24  7:16 [PATCH v2 0/3] Provide event map helper for regulator drivers Matti Vaittinen
@ 2021-11-24  7:16 ` Matti Vaittinen
  2021-11-24 12:54   ` Mark Brown
  2021-11-24  7:17 ` [PATCH v2 2/3] regulators: irq_helper: Provide helper for trivial IRQ notifications Matti Vaittinen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Matti Vaittinen @ 2021-11-24  7:16 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Liam Girdwood, Mark Brown, Andy Shevchenko,
	linux-kernel

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

Help drivers avoid storing both supported notification and supported error
flags by supporting conversion from regulator error to notification.
This may help saving some bytes.

Add helper for finding the regulator notification corresponding to a
regulator error.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 include/linux/regulator/driver.h | 34 ++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 1cb8071fee34..f0827d34cb65 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -646,6 +646,40 @@ struct regulator_dev {
 	spinlock_t err_lock;
 };
 
+/*
+ * Convert error flags to corresponding notifications.
+ *
+ * Can be used by drivers which use the notification helpers to
+ * find out correct notification flags based on the error flags. Drivers
+ * can avoid storing both supported notification and error flags which
+ * may save few bytes.
+ */
+static inline int regulator_err2notif(int err)
+{
+	switch (err) {
+	case REGULATOR_ERROR_UNDER_VOLTAGE:
+		return REGULATOR_EVENT_UNDER_VOLTAGE;
+	case REGULATOR_ERROR_OVER_CURRENT:
+		return REGULATOR_EVENT_OVER_CURRENT;
+	case REGULATOR_ERROR_REGULATION_OUT:
+		return REGULATOR_EVENT_REGULATION_OUT;
+	case REGULATOR_ERROR_FAIL:
+		return REGULATOR_EVENT_FAIL;
+	case REGULATOR_ERROR_OVER_TEMP:
+		return REGULATOR_EVENT_OVER_TEMP;
+	case REGULATOR_ERROR_UNDER_VOLTAGE_WARN:
+		return REGULATOR_EVENT_UNDER_VOLTAGE_WARN;
+	case REGULATOR_ERROR_OVER_CURRENT_WARN:
+		return REGULATOR_EVENT_OVER_CURRENT_WARN;
+	case REGULATOR_ERROR_OVER_VOLTAGE_WARN:
+		return REGULATOR_EVENT_OVER_VOLTAGE_WARN;
+	case REGULATOR_ERROR_OVER_TEMP_WARN:
+		return REGULATOR_EVENT_OVER_TEMP_WARN;
+	}
+	return 0;
+}
+
+
 struct regulator_dev *
 regulator_register(const struct regulator_desc *regulator_desc,
 		   const struct regulator_config *config);
-- 
2.31.1


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v2 2/3] regulators: irq_helper: Provide helper for trivial IRQ notifications
  2021-11-24  7:16 [PATCH v2 0/3] Provide event map helper for regulator drivers Matti Vaittinen
  2021-11-24  7:16 ` [PATCH v2 1/3] regulators: Add regulator_err2notif() helper Matti Vaittinen
@ 2021-11-24  7:17 ` Matti Vaittinen
  2021-11-24  7:17 ` [PATCH v2 3/3] regulator: Drop unnecessary struct member Matti Vaittinen
  2021-11-24 17:36 ` [PATCH v2 0/3] Provide event map helper for regulator drivers Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Matti Vaittinen @ 2021-11-24  7:17 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Liam Girdwood, Mark Brown, Andy Shevchenko,
	linux-kernel

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

Provide a generic map_event helper for regulators which have a notification
IRQ with single, well defined purpose. Eg, IRQ always indicates exactly one
event for exactly one regulator device. For such IRQs the mapping is
trivial.

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

---
v2:
 - use hweight not single_bit_set
---
 drivers/regulator/irq_helpers.c  | 41 +++++++++++++++++++++++++++++++-
 include/linux/regulator/driver.h |  2 ++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/irq_helpers.c b/drivers/regulator/irq_helpers.c
index 522764435575..fe7ae0f3f46a 100644
--- a/drivers/regulator/irq_helpers.c
+++ b/drivers/regulator/irq_helpers.c
@@ -320,7 +320,9 @@ static void init_rdev_errors(struct regulator_irq *h)
  *			IRQF_ONESHOT when requesting the (threaded) irq.
  * @common_errs:	Errors which can be flagged by this IRQ for all rdevs.
  *			When IRQ is re-enabled these errors will be cleared
- *			from all associated regulators
+ *			from all associated regulators. Use this instead of the
+ *			per_rdev_errs if you use
+ *			regulator_irq_map_event_simple() for event mapping.
  * @per_rdev_errs:	Optional error flag array describing errors specific
  *			for only some of the regulators. These errors will be
  *			or'ed with common errors. If this is given the array
@@ -395,3 +397,40 @@ void regulator_irq_helper_cancel(void **handle)
 	}
 }
 EXPORT_SYMBOL_GPL(regulator_irq_helper_cancel);
+
+/**
+ * regulator_irq_map_event_simple - regulator IRQ notification for trivial IRQs
+ *
+ * @irq:	Number of IRQ that occurred
+ * @rid:	Information about the event IRQ indicates
+ * @dev_mask:	mask indicating the regulator originating the IRQ
+ *
+ * Regulators whose IRQ has single, well defined purpose (always indicate
+ * exactly one event, and are relevant to exactly one regulator device) can
+ * use this function as their map_event callbac for their regulator IRQ
+ * notification helperk. Exactly one rdev and exactly one error (in
+ * "common_errs"-field) can be given at IRQ helper registration for
+ * regulator_irq_map_event_simple() to be viable.
+ */
+int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
+			    unsigned long *dev_mask)
+{
+	int err = rid->states[0].possible_errs;
+
+	*dev_mask = 1;
+	/*
+	 * This helper should only be used in a situation where the IRQ
+	 * can indicate only one type of problem for one specific rdev.
+	 * Something fishy is going on if we are having multiple rdevs or ERROR
+	 * flags here.
+	 */
+	if (WARN_ON(rid->num_states != 1 || hweight32(err) != 1))
+		return 0;
+
+	rid->states[0].errors = err;
+	rid->states[0].notifs = regulator_err2notif(err);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(regulator_irq_map_event_simple);
+
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index f0827d34cb65..15cd94bb6769 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -701,6 +701,8 @@ void *regulator_irq_helper(struct device *dev,
 			   int irq_flags, int common_errs, int *per_rdev_errs,
 			   struct regulator_dev **rdev, int rdev_amount);
 void regulator_irq_helper_cancel(void **handle);
+int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
+				   unsigned long *dev_mask);
 
 void *rdev_get_drvdata(struct regulator_dev *rdev);
 struct device *rdev_get_dev(struct regulator_dev *rdev);
-- 
2.31.1


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v2 3/3] regulator: Drop unnecessary struct member
  2021-11-24  7:16 [PATCH v2 0/3] Provide event map helper for regulator drivers Matti Vaittinen
  2021-11-24  7:16 ` [PATCH v2 1/3] regulators: Add regulator_err2notif() helper Matti Vaittinen
  2021-11-24  7:17 ` [PATCH v2 2/3] regulators: irq_helper: Provide helper for trivial IRQ notifications Matti Vaittinen
@ 2021-11-24  7:17 ` Matti Vaittinen
  2021-11-24 17:36 ` [PATCH v2 0/3] Provide event map helper for regulator drivers Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Matti Vaittinen @ 2021-11-24  7:17 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Liam Girdwood, Mark Brown, Andy Shevchenko,
	linux-kernel

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

The irq_flags from the regulator IRQ helper description struct was never
used. The IRQ flags are passed as parameters to helper registration
instead.

Remove the unnecessary struct field.

Fixes: 7111c6d1b31b ("regulator: IRQ based event/error notification helpers")
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 include/linux/regulator/driver.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 15cd94bb6769..4078c7776453 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -554,7 +554,6 @@ struct regulator_irq_data {
  */
 struct regulator_irq_desc {
 	const char *name;
-	int irq_flags;
 	int fatal_cnt;
 	int reread_ms;
 	int irq_off_ms;
-- 
2.31.1


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 1/3] regulators: Add regulator_err2notif() helper
  2021-11-24  7:16 ` [PATCH v2 1/3] regulators: Add regulator_err2notif() helper Matti Vaittinen
@ 2021-11-24 12:54   ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-11-24 12:54 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Liam Girdwood, Andy Shevchenko, linux-kernel

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

On Wed, Nov 24, 2021 at 09:16:45AM +0200, Matti Vaittinen wrote:
> Help drivers avoid storing both supported notification and supported error
> flags by supporting conversion from regulator error to notification.
> This may help saving some bytes.

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 0/3] Provide event map helper for regulator drivers
  2021-11-24  7:16 [PATCH v2 0/3] Provide event map helper for regulator drivers Matti Vaittinen
                   ` (2 preceding siblings ...)
  2021-11-24  7:17 ` [PATCH v2 3/3] regulator: Drop unnecessary struct member Matti Vaittinen
@ 2021-11-24 17:36 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-11-24 17:36 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Liam Girdwood, linux-kernel, Andy Shevchenko

On Wed, 24 Nov 2021 09:16:18 +0200, Matti Vaittinen wrote:
> This series provides an event map helper for regulator drivers and few
> other minor things.
> 
> Regulators which provide trivial notification IRQs can use generic IRQ
> mapper. Trivial in this context means the IRQ only informs one type of
> event, for one regulator.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/3] regulators: Add regulator_err2notif() helper
      commit: 6fadec4c5561e2fbe1dfa8a7da9bc58d094a8f04
[2/3] regulators: irq_helper: Provide helper for trivial IRQ notifications
      commit: a764ff77d697a4a13e69b3379cc613f7409c6b9a
[3/3] regulator: Drop unnecessary struct member
      commit: 1b6ed6bf32fb22ef8e3572fc9c0f6454adf1ca40

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2021-11-24 17:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24  7:16 [PATCH v2 0/3] Provide event map helper for regulator drivers Matti Vaittinen
2021-11-24  7:16 ` [PATCH v2 1/3] regulators: Add regulator_err2notif() helper Matti Vaittinen
2021-11-24 12:54   ` Mark Brown
2021-11-24  7:17 ` [PATCH v2 2/3] regulators: irq_helper: Provide helper for trivial IRQ notifications Matti Vaittinen
2021-11-24  7:17 ` [PATCH v2 3/3] regulator: Drop unnecessary struct member Matti Vaittinen
2021-11-24 17:36 ` [PATCH v2 0/3] Provide event map helper for regulator drivers Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).