Commit 8e87e3dc authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: clk: Make use of devm_pwmchip_alloc() function

This prepares the pwm-clk driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Also convert the to_pwm_clk_chip() helper macro to a static inline to
get some type safety.

Link: https://lore.kernel.org/r/c02ccc955fe7a0aec7ce0ccaf5cd2bd902ae687f.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent fc6549a9
...@@ -28,12 +28,14 @@ ...@@ -28,12 +28,14 @@
#include <linux/pwm.h> #include <linux/pwm.h>
struct pwm_clk_chip { struct pwm_clk_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
bool clk_enabled; bool clk_enabled;
}; };
#define to_pwm_clk_chip(_chip) container_of(_chip, struct pwm_clk_chip, chip) static inline struct pwm_clk_chip *to_pwm_clk_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int pwm_clk_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int pwm_clk_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
...@@ -85,19 +87,17 @@ static int pwm_clk_probe(struct platform_device *pdev) ...@@ -85,19 +87,17 @@ static int pwm_clk_probe(struct platform_device *pdev)
struct pwm_clk_chip *pcchip; struct pwm_clk_chip *pcchip;
int ret; int ret;
pcchip = devm_kzalloc(&pdev->dev, sizeof(*pcchip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*pcchip));
if (!pcchip) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
chip = &pcchip->chip; pcchip = to_pwm_clk_chip(chip);
pcchip->clk = devm_clk_get_prepared(&pdev->dev, NULL); pcchip->clk = devm_clk_get_prepared(&pdev->dev, NULL);
if (IS_ERR(pcchip->clk)) if (IS_ERR(pcchip->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(pcchip->clk), return dev_err_probe(&pdev->dev, PTR_ERR(pcchip->clk),
"Failed to get clock\n"); "Failed to get clock\n");
chip->dev = &pdev->dev;
chip->ops = &pwm_clk_ops; chip->ops = &pwm_clk_ops;
chip->npwm = 1;
ret = pwmchip_add(chip); ret = pwmchip_add(chip);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment