Skip to content

Commit a764ff7

Browse files
M-Vaittinenbroonie
authored andcommitted
regulator: irq_helper: Provide helper for trivial IRQ notifications
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 <[email protected]> Link: https://lore.kernel.org/r/603b7ed1938013a00371c1e7ccc63dfb16982b87.1637736436.git.matti.vaittinen@fi.rohmeurope.com Signed-off-by: Mark Brown <[email protected]>
1 parent 6fadec4 commit a764ff7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

drivers/regulator/irq_helpers.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ static void init_rdev_errors(struct regulator_irq *h)
320320
* IRQF_ONESHOT when requesting the (threaded) irq.
321321
* @common_errs: Errors which can be flagged by this IRQ for all rdevs.
322322
* When IRQ is re-enabled these errors will be cleared
323-
* from all associated regulators
323+
* from all associated regulators. Use this instead of the
324+
* per_rdev_errs if you use
325+
* regulator_irq_map_event_simple() for event mapping.
324326
* @per_rdev_errs: Optional error flag array describing errors specific
325327
* for only some of the regulators. These errors will be
326328
* or'ed with common errors. If this is given the array
@@ -395,3 +397,40 @@ void regulator_irq_helper_cancel(void **handle)
395397
}
396398
}
397399
EXPORT_SYMBOL_GPL(regulator_irq_helper_cancel);
400+
401+
/**
402+
* regulator_irq_map_event_simple - regulator IRQ notification for trivial IRQs
403+
*
404+
* @irq: Number of IRQ that occurred
405+
* @rid: Information about the event IRQ indicates
406+
* @dev_mask: mask indicating the regulator originating the IRQ
407+
*
408+
* Regulators whose IRQ has single, well defined purpose (always indicate
409+
* exactly one event, and are relevant to exactly one regulator device) can
410+
* use this function as their map_event callbac for their regulator IRQ
411+
* notification helperk. Exactly one rdev and exactly one error (in
412+
* "common_errs"-field) can be given at IRQ helper registration for
413+
* regulator_irq_map_event_simple() to be viable.
414+
*/
415+
int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
416+
unsigned long *dev_mask)
417+
{
418+
int err = rid->states[0].possible_errs;
419+
420+
*dev_mask = 1;
421+
/*
422+
* This helper should only be used in a situation where the IRQ
423+
* can indicate only one type of problem for one specific rdev.
424+
* Something fishy is going on if we are having multiple rdevs or ERROR
425+
* flags here.
426+
*/
427+
if (WARN_ON(rid->num_states != 1 || hweight32(err) != 1))
428+
return 0;
429+
430+
rid->states[0].errors = err;
431+
rid->states[0].notifs = regulator_err2notif(err);
432+
433+
return 0;
434+
}
435+
EXPORT_SYMBOL_GPL(regulator_irq_map_event_simple);
436+

include/linux/regulator/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ void *regulator_irq_helper(struct device *dev,
700700
int irq_flags, int common_errs, int *per_rdev_errs,
701701
struct regulator_dev **rdev, int rdev_amount);
702702
void regulator_irq_helper_cancel(void **handle);
703+
int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
704+
unsigned long *dev_mask);
703705

704706
void *rdev_get_drvdata(struct regulator_dev *rdev);
705707
struct device *rdev_get_dev(struct regulator_dev *rdev);

0 commit comments

Comments
 (0)