Skip to content

Commit

Permalink
pwm: imx-tpm: Make use of devm_pwmchip_alloc() function
Browse files Browse the repository at this point in the history
This prepares the pwm-tmp 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.

Link: https://lore.kernel.org/r/5de5d53295fa445d58a79f83421dd3406166c3c6.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
  • Loading branch information
Uwe Kleine-König committed Feb 19, 2024
1 parent dcef392 commit abf6569
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions drivers/pwm/pwm-imx-tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)

struct imx_tpm_pwm_chip {
struct pwm_chip chip;
struct clk *clk;
void __iomem *base;
struct mutex lock;
Expand All @@ -75,7 +74,7 @@ struct imx_tpm_pwm_param {
static inline struct imx_tpm_pwm_chip *
to_imx_tpm_pwm_chip(struct pwm_chip *chip)
{
return container_of(chip, struct imx_tpm_pwm_chip, chip);
return pwmchip_get_drvdata(chip);
}

/*
Expand Down Expand Up @@ -336,35 +335,40 @@ static const struct pwm_ops imx_tpm_pwm_ops = {

static int pwm_imx_tpm_probe(struct platform_device *pdev)
{
struct pwm_chip *chip;
struct imx_tpm_pwm_chip *tpm;
void __iomem *base;
int ret;
unsigned int npwm;
u32 val;

tpm = devm_kzalloc(&pdev->dev, sizeof(*tpm), GFP_KERNEL);
if (!tpm)
return -ENOMEM;
base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base))
return PTR_ERR(base);

/* get number of channels */
val = readl(base + PWM_IMX_TPM_PARAM);
npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val);

chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*tpm));
if (IS_ERR(chip))
return PTR_ERR(chip);
tpm = to_imx_tpm_pwm_chip(chip);

platform_set_drvdata(pdev, tpm);

tpm->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(tpm->base))
return PTR_ERR(tpm->base);
tpm->base = base;

tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(tpm->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk),
"failed to get PWM clock\n");

tpm->chip.dev = &pdev->dev;
tpm->chip.ops = &imx_tpm_pwm_ops;

/* get number of channels */
val = readl(tpm->base + PWM_IMX_TPM_PARAM);
tpm->chip.npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val);
chip->ops = &imx_tpm_pwm_ops;

mutex_init(&tpm->lock);

ret = devm_pwmchip_add(&pdev->dev, &tpm->chip);
ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");

Expand Down

0 comments on commit abf6569

Please sign in to comment.