Convert the driver from legacy PWM apply ops to modern waveform ops. There is no functional change. Signed-off-by: Marek Vasut <marek.vasut+renesas@xxxxxxxxxxx> --- Cc: "Uwe Kleine-König" <ukleinek@xxxxxxxxxx> Cc: Dave Stevenson <dave.stevenson@xxxxxxxxxxxxxxx> Cc: Liam Girdwood <lgirdwood@xxxxxxxxx> Cc: Mark Brown <broonie@xxxxxxxxxx> Cc: linux-pwm@xxxxxxxxxxxxxxx Cc: linux-renesas-soc@xxxxxxxxxxxxxxx --- V2: - Safeguard against wf->duty_length_ns > wf->period_length_ns --- drivers/regulator/rpi-panel-v2-regulator.c | 53 +++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c index 30b78aa75ee38..eb4c4e3ead364 100644 --- a/drivers/regulator/rpi-panel-v2-regulator.c +++ b/drivers/regulator/rpi-panel-v2-regulator.c @@ -35,24 +35,55 @@ static const struct regmap_config rpi_panel_regmap_config = { .can_sleep = true, }; -static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, - const struct pwm_state *state) +static int rpi_panel_v2_pwm_round_waveform_tohw(struct pwm_chip *chip, + struct pwm_device *pwm, + const struct pwm_waveform *wf, + void *_wfhw) { - struct regmap *regmap = pwmchip_get_drvdata(chip); - unsigned int duty; + u8 *wfhw = _wfhw; + + if (wf->duty_length_ns > wf->period_length_ns) + *wfhw = 100; + else + *wfhw = mul_u64_u64_div_u64(wf->duty_length_ns, 100, wf->period_length_ns); + + return 0; +} - if (state->polarity != PWM_POLARITY_NORMAL) - return -EINVAL; +static int rpi_panel_v2_pwm_round_waveform_fromhw(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw, + struct pwm_waveform *wf) +{ + const u8 *wfhw = _wfhw; + + /* + * These numbers here are utter fabrications, the device is sealed + * in metal casing and difficult to take apart and measure, so we + * pick some arbitrary values here, values which fit nicely. + */ + wf->period_length_ns = 100 * 1000; /* 100 us ~= 10 kHz */ + wf->duty_length_ns = *wfhw * 1000; /* 0..100us */ + wf->duty_offset_ns = 0; + + return 0; +} - if (!state->enabled) - return regmap_write(regmap, REG_PWM, 0); +static int rpi_panel_v2_pwm_write_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw) +{ + struct regmap *regmap = pwmchip_get_drvdata(chip); + const u8 *wfhw = _wfhw; - duty = pwm_get_relative_duty_cycle(state, PWM_BL_MASK); - return regmap_write(regmap, REG_PWM, duty | PWM_BL_ENABLE); + return regmap_write(regmap, REG_PWM, *wfhw | (*wfhw ? PWM_BL_ENABLE : 0)); } static const struct pwm_ops rpi_panel_v2_pwm_ops = { - .apply = rpi_panel_v2_pwm_apply, + .sizeof_wfhw = sizeof(u8), + .round_waveform_fromhw = rpi_panel_v2_pwm_round_waveform_fromhw, + .round_waveform_tohw = rpi_panel_v2_pwm_round_waveform_tohw, + .write_waveform = rpi_panel_v2_pwm_write_waveform, }; /* -- 2.50.1