linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@mailbox.org>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
	linux-arm-kernel@lists.infradead.org,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH] regulator: rpi-panel-v2: Convert to new PWM waveform ops
Date: Sat, 21 Jun 2025 18:18:01 +0200	[thread overview]
Message-ID: <224fb424-6be7-455e-a2b1-f6e39e40d0d1@mailbox.org> (raw)
In-Reply-To: <pb5gr65kbkokb7ybx3smqaa6vve4rkpg6qks2hdibwgrwmdzfu@6s5msb3k2p6y>

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.


  reply	other threads:[~2025-06-21 16:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17  0:50 [PATCH] regulator: rpi-panel-v2: Convert to new PWM waveform ops Marek Vasut
2025-06-17  8:14 ` Uwe Kleine-König
2025-06-17  9:38   ` Marek Vasut
2025-06-17 14:13     ` Uwe Kleine-König
2025-06-21 16:18       ` Marek Vasut [this message]
2025-06-22 17:42         ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=224fb424-6be7-455e-a2b1-f6e39e40d0d1@mailbox.org \
    --to=marek.vasut@mailbox.org \
    --cc=broonie@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=ukleinek@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).