Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/603b7ed1938013a00371c1e7ccc63dfb16982b87.1637736436.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Matti Vaittinen and committed by
Mark Brown
a764ff77 6fadec4c

+42 -1
+40 -1
drivers/regulator/irq_helpers.c
··· 320 320 * IRQF_ONESHOT when requesting the (threaded) irq. 321 321 * @common_errs: Errors which can be flagged by this IRQ for all rdevs. 322 322 * 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. 324 326 * @per_rdev_errs: Optional error flag array describing errors specific 325 327 * for only some of the regulators. These errors will be 326 328 * or'ed with common errors. If this is given the array ··· 397 395 } 398 396 } 399 397 EXPORT_SYMBOL_GPL(regulator_irq_helper_cancel); 398 + 399 + /** 400 + * regulator_irq_map_event_simple - regulator IRQ notification for trivial IRQs 401 + * 402 + * @irq: Number of IRQ that occurred 403 + * @rid: Information about the event IRQ indicates 404 + * @dev_mask: mask indicating the regulator originating the IRQ 405 + * 406 + * Regulators whose IRQ has single, well defined purpose (always indicate 407 + * exactly one event, and are relevant to exactly one regulator device) can 408 + * use this function as their map_event callbac for their regulator IRQ 409 + * notification helperk. Exactly one rdev and exactly one error (in 410 + * "common_errs"-field) can be given at IRQ helper registration for 411 + * regulator_irq_map_event_simple() to be viable. 412 + */ 413 + int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid, 414 + unsigned long *dev_mask) 415 + { 416 + int err = rid->states[0].possible_errs; 417 + 418 + *dev_mask = 1; 419 + /* 420 + * This helper should only be used in a situation where the IRQ 421 + * can indicate only one type of problem for one specific rdev. 422 + * Something fishy is going on if we are having multiple rdevs or ERROR 423 + * flags here. 424 + */ 425 + if (WARN_ON(rid->num_states != 1 || hweight32(err) != 1)) 426 + return 0; 427 + 428 + rid->states[0].errors = err; 429 + rid->states[0].notifs = regulator_err2notif(err); 430 + 431 + return 0; 432 + } 433 + EXPORT_SYMBOL_GPL(regulator_irq_map_event_simple); 434 +
+2
include/linux/regulator/driver.h
··· 700 700 int irq_flags, int common_errs, int *per_rdev_errs, 701 701 struct regulator_dev **rdev, int rdev_amount); 702 702 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); 703 705 704 706 void *rdev_get_drvdata(struct regulator_dev *rdev); 705 707 struct device *rdev_get_dev(struct regulator_dev *rdev);