Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c31252c authored by Boris Brezillon's avatar Boris Brezillon Committed by Thierry Reding
Browse files

pwm: Add the pwm_is_enabled() helper



Some PWM drivers are testing the PWMF_ENABLED flag. Create a helper
function to hide the logic behind enabled test. This will allow us to
smoothly move from the current approach to an atomic PWM update
approach.

Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent d770e558
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -455,7 +455,7 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
	if (!pwm->chip->ops->set_polarity)
		return -ENOSYS;

	if (test_bit(PWMF_ENABLED, &pwm->flags))
	if (pwm_is_enabled(pwm))
		return -EBUSY;

	err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
@@ -853,7 +853,7 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
		if (test_bit(PWMF_REQUESTED, &pwm->flags))
			seq_puts(s, " requested");

		if (test_bit(PWMF_ENABLED, &pwm->flags))
		if (pwm_is_enabled(pwm))
			seq_puts(s, " enabled");

		seq_puts(s, "\n");
+1 −1
Original line number Diff line number Diff line
@@ -347,7 +347,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
	tcbpwm->duty = duty;

	/* If the PWM is enabled, call enable to apply the new conf */
	if (test_bit(PWMF_ENABLED, &pwm->flags))
	if (pwm_is_enabled(pwm))
		atmel_tcb_pwm_enable(chip, pwm);

	return 0;
+3 −3
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
	u32 val;
	int ret;

	if (test_bit(PWMF_ENABLED, &pwm->flags) && (period_ns != pwm->period)) {
	if (pwm_is_enabled(pwm) && (period_ns != pwm->period)) {
		dev_err(chip->dev, "cannot change PWM period while enabled\n");
		return -EBUSY;
	}
@@ -176,7 +176,7 @@ static void atmel_pwm_config_v1(struct pwm_chip *chip, struct pwm_device *pwm,
	 * If the PWM channel is enabled, only update CDTY by using the update
	 * register, it needs to set bit 10 of CMR to 0
	 */
	if (test_bit(PWMF_ENABLED, &pwm->flags))
	if (pwm_is_enabled(pwm))
		return;
	/*
	 * If the PWM channel is disabled, write value to duty and period
@@ -191,7 +191,7 @@ static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm,
{
	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);

	if (test_bit(PWMF_ENABLED, &pwm->flags)) {
	if (pwm_is_enabled(pwm)) {
		/*
		 * If the PWM channel is enabled, using the duty update register
		 * to update the value.
+2 −2
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm,
	}

	/* If the PWM channel is enabled, write the settings to the HW */
	if (test_bit(PWMF_ENABLED, &pwm->flags)) {
	if (pwm_is_enabled(pwm)) {
		value = readl(kp->base + PRESCALE_OFFSET);
		value &= ~PRESCALE_MASK(chan);
		value |= prescale << PRESCALE_SHIFT(chan);
@@ -287,7 +287,7 @@ static int kona_pwmc_remove(struct platform_device *pdev)
	unsigned int chan;

	for (chan = 0; chan < kp->chip.npwm; chan++)
		if (test_bit(PWMF_ENABLED, &kp->chip.pwms[chan].flags))
		if (pwm_is_enabled(&kp->chip.pwms[chan]))
			clk_disable_unprepare(kp->clk);

	return pwmchip_remove(&kp->chip);
+2 −2
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ static int ep93xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
	 * The clock needs to be enabled to access the PWM registers.
	 * Configuration can be changed at any time.
	 */
	if (!test_bit(PWMF_ENABLED, &pwm->flags)) {
	if (!pwm_is_enabled(pwm)) {
		ret = clk_enable(ep93xx_pwm->clk);
		if (ret)
			return ret;
@@ -113,7 +113,7 @@ static int ep93xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
		ret = -EINVAL;
	}

	if (!test_bit(PWMF_ENABLED, &pwm->flags))
	if (!pwm_is_enabled(pwm))
		clk_disable(ep93xx_pwm->clk);

	return ret;
Loading