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

pwm: bcm-iproc: Make use of devm_pwmchip_alloc() function

This prepares the pwm-bcm-iproc 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/cdc6136b94f685c85a615e9e5ccbd7ebb2f91cfc.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 19c09ed0
...@@ -34,14 +34,13 @@ ...@@ -34,14 +34,13 @@
#define IPROC_PWM_PRESCALE_MAX 0x3f #define IPROC_PWM_PRESCALE_MAX 0x3f
struct iproc_pwmc { struct iproc_pwmc {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
}; };
static inline struct iproc_pwmc *to_iproc_pwmc(struct pwm_chip *chip) static inline struct iproc_pwmc *to_iproc_pwmc(struct pwm_chip *chip)
{ {
return container_of(chip, struct iproc_pwmc, chip); return pwmchip_get_drvdata(chip);
} }
static void iproc_pwmc_enable(struct iproc_pwmc *ip, unsigned int channel) static void iproc_pwmc_enable(struct iproc_pwmc *ip, unsigned int channel)
...@@ -187,20 +186,20 @@ static const struct pwm_ops iproc_pwm_ops = { ...@@ -187,20 +186,20 @@ static const struct pwm_ops iproc_pwm_ops = {
static int iproc_pwmc_probe(struct platform_device *pdev) static int iproc_pwmc_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct iproc_pwmc *ip; struct iproc_pwmc *ip;
unsigned int i; unsigned int i;
u32 value; u32 value;
int ret; int ret;
ip = devm_kzalloc(&pdev->dev, sizeof(*ip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 4, sizeof(*ip));
if (!ip) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
ip = to_iproc_pwmc(chip);
platform_set_drvdata(pdev, ip); platform_set_drvdata(pdev, ip);
ip->chip.dev = &pdev->dev; chip->ops = &iproc_pwm_ops;
ip->chip.ops = &iproc_pwm_ops;
ip->chip.npwm = 4;
ip->base = devm_platform_ioremap_resource(pdev, 0); ip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(ip->base)) if (IS_ERR(ip->base))
...@@ -214,14 +213,14 @@ static int iproc_pwmc_probe(struct platform_device *pdev) ...@@ -214,14 +213,14 @@ static int iproc_pwmc_probe(struct platform_device *pdev)
/* Set full drive and normal polarity for all channels */ /* Set full drive and normal polarity for all channels */
value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
for (i = 0; i < ip->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
value &= ~(1 << IPROC_PWM_CTRL_TYPE_SHIFT(i)); value &= ~(1 << IPROC_PWM_CTRL_TYPE_SHIFT(i));
value |= 1 << IPROC_PWM_CTRL_POLARITY_SHIFT(i); value |= 1 << IPROC_PWM_CTRL_POLARITY_SHIFT(i);
} }
writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); writel(value, ip->base + IPROC_PWM_CTRL_OFFSET);
ret = devm_pwmchip_add(&pdev->dev, &ip->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"failed to add PWM chip\n"); "failed to add PWM chip\n");
......
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