pwm: imx-tpm: Make use of devm_pwmchip_alloc() function
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>
This commit is contained in:
parent
dcef3929e0
commit
abf6569d64
@ -57,7 +57,6 @@
|
|||||||
#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)
|
#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)
|
||||||
|
|
||||||
struct imx_tpm_pwm_chip {
|
struct imx_tpm_pwm_chip {
|
||||||
struct pwm_chip chip;
|
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
@ -75,7 +74,7 @@ struct imx_tpm_pwm_param {
|
|||||||
static inline struct imx_tpm_pwm_chip *
|
static inline struct imx_tpm_pwm_chip *
|
||||||
to_imx_tpm_pwm_chip(struct pwm_chip *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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -336,35 +335,40 @@ static const struct pwm_ops imx_tpm_pwm_ops = {
|
|||||||
|
|
||||||
static int pwm_imx_tpm_probe(struct platform_device *pdev)
|
static int pwm_imx_tpm_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct pwm_chip *chip;
|
||||||
struct imx_tpm_pwm_chip *tpm;
|
struct imx_tpm_pwm_chip *tpm;
|
||||||
|
void __iomem *base;
|
||||||
int ret;
|
int ret;
|
||||||
|
unsigned int npwm;
|
||||||
u32 val;
|
u32 val;
|
||||||
|
|
||||||
tpm = devm_kzalloc(&pdev->dev, sizeof(*tpm), GFP_KERNEL);
|
base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (!tpm)
|
if (IS_ERR(base))
|
||||||
return -ENOMEM;
|
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);
|
platform_set_drvdata(pdev, tpm);
|
||||||
|
|
||||||
tpm->base = devm_platform_ioremap_resource(pdev, 0);
|
tpm->base = base;
|
||||||
if (IS_ERR(tpm->base))
|
|
||||||
return PTR_ERR(tpm->base);
|
|
||||||
|
|
||||||
tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
|
tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
|
||||||
if (IS_ERR(tpm->clk))
|
if (IS_ERR(tpm->clk))
|
||||||
return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk),
|
return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk),
|
||||||
"failed to get PWM clock\n");
|
"failed to get PWM clock\n");
|
||||||
|
|
||||||
tpm->chip.dev = &pdev->dev;
|
chip->ops = &imx_tpm_pwm_ops;
|
||||||
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);
|
|
||||||
|
|
||||||
mutex_init(&tpm->lock);
|
mutex_init(&tpm->lock);
|
||||||
|
|
||||||
ret = devm_pwmchip_add(&pdev->dev, &tpm->chip);
|
ret = devm_pwmchip_add(&pdev->dev, chip);
|
||||||
if (ret)
|
if (ret)
|
||||||
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
|
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user