pwm: lpc32xx: Make use of devm_pwmchip_alloc() function
This prepares the pwm-lpc32xx 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_lpc32xx_pwm_chip() helper macro to a static inline to get some type safety. Link: https://lore.kernel.org/r/ef26238772ee9ca455a49e9b976a4f66654b26f7.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
1dc7dcba0b
commit
ac4b44cac5
@ -15,7 +15,6 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
|
||||||
struct lpc32xx_pwm_chip {
|
struct lpc32xx_pwm_chip {
|
||||||
struct pwm_chip chip;
|
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
};
|
};
|
||||||
@ -23,8 +22,10 @@ struct lpc32xx_pwm_chip {
|
|||||||
#define PWM_ENABLE BIT(31)
|
#define PWM_ENABLE BIT(31)
|
||||||
#define PWM_PIN_LEVEL BIT(30)
|
#define PWM_PIN_LEVEL BIT(30)
|
||||||
|
|
||||||
#define to_lpc32xx_pwm_chip(_chip) \
|
static inline struct lpc32xx_pwm_chip *to_lpc32xx_pwm_chip(struct pwm_chip *chip)
|
||||||
container_of(_chip, struct lpc32xx_pwm_chip, chip)
|
{
|
||||||
|
return pwmchip_get_drvdata(chip);
|
||||||
|
}
|
||||||
|
|
||||||
static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
int duty_ns, int period_ns)
|
int duty_ns, int period_ns)
|
||||||
@ -119,13 +120,15 @@ static const struct pwm_ops lpc32xx_pwm_ops = {
|
|||||||
|
|
||||||
static int lpc32xx_pwm_probe(struct platform_device *pdev)
|
static int lpc32xx_pwm_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct pwm_chip *chip;
|
||||||
struct lpc32xx_pwm_chip *lpc32xx;
|
struct lpc32xx_pwm_chip *lpc32xx;
|
||||||
int ret;
|
int ret;
|
||||||
u32 val;
|
u32 val;
|
||||||
|
|
||||||
lpc32xx = devm_kzalloc(&pdev->dev, sizeof(*lpc32xx), GFP_KERNEL);
|
chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*lpc32xx));
|
||||||
if (!lpc32xx)
|
if (IS_ERR(chip))
|
||||||
return -ENOMEM;
|
return PTR_ERR(chip);
|
||||||
|
lpc32xx = to_lpc32xx_pwm_chip(chip);
|
||||||
|
|
||||||
lpc32xx->base = devm_platform_ioremap_resource(pdev, 0);
|
lpc32xx->base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(lpc32xx->base))
|
if (IS_ERR(lpc32xx->base))
|
||||||
@ -135,16 +138,14 @@ static int lpc32xx_pwm_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(lpc32xx->clk))
|
if (IS_ERR(lpc32xx->clk))
|
||||||
return PTR_ERR(lpc32xx->clk);
|
return PTR_ERR(lpc32xx->clk);
|
||||||
|
|
||||||
lpc32xx->chip.dev = &pdev->dev;
|
chip->ops = &lpc32xx_pwm_ops;
|
||||||
lpc32xx->chip.ops = &lpc32xx_pwm_ops;
|
|
||||||
lpc32xx->chip.npwm = 1;
|
|
||||||
|
|
||||||
/* If PWM is disabled, configure the output to the default value */
|
/* If PWM is disabled, configure the output to the default value */
|
||||||
val = readl(lpc32xx->base);
|
val = readl(lpc32xx->base);
|
||||||
val &= ~PWM_PIN_LEVEL;
|
val &= ~PWM_PIN_LEVEL;
|
||||||
writel(val, lpc32xx->base);
|
writel(val, lpc32xx->base);
|
||||||
|
|
||||||
ret = devm_pwmchip_add(&pdev->dev, &lpc32xx->chip);
|
ret = devm_pwmchip_add(&pdev->dev, chip);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&pdev->dev, "failed to add PWM chip, error %d\n", ret);
|
dev_err(&pdev->dev, "failed to add PWM chip, error %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user