Provide event map helper for regulator drivers
v2 cover Provide event map helper for regulator drivers
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(-)
Signature · 14 lines
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 =]
PATCH v2 1/3 regulators: Add regulator_err2notif() helper
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.
--- include/linux/regulator/driver.h | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
include/linux/regulator/driver.h +34 -0
@@ -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);
Signature · 14 lines
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 =]
Mark Brown
maintainerRe: [PATCH v2 1/3] regulators: Add regulator_err2notif() helper
Quoted 3 lines · Matti Vaittinen
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.
PATCH v2 2/3 regulators: irq_helper: Provide helper for trivial IRQ notifications
In reply to Matti VaittinenProvide 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.
---
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(-)
drivers/regulator/irq_helpers.c +40 -1
@@ -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); +
include/linux/regulator/driver.h +2 -0
@@ -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);
Signature · 14 lines
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 =]
PATCH v2 3/3 regulator: Drop unnecessary struct member
In reply to Matti VaittinenThe 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.
--- include/linux/regulator/driver.h | 1 - 1 file changed, 1 deletion(-)
include/linux/regulator/driver.h +0 -1
@@ -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;
Signature · 14 lines
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 =]
Mark Brown
maintainerQuoted 8 lines · Matti Vaittinen
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: 1b6ed6bf32fb22ef8e3572fc9c0f6454adf1ca40All 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