From: Daniel Thompson <daniel.thompson@linaro.org>
To: Flavio Suligoi <f.suligoi@asem.it>
Cc: Lee Jones <lee@kernel.org>, Jingoo Han <jingoohan1@gmail.com>,
Helge Deller <deller@gmx.de>, Pavel Machek <pavel@ucw.cz>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] backlight: mp3309c: Add support for MPS MP3309C
Date: Tue, 26 Sep 2023 14:10:39 +0100 [thread overview]
Message-ID: <20230926131039.GC4356@aspen.lan> (raw)
In-Reply-To: <20230925122609.78849-2-f.suligoi@asem.it>
On Mon, Sep 25, 2023 at 02:26:09PM +0200, Flavio Suligoi wrote:
> diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c
> new file mode 100644
> index 000000000000..923ac7f7b291
> --- /dev/null
> +++ b/drivers/video/backlight/mp3309c.c
> @@ -0,0 +1,398 @@
> ...
> +static int mp3309c_bl_update_status(struct backlight_device *bl)
> +{
> + struct mp3309c_chip *chip = bl_get_data(bl);
> + int brightness = backlight_get_brightness(bl);
> + struct pwm_state pwmstate;
> + unsigned int analog_val, bits_val;
> + int i, ret;
> +
> + if (chip->pdata->dimming_mode == DIMMING_PWM) {
> + /*
> + * PWM dimming mode
> + */
> + pwm_get_state(chip->pwmd, &pwmstate);
> + pwm_set_relative_duty_cycle(&pwmstate, brightness,
> + chip->pdata->max_brightness);
> + pwmstate.enabled = true;
> + ret = pwm_apply_state(chip->pwmd, &pwmstate);
> + if (ret)
> + return ret;
> +
> + switch (chip->pdata->status) {
> + case FIRST_POWER_ON:
> + case BACKLIGHT_OFF:
> + /*
> + * After 20ms of low pwm signal level, the chip turns
> + off automatically. In this case, before enabling the
> + chip again, we must wait about 10ms for pwm signal to
> + stabilize.
> + */
> + if (brightness > 0) {
> + msleep(10);
> + mp3309c_enable_device(chip);
> + chip->pdata->status = BACKLIGHT_ON;
> + } else {
> + chip->pdata->status = BACKLIGHT_OFF;
> + }
> + break;
> + case BACKLIGHT_ON:
> + if (brightness == 0)
> + chip->pdata->status = BACKLIGHT_OFF;
> + break;
> + }
> + } else {
> + /*
> + * Analog dimming (by I2C command) dimming mode
> + *
> + * The first time, before setting brightness, we must enable the
> + * device
> + */
> + if (chip->pdata->status == FIRST_POWER_ON)
> + mp3309c_enable_device(chip);
> +
> + /*
> + * Dimming mode I2C command
> + *
> + * The 5 bits of the dimming analog value D4..D0 is allocated
> + * in the I2C register #0, in the following way:
> + *
> + * +--+--+--+--+--+--+--+--+
> + * |EN|D0|D1|D2|D3|D4|XX|XX|
> + * +--+--+--+--+--+--+--+--+
> + */
> + analog_val = DIV_ROUND_UP(ANALOG_MAX_VAL * brightness,
> + chip->pdata->max_brightness);
Sorry to only notice after sharing a Reviewed-by:[1] but...
Scaling brightness here isn't right. When running in I2C dimming mode then
max_brightness *must* be 31 or lower, meaning the value in brightness can
be applied directly to the hardware without scaling.
Quoting the DT binding docs about how max-brightness should be
interpretted:
Normally the maximum brightness is determined by the hardware and this
property is not required. This property is used to put a software
limit on the brightness apart from what the driver says, as it could
happen that a LED can be made so bright that it gets damaged or causes
damage due to restrictions in a specific system, such as mounting
conditions.
Daniel.
[1] I remember checking if this code could overflow the field but I was
so distracted by that I ended up missing the obvious!
WARNING: multiple messages have this Message-ID (diff)
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Flavio Suligoi <f.suligoi@asem.it>
Cc: devicetree@vger.kernel.org, Conor Dooley <conor+dt@kernel.org>,
Pavel Machek <pavel@ucw.cz>, Jingoo Han <jingoohan1@gmail.com>,
Helge Deller <deller@gmx.de>, Lee Jones <lee@kernel.org>,
linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
linux-leds@vger.kernel.org
Subject: Re: [PATCH v3 2/2] backlight: mp3309c: Add support for MPS MP3309C
Date: Tue, 26 Sep 2023 14:10:39 +0100 [thread overview]
Message-ID: <20230926131039.GC4356@aspen.lan> (raw)
In-Reply-To: <20230925122609.78849-2-f.suligoi@asem.it>
On Mon, Sep 25, 2023 at 02:26:09PM +0200, Flavio Suligoi wrote:
> diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c
> new file mode 100644
> index 000000000000..923ac7f7b291
> --- /dev/null
> +++ b/drivers/video/backlight/mp3309c.c
> @@ -0,0 +1,398 @@
> ...
> +static int mp3309c_bl_update_status(struct backlight_device *bl)
> +{
> + struct mp3309c_chip *chip = bl_get_data(bl);
> + int brightness = backlight_get_brightness(bl);
> + struct pwm_state pwmstate;
> + unsigned int analog_val, bits_val;
> + int i, ret;
> +
> + if (chip->pdata->dimming_mode == DIMMING_PWM) {
> + /*
> + * PWM dimming mode
> + */
> + pwm_get_state(chip->pwmd, &pwmstate);
> + pwm_set_relative_duty_cycle(&pwmstate, brightness,
> + chip->pdata->max_brightness);
> + pwmstate.enabled = true;
> + ret = pwm_apply_state(chip->pwmd, &pwmstate);
> + if (ret)
> + return ret;
> +
> + switch (chip->pdata->status) {
> + case FIRST_POWER_ON:
> + case BACKLIGHT_OFF:
> + /*
> + * After 20ms of low pwm signal level, the chip turns
> + off automatically. In this case, before enabling the
> + chip again, we must wait about 10ms for pwm signal to
> + stabilize.
> + */
> + if (brightness > 0) {
> + msleep(10);
> + mp3309c_enable_device(chip);
> + chip->pdata->status = BACKLIGHT_ON;
> + } else {
> + chip->pdata->status = BACKLIGHT_OFF;
> + }
> + break;
> + case BACKLIGHT_ON:
> + if (brightness == 0)
> + chip->pdata->status = BACKLIGHT_OFF;
> + break;
> + }
> + } else {
> + /*
> + * Analog dimming (by I2C command) dimming mode
> + *
> + * The first time, before setting brightness, we must enable the
> + * device
> + */
> + if (chip->pdata->status == FIRST_POWER_ON)
> + mp3309c_enable_device(chip);
> +
> + /*
> + * Dimming mode I2C command
> + *
> + * The 5 bits of the dimming analog value D4..D0 is allocated
> + * in the I2C register #0, in the following way:
> + *
> + * +--+--+--+--+--+--+--+--+
> + * |EN|D0|D1|D2|D3|D4|XX|XX|
> + * +--+--+--+--+--+--+--+--+
> + */
> + analog_val = DIV_ROUND_UP(ANALOG_MAX_VAL * brightness,
> + chip->pdata->max_brightness);
Sorry to only notice after sharing a Reviewed-by:[1] but...
Scaling brightness here isn't right. When running in I2C dimming mode then
max_brightness *must* be 31 or lower, meaning the value in brightness can
be applied directly to the hardware without scaling.
Quoting the DT binding docs about how max-brightness should be
interpretted:
Normally the maximum brightness is determined by the hardware and this
property is not required. This property is used to put a software
limit on the brightness apart from what the driver says, as it could
happen that a LED can be made so bright that it gets damaged or causes
damage due to restrictions in a specific system, such as mounting
conditions.
Daniel.
[1] I remember checking if this code could overflow the field but I was
so distracted by that I ended up missing the obvious!
next prev parent reply other threads:[~2023-09-26 13:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 12:26 [PATCH v3 1/2] dt-bindings: backlight: Add MPS MP3309C Flavio Suligoi
2023-09-25 12:26 ` Flavio Suligoi
2023-09-25 12:26 ` [PATCH v3 2/2] backlight: mp3309c: Add support for " Flavio Suligoi
2023-09-25 12:26 ` Flavio Suligoi
2023-09-26 13:10 ` Daniel Thompson [this message]
2023-09-26 13:10 ` Daniel Thompson
2023-10-03 9:45 ` Flavio Suligoi
2023-10-03 9:45 ` Flavio Suligoi
2023-09-26 13:01 ` [PATCH v3 1/2] dt-bindings: backlight: Add " Daniel Thompson
2023-09-26 13:01 ` Daniel Thompson
2023-10-03 9:43 ` Flavio Suligoi
2023-10-03 9:43 ` Flavio Suligoi
2023-10-03 10:21 ` Daniel Thompson
2023-10-03 10:21 ` Daniel Thompson
2023-10-03 16:00 ` Flavio Suligoi
2023-10-03 16:00 ` Flavio Suligoi
2023-10-04 15:18 ` Flavio Suligoi
2023-10-04 15:18 ` Flavio Suligoi
2023-10-05 12:58 ` Daniel Thompson
2023-10-05 12:58 ` Daniel Thompson
2023-10-06 8:56 ` Flavio Suligoi
2023-10-06 8:56 ` Flavio Suligoi
2023-09-28 14:03 ` (subset) " Lee Jones
2023-09-28 14:03 ` Lee Jones
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=20230926131039.GC4356@aspen.lan \
--to=daniel.thompson@linaro.org \
--cc=conor+dt@kernel.org \
--cc=deller@gmx.de \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=f.suligoi@asem.it \
--cc=jingoohan1@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=robh+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.