linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Artur Weber <aweber.kernel@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Lee Jones <lee@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	Jingoo Han <jingoohan1@gmail.com>, Pavel Machek <pavel@ucw.cz>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Helge Deller <deller@gmx.de>,
	dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-tegra@vger.kernel.org,
	linux-fbdev@vger.kernel.org, linux-pwm@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH 2/4] video: backlight: lp855x: get PWM for PWM mode during probe
Date: Fri, 16 Jun 2023 17:29:08 +0200	[thread overview]
Message-ID: <23f9f004-3e20-67b0-bddc-ab9700968c53@gmail.com> (raw)
In-Reply-To: <20230614083953.e4kkweddjz7wztby@pengutronix.de>

On 14/06/2023 10:39, Uwe Kleine-König wrote:
> On Sat, Apr 29, 2023 at 12:45:32PM +0200, Artur Weber wrote:
>> Also deprecate the pwm-period DT property, as it is now redundant
>> (pwms property already contains period value).
>>
>> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
>> ---
>>  drivers/video/backlight/lp855x_bl.c | 48 ++++++++++++++++-------------
>>  1 file changed, 26 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
>> index 81012bf29baf..21eb4943ed56 100644
>> --- a/drivers/video/backlight/lp855x_bl.c
>> +++ b/drivers/video/backlight/lp855x_bl.c
>> ...
>> @@ -472,11 +456,31 @@ static int lp855x_probe(struct i2c_client *cl)
>>  	lp->enable = devm_regulator_get_optional(dev, "enable");
>>  	if (IS_ERR(lp->enable)) {
>>  		ret = PTR_ERR(lp->enable);
>> -		if (ret == -ENODEV) {
>> +		if (ret == -ENODEV)
>>  			lp->enable = NULL;
>> -		} else {
>> +		else
>>  			return dev_err_probe(dev, ret, "getting enable regulator\n");
>> -		}
>> +	}
>> +
>> +	lp->pwm = devm_pwm_get(lp->dev, lp->chipname);
>> +	if (IS_ERR(lp->pwm)) {
>> +		ret = PTR_ERR(lp->pwm);
>> +		if (ret == -ENODEV || ret == -EINVAL)
> 
> Why would you ignore EINVAL?

EINVAL is returned when the pwms property is not found in the DT node
for the backlight. Not sure if there's a better way of separately
detecting whether it's present (especially when taking into
consideration non-DT platforms that might use the driver). Would be nice
to have something like devm_regulator_get_optional but for PWMs...

Still, someone who's setting up the driver could check the debug
messages to see if the backlight was set up in PWM mode or register mode.

> ...
>> +		pwm_init_state(lp->pwm, &pwmstate);
>> +		/* Legacy platform data compatibility */
>> +		if (lp->pdata->period_ns > 0)
>> +			pwmstate.period = lp->pdata->period_ns;
>> +		pwm_apply_state(lp->pwm, &pwmstate);
> 
> This is a change in behaviour. Before lp855x_probe() didn't modify the
> state the bootloader left the backlight in. Now you're disabling it (I
> think). Is this intended?

I didn't really consider the implication of this in this way, as on the
device I was testing this on (Exynos4212-based tablet) the PWM state
would get reset during PWM chip initialization in the kernel anyways,
meaning that the state from the bootloader would be lost regardless of
this change. Either way, there's no guarantee that this would be the
same on other devices, though I'd assume that in most cases it's not
noticeable anyways as brightness is usually set somewhere in userspace
(or even earlier, in the driver, if the init-brt property is set).
Nonetheless, that's an oversight on my part.

As for the reasoning for this change in behavior - the previous behavior
was to silently fail if, while setting the brightness, the PWM could not
be set up. This seemed rather confusing to me (I encountered this while
I was initially working on the tablet, I added a "pwm" property instead
of "pwms" and was wondering why the backlight didn't work...)

Of course, that could be fixed by adding error detection in the
brightness set function, but since I was already working on it, it made
more sense to me for the PWM to be set up during the probing process,
given that this way we could 1. warn about errors early, and 2. catch
deferred probes and defer the backlight's probe if we're still waiting
for the PWM. That's why it's done the way it is in this patch.

If this is undesired behavior, let me know and I'll submit another patch
to revert it.

Best regards
Artur

  reply	other threads:[~2023-06-16 15:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-29 10:45 [PATCH 0/4] video: backlight: lp855x: modernize bindings Artur Weber
2023-04-29 10:45 ` [PATCH 1/4] dt-bindings: backlight: lp855x: convert to YAML and modernize Artur Weber
2023-05-05 20:20   ` Rob Herring
2023-04-29 10:45 ` [PATCH 2/4] video: backlight: lp855x: get PWM for PWM mode during probe Artur Weber
2023-06-14  8:39   ` Uwe Kleine-König
2023-06-16 15:29     ` Artur Weber [this message]
2023-06-16 16:41       ` Uwe Kleine-König
2023-04-29 10:45 ` [PATCH 3/4] ARM: dts: adapt to LP855X bindings changes Artur Weber
2023-04-29 11:14   ` Luca Weiss
2023-04-29 10:45 ` [PATCH 4/4] arm64: " Artur Weber

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=23f9f004-3e20-67b0-bddc-ab9700968c53@gmail.com \
    --to=aweber.kernel@gmail.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=daniel.thompson@linaro.org \
    --cc=deller@gmx.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jingoohan1@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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).