aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/driver-model/devres.txt4
-rw-r--r--Documentation/pwm.txt3
-rw-r--r--drivers/pwm/core.c58
-rw-r--r--include/linux/pwm.h3
4 files changed, 67 insertions, 1 deletions
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 950856bd2e39..43cff70465ab 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -284,3 +284,7 @@ CLOCK
284PINCTRL 284PINCTRL
285 devm_pinctrl_get() 285 devm_pinctrl_get()
286 devm_pinctrl_put() 286 devm_pinctrl_put()
287
288PWM
289 devm_pwm_get()
290 devm_pwm_put()
diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt
index 554290ebab94..7d2b4c9b544b 100644
--- a/Documentation/pwm.txt
+++ b/Documentation/pwm.txt
@@ -36,7 +36,8 @@ Legacy users can request a PWM device using pwm_request() and free it
36after usage with pwm_free(). 36after usage with pwm_free().
37 37
38New users should use the pwm_get() function and pass to it the consumer 38New users should use the pwm_get() function and pass to it the consumer
39device or a consumer name. pwm_put() is used to free the PWM device. 39device or a consumer name. pwm_put() is used to free the PWM device. Managed
40variants of these functions, devm_pwm_get() and devm_pwm_put(), also exist.
40 41
41After being requested a PWM has to be configured using: 42After being requested a PWM has to be configured using:
42 43
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 85592e97ef2d..92b1782d0d8e 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -646,6 +646,64 @@ out:
646} 646}
647EXPORT_SYMBOL_GPL(pwm_put); 647EXPORT_SYMBOL_GPL(pwm_put);
648 648
649static void devm_pwm_release(struct device *dev, void *res)
650{
651 pwm_put(*(struct pwm_device **)res);
652}
653
654/**
655 * devm_pwm_get() - resource managed pwm_get()
656 * @dev: device for PWM consumer
657 * @con_id: consumer name
658 *
659 * This function performs like pwm_get() but the acquired PWM device will
660 * automatically be released on driver detach.
661 */
662struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
663{
664 struct pwm_device **ptr, *pwm;
665
666 ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
667 if (!ptr)
668 return ERR_PTR(-ENOMEM);
669
670 pwm = pwm_get(dev, con_id);
671 if (!IS_ERR(pwm)) {
672 *ptr = pwm;
673 devres_add(dev, ptr);
674 } else {
675 devres_free(ptr);
676 }
677
678 return pwm;
679}
680EXPORT_SYMBOL_GPL(devm_pwm_get);
681
682static int devm_pwm_match(struct device *dev, void *res, void *data)
683{
684 struct pwm_device **p = res;
685
686 if (WARN_ON(!p || !*p))
687 return 0;
688
689 return *p == data;
690}
691
692/**
693 * devm_pwm_put() - resource managed pwm_put()
694 * @dev: device for PWM consumer
695 * @pwm: PWM device
696 *
697 * Release a PWM previously allocated using devm_pwm_get(). Calling this
698 * function is usually not needed because devm-allocated resources are
699 * automatically released on driver detach.
700 */
701void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
702{
703 WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm));
704}
705EXPORT_SYMBOL_GPL(devm_pwm_put);
706
649#ifdef CONFIG_DEBUG_FS 707#ifdef CONFIG_DEBUG_FS
650static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) 708static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
651{ 709{
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 354764cf5f7a..40c764318957 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -148,6 +148,9 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
148struct pwm_device *pwm_get(struct device *dev, const char *consumer); 148struct pwm_device *pwm_get(struct device *dev, const char *consumer);
149void pwm_put(struct pwm_device *pwm); 149void pwm_put(struct pwm_device *pwm);
150 150
151struct pwm_device *devm_pwm_get(struct device *dev, const char *consumer);
152void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
153
151struct pwm_lookup { 154struct pwm_lookup {
152 struct list_head list; 155 struct list_head list;
153 const char *provider; 156 const char *provider;