[PATCH] regulator: rpi-panel-v2: Convert to new PWM waveform ops
Marek Vasut
marek.vasut+renesas at mailbox.org
Mon Jun 16 17:50:25 PDT 2025
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 at mailbox.org>
---
Cc: "Uwe Kleine-König" <ukleinek at kernel.org>
Cc: Dave Stevenson <dave.stevenson at raspberrypi.com>
Cc: Liam Girdwood <lgirdwood at gmail.com>
Cc: Mark Brown <broonie at kernel.org>
Cc: linux-renesas-soc at vger.kernel.org
---
drivers/regulator/rpi-panel-v2-regulator.c | 50 +++++++++++++++++-----
1 file changed, 39 insertions(+), 11 deletions(-)
diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c
index 30b78aa75ee3..be42afc81d72 100644
--- a/drivers/regulator/rpi-panel-v2-regulator.c
+++ b/drivers/regulator/rpi-panel-v2-regulator.c
@@ -35,24 +35,52 @@ 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;
+
+ *wfhw = DIV_ROUND_CLOSEST_ULL(wf->duty_length_ns * PWM_BL_MASK, 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.47.2
More information about the linux-arm-kernel
mailing list