aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2015-03-05 11:45:41 -0500
committerMark Brown <broonie@kernel.org>2015-03-05 11:45:41 -0500
commit5142442d75194ab983e865e6c12995da5666a11c (patch)
tree961f1477ddea9bc2c298b9d4996679e5b134ed66
parent6f2c9348095ae1a489abafe2ab3db7deca406e49 (diff)
parent046db763aaaeb987ea01ea8c7e6d618e0ad1e6b8 (diff)
Merge branch 'topic/notifier' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator into asoc-wm8804
-rw-r--r--drivers/regulator/devres.c85
-rw-r--r--include/linux/regulator/consumer.h16
2 files changed, 101 insertions, 0 deletions
diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
index 8f785bc9e510..6ec1d400adae 100644
--- a/drivers/regulator/devres.c
+++ b/drivers/regulator/devres.c
@@ -413,3 +413,88 @@ void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
413 devm_regulator_unregister_supply_alias(dev, id[i]); 413 devm_regulator_unregister_supply_alias(dev, id[i]);
414} 414}
415EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias); 415EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias);
416
417struct regulator_notifier_match {
418 struct regulator *regulator;
419 struct notifier_block *nb;
420};
421
422static int devm_regulator_match_notifier(struct device *dev, void *res,
423 void *data)
424{
425 struct regulator_notifier_match *match = res;
426 struct regulator_notifier_match *target = data;
427
428 return match->regulator == target->regulator && match->nb == target->nb;
429}
430
431static void devm_regulator_destroy_notifier(struct device *dev, void *res)
432{
433 struct regulator_notifier_match *match = res;
434
435 regulator_unregister_notifier(match->regulator, match->nb);
436}
437
438/**
439 * devm_regulator_register_notifier - Resource managed
440 * regulator_register_notifier
441 *
442 * @regulator: regulator source
443 * @nb: notifier block
444 *
445 * The notifier will be registers under the consumer device and be
446 * automatically be unregistered when the source device is unbound.
447 */
448int devm_regulator_register_notifier(struct regulator *regulator,
449 struct notifier_block *nb)
450{
451 struct regulator_notifier_match *match;
452 int ret;
453
454 match = devres_alloc(devm_regulator_destroy_notifier,
455 sizeof(struct regulator_notifier_match),
456 GFP_KERNEL);
457 if (!match)
458 return -ENOMEM;
459
460 match->regulator = regulator;
461 match->nb = nb;
462
463 ret = regulator_register_notifier(regulator, nb);
464 if (ret < 0) {
465 devres_free(match);
466 return ret;
467 }
468
469 devres_add(regulator->dev, match);
470
471 return 0;
472}
473EXPORT_SYMBOL_GPL(devm_regulator_register_notifier);
474
475/**
476 * devm_regulator_unregister_notifier - Resource managed
477 * regulator_unregister_notifier()
478 *
479 * @regulator: regulator source
480 * @nb: notifier block
481 *
482 * Unregister a notifier registered with devm_regulator_register_notifier().
483 * Normally this function will not need to be called and the resource
484 * management code will ensure that the resource is freed.
485 */
486void devm_regulator_unregister_notifier(struct regulator *regulator,
487 struct notifier_block *nb)
488{
489 struct regulator_notifier_match match;
490 int rc;
491
492 match.regulator = regulator;
493 match.nb = nb;
494
495 rc = devres_release(regulator->dev, devm_regulator_destroy_notifier,
496 devm_regulator_match_notifier, &match);
497 if (rc != 0)
498 WARN_ON(rc);
499}
500EXPORT_SYMBOL_GPL(devm_regulator_unregister_notifier);
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index d17e1ff7ad01..bd631ee5f1da 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -252,8 +252,12 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
252/* regulator notifier block */ 252/* regulator notifier block */
253int regulator_register_notifier(struct regulator *regulator, 253int regulator_register_notifier(struct regulator *regulator,
254 struct notifier_block *nb); 254 struct notifier_block *nb);
255int devm_regulator_register_notifier(struct regulator *regulator,
256 struct notifier_block *nb);
255int regulator_unregister_notifier(struct regulator *regulator, 257int regulator_unregister_notifier(struct regulator *regulator,
256 struct notifier_block *nb); 258 struct notifier_block *nb);
259void devm_regulator_unregister_notifier(struct regulator *regulator,
260 struct notifier_block *nb);
257 261
258/* driver data - core doesn't touch */ 262/* driver data - core doesn't touch */
259void *regulator_get_drvdata(struct regulator *regulator); 263void *regulator_get_drvdata(struct regulator *regulator);
@@ -515,12 +519,24 @@ static inline int regulator_register_notifier(struct regulator *regulator,
515 return 0; 519 return 0;
516} 520}
517 521
522static inline int devm_regulator_register_notifier(struct regulator *regulator,
523 struct notifier_block *nb)
524{
525 return 0;
526}
527
518static inline int regulator_unregister_notifier(struct regulator *regulator, 528static inline int regulator_unregister_notifier(struct regulator *regulator,
519 struct notifier_block *nb) 529 struct notifier_block *nb)
520{ 530{
521 return 0; 531 return 0;
522} 532}
523 533
534static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
535 struct notifier_block *nb)
536{
537 return 0;
538}
539
524static inline void *regulator_get_drvdata(struct regulator *regulator) 540static inline void *regulator_get_drvdata(struct regulator *regulator)
525{ 541{
526 return NULL; 542 return NULL;