Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 333088
b: refs/heads/master
c: 6354316
h: refs/heads/master
v: v3
  • Loading branch information
Alexandre Courbot authored and Thierry Reding committed Sep 10, 2012
1 parent 06eab1b commit a1b4ff5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0aa0869c3c9b10338dd92a20fa4a9b6959f177b5
refs/heads/master: 6354316dbe5a13b25bea15d7ffc891be025eb267
4 changes: 4 additions & 0 deletions trunk/Documentation/driver-model/devres.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,7 @@ CLOCK
PINCTRL
devm_pinctrl_get()
devm_pinctrl_put()

PWM
devm_pwm_get()
devm_pwm_put()
3 changes: 2 additions & 1 deletion trunk/Documentation/pwm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Legacy users can request a PWM device using pwm_request() and free it
after usage with pwm_free().

New users should use the pwm_get() function and pass to it the consumer
device or a consumer name. pwm_put() is used to free the PWM device.
device or a consumer name. pwm_put() is used to free the PWM device. Managed
variants of these functions, devm_pwm_get() and devm_pwm_put(), also exist.

After being requested a PWM has to be configured using:

Expand Down
58 changes: 58 additions & 0 deletions trunk/drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,64 @@ void pwm_put(struct pwm_device *pwm)
}
EXPORT_SYMBOL_GPL(pwm_put);

static void devm_pwm_release(struct device *dev, void *res)
{
pwm_put(*(struct pwm_device **)res);
}

/**
* devm_pwm_get() - resource managed pwm_get()
* @dev: device for PWM consumer
* @con_id: consumer name
*
* This function performs like pwm_get() but the acquired PWM device will
* automatically be released on driver detach.
*/
struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
{
struct pwm_device **ptr, *pwm;

ptr = devres_alloc(devm_pwm_release, sizeof(**ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

pwm = pwm_get(dev, con_id);
if (!IS_ERR(pwm)) {
*ptr = pwm;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}

return pwm;
}
EXPORT_SYMBOL_GPL(devm_pwm_get);

static int devm_pwm_match(struct device *dev, void *res, void *data)
{
struct pwm_device **p = res;

if (WARN_ON(!p || !*p))
return 0;

return *p == data;
}

/**
* devm_pwm_put() - resource managed pwm_put()
* @dev: device for PWM consumer
* @pwm: PWM device
*
* Release a PWM previously allocated using devm_pwm_get(). Calling this
* function is usually not needed because devm-allocated resources are
* automatically released on driver detach.
*/
void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
{
WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm));
}
EXPORT_SYMBOL_GPL(devm_pwm_put);

#ifdef CONFIG_DEBUG_FS
static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
{
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
struct pwm_device *pwm_get(struct device *dev, const char *consumer);
void pwm_put(struct pwm_device *pwm);

struct pwm_device *devm_pwm_get(struct device *dev, const char *consumer);
void devm_pwm_put(struct device *dev, struct pwm_device *pwm);

struct pwm_lookup {
struct list_head list;
const char *provider;
Expand Down

0 comments on commit a1b4ff5

Please sign in to comment.