Skip to content

Commit

Permalink
pwm: Add a device-managed function to add PWM chips
Browse files Browse the repository at this point in the history
This potentially simplifies low-level PWM drivers.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Uwe Kleine-König authored and Thierry Reding committed Jun 28, 2021
1 parent d233504 commit bcda91b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,25 @@ int pwmchip_remove(struct pwm_chip *chip)
}
EXPORT_SYMBOL_GPL(pwmchip_remove);

static void devm_pwmchip_remove(void *data)
{
struct pwm_chip *chip = data;

pwmchip_remove(chip);
}

int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip)
{
int ret;

ret = pwmchip_add(chip);
if (ret)
return ret;

return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip);
}
EXPORT_SYMBOL_GPL(devm_pwmchip_add);

/**
* pwm_request() - request a PWM device
* @pwm: global PWM device index
Expand Down
3 changes: 3 additions & 0 deletions include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ void *pwm_get_chip_data(struct pwm_device *pwm);

int pwmchip_add(struct pwm_chip *chip);
int pwmchip_remove(struct pwm_chip *chip);

int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip);

struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
unsigned int index,
const char *label);
Expand Down

0 comments on commit bcda91b

Please sign in to comment.