mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 09:13:38 +00:00
pwm: mxs: Make use of devm_pwmchip_alloc() function
This prepares the pwm-mxs 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_mxs_pwm_chip() helper macro to a static inline to get some type safety. Link: https://lore.kernel.org/r/39203f3bfbf4e97654db78bdc7e0c9a2b72c1368.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
ad0828825e
commit
2ae7039fa7
@ -37,12 +37,14 @@ static const u8 cdiv_shift[PERIOD_CDIV_MAX] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mxs_pwm_chip {
|
struct mxs_pwm_chip {
|
||||||
struct pwm_chip chip;
|
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip)
|
static inline struct mxs_pwm_chip *to_mxs_pwm_chip(struct pwm_chip *chip)
|
||||||
|
{
|
||||||
|
return pwmchip_get_drvdata(chip);
|
||||||
|
}
|
||||||
|
|
||||||
static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
const struct pwm_state *state)
|
const struct pwm_state *state)
|
||||||
@ -120,12 +122,21 @@ static const struct pwm_ops mxs_pwm_ops = {
|
|||||||
static int mxs_pwm_probe(struct platform_device *pdev)
|
static int mxs_pwm_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = pdev->dev.of_node;
|
||||||
|
struct pwm_chip *chip;
|
||||||
struct mxs_pwm_chip *mxs;
|
struct mxs_pwm_chip *mxs;
|
||||||
|
u32 npwm;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL);
|
ret = of_property_read_u32(np, "fsl,pwm-number", &npwm);
|
||||||
if (!mxs)
|
if (ret < 0) {
|
||||||
return -ENOMEM;
|
dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*mxs));
|
||||||
|
if (IS_ERR(chip))
|
||||||
|
return PTR_ERR(chip);
|
||||||
|
mxs = to_mxs_pwm_chip(chip);
|
||||||
|
|
||||||
mxs->base = devm_platform_ioremap_resource(pdev, 0);
|
mxs->base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(mxs->base))
|
if (IS_ERR(mxs->base))
|
||||||
@ -135,21 +146,14 @@ static int mxs_pwm_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(mxs->clk))
|
if (IS_ERR(mxs->clk))
|
||||||
return PTR_ERR(mxs->clk);
|
return PTR_ERR(mxs->clk);
|
||||||
|
|
||||||
mxs->chip.dev = &pdev->dev;
|
chip->ops = &mxs_pwm_ops;
|
||||||
mxs->chip.ops = &mxs_pwm_ops;
|
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: Only do this if the PWM isn't already running */
|
/* FIXME: Only do this if the PWM isn't already running */
|
||||||
ret = stmp_reset_block(mxs->base);
|
ret = stmp_reset_block(mxs->base);
|
||||||
if (ret)
|
if (ret)
|
||||||
return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n");
|
return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n");
|
||||||
|
|
||||||
ret = devm_pwmchip_add(&pdev->dev, &mxs->chip);
|
ret = devm_pwmchip_add(&pdev->dev, chip);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret);
|
dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user