From: Daniel Thompson <daniel.thompson@linaro.org>
To: "Duje Mihanović" <duje.mihanovic@skole.hr>
Cc: Lee Jones <lee@kernel.org>, Jingoo Han <jingoohan1@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>, Helge Deller <deller@gmx.de>,
Linus Walleij <linus.walleij@linaro.org>,
Karel Balej <balejk@matfyz.cz>,
~postmarketos/upstreaming@lists.sr.ht,
phone-devel@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org
Subject: Re: [PATCH v3 3/3] backlight: Add Kinetic KTD2801 backlight support
Date: Mon, 22 Jan 2024 10:28:05 +0000 [thread overview]
Message-ID: <20240122102805.GB8596@aspen.lan> (raw)
In-Reply-To: <20240120-ktd2801-v3-3-fe2cbafffb21@skole.hr>
On Sat, Jan 20, 2024 at 10:26:45PM +0100, Duje Mihanović wrote:
> KTD2801 is a LED backlight driver IC found in samsung,coreprimevelte.
> The brightness can be set using PWM or the ExpressWire protocol. Add
> support for the KTD2801.
>
> Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr>
As Linus W. said, this is looking really nice now. Thanks!
Just a couple of nits below.
> diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
> index 51387b1ef012..585a5a713759 100644
> --- a/drivers/video/backlight/Kconfig
> +++ b/drivers/video/backlight/Kconfig
> @@ -183,6 +183,14 @@ config BACKLIGHT_KTD253
> which is a 1-wire GPIO-controlled backlight found in some mobile
> phones.
>
> +config BACKLIGHT_KTD2801
> + tristate "Backlight Driver for Kinetic KTD2801"
> + depends on GPIOLIB || COMPILE_TEST
As patch 1 feedback, seems odd for the client to be responsible for
this. It should be managed in LEDS_EXPRESSWIRE.
> + select LEDS_EXPRESSWIRE
> + help
> + Say Y to enable the backlight driver for the Kinetic KTD2801 1-wire
> + GPIO-controlled backlight found in Samsung Galaxy Core Prime VE LTE.
> +
> config BACKLIGHT_KTZ8866
> tristate "Backlight Driver for Kinetic KTZ8866"
> depends on I2C
> diff --git a/drivers/video/backlight/ktd2801-backlight.c b/drivers/video/backlight/ktd2801-backlight.c
> new file mode 100644
> index 000000000000..7b9d1a93aa71
> --- /dev/null
> +++ b/drivers/video/backlight/ktd2801-backlight.c
> @@ -0,0 +1,143 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Datasheet:
> + * https://www.kinet-ic.com/uploads/web/KTD2801/KTD2801-04b.pdf
> + */
> +#include <linux/backlight.h>
> +#include <linux/bits.h>
> +#include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/leds-expresswire.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +
> +/* These values have been extracted from Samsung's driver. */
> +#define KTD2801_EXPRESSWIRE_DETECT_DELAY_US 150
> +#define KTD2801_EXPRESSWIRE_DETECT_US 270
> +#define KTD2801_SHORT_BITSET_US 5
> +#define KTD2801_LONG_BITSET_US (3 * KTD2801_SHORT_BITSET_US)
> +#define KTD2801_DATA_START_US 5
> +#define KTD2801_END_OF_DATA_LOW_US 10
> +#define KTD2801_END_OF_DATA_HIGH_US 350
> +#define KTD2801_PWR_DOWN_DELAY_US 2600
These are a little pointless now. They are all single use constants
and have little documentary value.
The lack of documentary value is because, for example,
KTD2801_EXPRESSWIRE_DETECT_DELAY_US, is assigned to a structure
field called detect_delay_us.
Likewise I doubt that explicitly stating that long_bitset_us is 3x
bigger than short_bitset_us is important for future driver maintainance.
> +
> +#define KTD2801_DEFAULT_BRIGHTNESS 100
> +#define KTD2801_MAX_BRIGHTNESS 255
> +
> +const struct expresswire_timing ktd2801_timing = {
> + .poweroff_us = KTD2801_PWR_DOWN_DELAY_US,
> + .detect_delay_us = KTD2801_EXPRESSWIRE_DETECT_DELAY_US,
> + .detect_us = KTD2801_EXPRESSWIRE_DETECT_US,
> + .data_start_us = KTD2801_DATA_START_US,
> + .short_bitset_us = KTD2801_SHORT_BITSET_US,
> + .long_bitset_us = KTD2801_LONG_BITSET_US,
> + .end_of_data_low_us = KTD2801_END_OF_DATA_LOW_US,
> + .end_of_data_high_us = KTD2801_END_OF_DATA_HIGH_US
> +};
> +
> +struct ktd2801_backlight {
> + struct expresswire_common_props props;
> + struct backlight_device *bd;
> + bool was_on;
> +};
> +
> +static int ktd2801_update_status(struct backlight_device *bd)
> +{
> + struct ktd2801_backlight *ktd2801 = bl_get_data(bd);
> + u8 brightness = (u8) backlight_get_brightness(bd);
> +
> + if (backlight_is_blank(bd)) {
> + expresswire_power_off(&ktd2801->props);
> + ktd2801->was_on = false;
> + return 0;
> + }
> +
> + if (!ktd2801->was_on) {
> + expresswire_enable(&ktd2801->props);
> + ktd2801->was_on = true;
> + }
> +
> + expresswire_start(&ktd2801->props);
> +
> + for (int i = 7; i >= 0; i--)
> + expresswire_set_bit(&ktd2801->props, !!(brightness & BIT(i)));
The !! is redundant... but, as previous feedback, I think writing a u8
should be in the library code anyway.
> + expresswire_end(&ktd2801->props);
> + return 0;
> +}
> +
> <snip>
Daniel.
next prev parent reply other threads:[~2024-01-22 10:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-20 21:26 [PATCH v3 0/3] Kinetic ExpressWire library and KTD2801 backlight driver Duje Mihanović
2024-01-20 21:26 ` [PATCH v3 1/3] leds: ktd2692: move ExpressWire code to library Duje Mihanović
2024-01-21 14:35 ` Linus Walleij
2024-01-21 15:06 ` Duje Mihanović
2024-01-22 10:19 ` Daniel Thompson
2024-01-22 16:24 ` Duje Mihanović
2024-01-22 16:50 ` Daniel Thompson
2024-01-22 16:57 ` Duje Mihanović
2024-01-22 17:26 ` Duje Mihanović
2024-01-22 17:50 ` Daniel Thompson
2024-01-22 18:13 ` Duje Mihanović
2024-01-20 21:26 ` [PATCH v3 2/3] dt-bindings: backlight: add Kinetic KTD2801 binding Duje Mihanović
2024-01-20 21:26 ` [PATCH v3 3/3] backlight: Add Kinetic KTD2801 backlight support Duje Mihanović
2024-01-21 14:37 ` Linus Walleij
2024-01-22 10:28 ` Daniel Thompson [this message]
2024-01-22 16:24 ` Duje Mihanović
2024-01-22 16:51 ` Daniel Thompson
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=20240122102805.GB8596@aspen.lan \
--to=daniel.thompson@linaro.org \
--cc=balejk@matfyz.cz \
--cc=conor+dt@kernel.org \
--cc=deller@gmx.de \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=duje.mihanovic@skole.hr \
--cc=jingoohan1@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=phone-devel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--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).