[PATCH] regulator: rpi-panel-v2: Convert to new PWM waveform ops
Marek Vasut
marek.vasut at mailbox.org
Sat Jun 21 09:18:01 PDT 2025
On 6/17/25 4:13 PM, Uwe Kleine-König wrote:
> Hello Marek,
Hi,
>>> /* The actual value isn't known, so this is made up. */
>>> #define RPI_PANEL_V2_FIXED_PERIOD_NS 100000
>>>
>>>
>>> static int rpi_panel_v2_pwm_round_waveform_tohw(...)
>>> {
>>> ...
>>>
>>> if (wf->duty_length_ns > RPI_PANEL_V2_FIXED_PERIOD_NS)
>>> *wfhw = 100;
>>> else
>>> *wfhw = mul_u64_u64_div_u64(wf->duty_length_ns * 100, RPI_PANEL_V2_FIXED_PERIOD_NS);
>>>
>>> return 0;
>>> }
>>
>> This fixed period specified in driver has one problem -- what if the period
>> is also specified in DT by the consumer, e.g. pwm-backlight pwms property,
>> and it does not match RPI_PANEL_V2_FIXED_PERIOD_NS ?
>
> If it's off by only a little amount you will hardly notice. If it's
> further off that's less optimal. I don't think this is a problem. If the
> device tree is wrong, the machine doesn't work optimally. That's quite
> expected.
Before this rework, the DT period and duty cycle were scaled to match,
so the period mismatch problem never occurred no matter what period was
set in DT. I suspect with this rework, such a behavior is no longer
possible, or is it ?
>> This is easy to solve for this tohw function, but what about the fromhw
>> which assigns period_ns ?
>
> If you only write waveforms to the hardware (probably using
> pwm_apply_might_sleep()), the fromhw callback isn't involved (apart from
> debugging). And all fromhw callbacks are supposed to assign
> period_length_ns. I suspect we don't have the same understanding of the
> PWM abstraction.
The core does check whether the fromhw is implemented alongside
.write_waveform , so how should the fromhw behave in such a case ?
See this drivers/pwm/core.c :
1633 static bool pwm_ops_check(const struct pwm_chip *chip)
1634 {
1635 const struct pwm_ops *ops = chip->ops;
1636
1637 if (ops->write_waveform) {
1638 if (!ops->round_waveform_tohw ||
1639 !ops->round_waveform_fromhw || // <------ HERE
1640 !ops->write_waveform)
1641 return false;
Maybe this should be patched out of the core.c and fromhw removed from
this driver ?
>>>> +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));
>>>
>>> How does the PWM behave without PWM_BL_ENABLE set?
>> The display stays dark.
>
> So you cannot distinguish writing `0` (or any other value) and
> `PWM_BL_ENABLE | 0` I guess?
I think no.
> I ask because for some hardware's it makes a difference, the output
> might e.g go High-Z on disable.
Maybe Dave can clarify this, although I suspect this is also some third
party hardware with no documentation.
More information about the linux-arm-kernel
mailing list