Skip to content

Commit

Permalink
regulator: pwm-regulator: Calculate the output voltage for disabled PWMs
Browse files Browse the repository at this point in the history
If a PWM output is disabled then it's voltage has to be calculated
based on a zero duty cycle (for normal polarity) or duty cycle being
equal to the PWM period (for inverted polarity). Add support for this
to pwm_regulator_get_voltage().

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Link: https://msgid.link/r/20240113224628.377993-3-martin.blumenstingl@googlemail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Martin Blumenstingl authored and Mark Brown committed Jan 22, 2024
1 parent c92688c commit 6a7d11e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/regulator/pwm-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ static int pwm_regulator_get_voltage(struct regulator_dev *rdev)

pwm_get_state(drvdata->pwm, &pstate);

if (!pstate.enabled) {
if (pstate.polarity == PWM_POLARITY_INVERSED)
pstate.duty_cycle = pstate.period;
else
pstate.duty_cycle = 0;
}

voltage = pwm_get_relative_duty_cycle(&pstate, duty_unit);
if (voltage < min(max_uV_duty, min_uV_duty) ||
voltage > max(max_uV_duty, min_uV_duty))
Expand Down

0 comments on commit 6a7d11e

Please sign in to comment.