Commit 5911fc37 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: imx1: Make use of devm_pwmchip_alloc() function

This prepares the pwm-imx1 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_imx1_chip() helper macro to a static inline to
get some type safety.

Link: https://lore.kernel.org/r/c6995e0d281255a7514edf9f25a561302dcaf65f.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 12ca0c33
...@@ -28,10 +28,12 @@ struct pwm_imx1_chip { ...@@ -28,10 +28,12 @@ struct pwm_imx1_chip {
struct clk *clk_ipg; struct clk *clk_ipg;
struct clk *clk_per; struct clk *clk_per;
void __iomem *mmio_base; void __iomem *mmio_base;
struct pwm_chip chip;
}; };
#define to_pwm_imx1_chip(chip) container_of(chip, struct pwm_imx1_chip, chip) static inline struct pwm_imx1_chip *to_pwm_imx1_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int pwm_imx1_clk_prepare_enable(struct pwm_chip *chip) static int pwm_imx1_clk_prepare_enable(struct pwm_chip *chip)
{ {
...@@ -156,11 +158,13 @@ MODULE_DEVICE_TABLE(of, pwm_imx1_dt_ids); ...@@ -156,11 +158,13 @@ MODULE_DEVICE_TABLE(of, pwm_imx1_dt_ids);
static int pwm_imx1_probe(struct platform_device *pdev) static int pwm_imx1_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct pwm_imx1_chip *imx; struct pwm_imx1_chip *imx;
imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx));
if (!imx) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
imx = to_pwm_imx1_chip(chip);
imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(imx->clk_ipg)) if (IS_ERR(imx->clk_ipg))
...@@ -172,15 +176,13 @@ static int pwm_imx1_probe(struct platform_device *pdev) ...@@ -172,15 +176,13 @@ static int pwm_imx1_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per),
"failed to get peripheral clock\n"); "failed to get peripheral clock\n");
imx->chip.ops = &pwm_imx1_ops; chip->ops = &pwm_imx1_ops;
imx->chip.dev = &pdev->dev;
imx->chip.npwm = 1;
imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); imx->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(imx->mmio_base)) if (IS_ERR(imx->mmio_base))
return PTR_ERR(imx->mmio_base); return PTR_ERR(imx->mmio_base);
return devm_pwmchip_add(&pdev->dev, &imx->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
static struct platform_driver pwm_imx1_driver = { static struct platform_driver pwm_imx1_driver = {
......
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