pwm: atmel: Change prototype of a helper to prepare further changes

This prepares the driver for further changes that will make it harder to
determine the pwm_chip from a given atmel_pwm_chip. To just not have to
do that, rework atmel_pwm_enable_clk_if_on() to take a pwm_chip.

Link: https://lore.kernel.org/r/c9a92f77760e401debfe0c9bfc086222f31fb3c4.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This commit is contained in:
Uwe Kleine-König 2024-02-14 10:30:55 +01:00
parent 5dd820cbfc
commit cc2b5bc614

View File

@ -459,8 +459,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids);
static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
static int atmel_pwm_enable_clk_if_on(struct pwm_chip *chip, bool on)
{
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
unsigned int i, cnt = 0;
unsigned long sr;
int ret = 0;
@ -469,7 +470,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
if (!sr)
return 0;
cnt = bitmap_weight(&sr, atmel_pwm->chip.npwm);
cnt = bitmap_weight(&sr, chip->npwm);
if (!on)
goto disable_clk;
@ -477,7 +478,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
for (i = 0; i < cnt; i++) {
ret = clk_enable(atmel_pwm->clk);
if (ret) {
dev_err(atmel_pwm->chip.dev,
dev_err(chip->dev,
"failed to enable clock for pwm %pe\n",
ERR_PTR(ret));
@ -498,6 +499,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
static int atmel_pwm_probe(struct platform_device *pdev)
{
struct atmel_pwm_chip *atmel_pwm;
struct pwm_chip *chip;
int ret;
atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL);
@ -518,15 +520,16 @@ static int atmel_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->clk),
"failed to get prepared PWM clock\n");
atmel_pwm->chip.dev = &pdev->dev;
atmel_pwm->chip.ops = &atmel_pwm_ops;
atmel_pwm->chip.npwm = 4;
chip = &atmel_pwm->chip;
chip->dev = &pdev->dev;
chip->ops = &atmel_pwm_ops;
chip->npwm = 4;
ret = atmel_pwm_enable_clk_if_on(atmel_pwm, true);
ret = atmel_pwm_enable_clk_if_on(chip, true);
if (ret < 0)
return ret;
ret = devm_pwmchip_add(&pdev->dev, &atmel_pwm->chip);
ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) {
dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
goto disable_clk;
@ -535,7 +538,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
return 0;
disable_clk:
atmel_pwm_enable_clk_if_on(atmel_pwm, false);
atmel_pwm_enable_clk_if_on(chip, false);
return ret;
}