LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jiri Kosina <trivial@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Yury Norov <yury.norov@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] regulators: irq_helper: Provide helper for trivial IRQ notifications
Date: Mon, 22 Nov 2021 13:04:12 +0200	[thread overview]
Message-ID: <fc622a2135be79f718d32efac156558470568340.1637330431.git.matti.vaittinen@fi.rohmeurope.com> (raw)
In-Reply-To: <cover.1637330431.git.matti.vaittinen@fi.rohmeurope.com>

[-- Attachment #1: Type: text/plain, Size: 4376 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>

---
This change was introduced earlier as part of the series:
"Few miscellaneous regulator improvements". Other patches from the
series were merged so this is now a lonely one and also the commit name
was changed to better reflect the new apporach (provide helper instead
of allowing omitting the callback). Changes from the initial idea:

 - Move the single_bit_set() to location where it is usable also for
   others.
 - Export helper for trivial mapping instead of adding the callback on
   behalf of the driver.
---
 drivers/regulator/irq_helpers.c  | 42 +++++++++++++++++++++++++++++++-
 include/linux/regulator/driver.h |  2 ++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/irq_helpers.c b/drivers/regulator/irq_helpers.c
index 522764435575..4ba1f1975f16 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,41 @@ 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 ||
+	    !single_bit_set(err, sizeof(err) * 8)))
+		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 --]

  parent reply	other threads:[~2021-11-22 11:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 11:03 [PATCH 0/4] Provide event map helper for regulator drivers Matti Vaittinen
2021-11-22 11:03 ` [PATCH 1/4] bitops: Add single_bit_set() Matti Vaittinen
2021-11-22 11:28   ` Andy Shevchenko
2021-11-22 12:42     ` Vaittinen, Matti
2021-11-22 12:57       ` Andy Shevchenko
2021-11-22 13:00         ` Andy Shevchenko
2021-11-22 13:18         ` Vaittinen, Matti
2021-11-23 10:42           ` David Laight
2021-11-23 10:47             ` Andy Shevchenko
2021-11-23 10:58               ` David Laight
2021-11-23 13:43                 ` 'Andy Shevchenko'
2021-11-23 14:36                   ` David Laight
2021-11-23 11:42             ` Vaittinen, Matti
2021-11-22 17:54         ` Yury Norov
2021-11-22 19:56           ` Andy Shevchenko
2021-11-23  7:51             ` Yury Norov
2021-11-23  5:26           ` Vaittinen, Matti
2021-11-23  7:33             ` Yury Norov
2021-11-23  9:03               ` Andy Shevchenko
2021-11-23  9:10                 ` Geert Uytterhoeven
2021-11-22 11:03 ` [PATCH 2/4] regulators: Add regulator_err2notif() helper Matti Vaittinen
2021-11-22 11:04 ` Matti Vaittinen [this message]
2021-11-22 11:48   ` [PATCH 3/4] regulators: irq_helper: Provide helper for trivial IRQ notifications Andy Shevchenko
2021-11-22 12:44     ` Vaittinen, Matti
2021-11-22 11:04 ` [PATCH 4/4] regulator: Drop unnecessary struct member Matti Vaittinen

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=fc622a2135be79f718d32efac156558470568340.1637330431.git.matti.vaittinen@fi.rohmeurope.com \
    --to=matti.vaittinen@fi.rohmeurope.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mazziesaccount@gmail.com \
    --cc=memxor@gmail.com \
    --cc=trivial@kernel.org \
    --cc=yury.norov@gmail.com \
    --subject='Re: [PATCH 3/4] regulators: irq_helper: Provide helper for trivial IRQ notifications' \
    /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

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).