linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Jianhua Lu <lujianhua000@gmail.com>
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>,
	Helge Deller <deller@gmx.de>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-fbdev@vger.kernel.org
Subject: Re: [PATCH v3 1/2] backlight: ktz8866: Add support for Kinetic KTZ8866 backlight
Date: Thu, 22 Dec 2022 16:39:54 +0000	[thread overview]
Message-ID: <Y6SIWoVFX/OlNO0n@aspen.lan> (raw)
In-Reply-To: <20221222125441.1547-1-lujianhua000@gmail.com>

On Thu, Dec 22, 2022 at 08:54:40PM +0800, Jianhua Lu wrote:
> Add support for Kinetic KTZ8866 backlight, which is used in
> Xiaomi tablet, Mi Pad 5 series. This driver lightly based on
> downstream implementation [1].
> [1] https://github.com/MiCode/Xiaomi_Kernel_OpenSource/blob/elish-r-oss/drivers/video/backlight/ktz8866.c
>
> Signed-off-by: Jianhua Lu <lujianhua000@gmail.com>
> ---
> Changes in v2:
>   - Add missing staitc modifier to ktz8866_write function.
>
> Changes in v3:
>   - Add 2022 to Copyright line.
>   - Sort headers
>   - Remove meaningless comment
>   - Use definitions instead of hardcoding.
>   - Add missing maintainer info
>
>  MAINTAINERS                       |   6 +
>  drivers/video/backlight/Kconfig   |   8 ++
>  drivers/video/backlight/Makefile  |   1 +
>  drivers/video/backlight/ktz8866.c | 180 ++++++++++++++++++++++++++++++
>  drivers/video/backlight/ktz8866.h |  31 +++++
>  5 files changed, 226 insertions(+)
>  create mode 100644 drivers/video/backlight/ktz8866.c
>  create mode 100644 drivers/video/backlight/ktz8866.h
>
> diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
> new file mode 100644
> index 000000000000..ea641bdfc4d2
> --- /dev/null
> +++ b/drivers/video/backlight/ktz8866.c
> @@ -0,0 +1,180 @@
> +
> +#define BL_EN_BIT BIT(6)
> +#define BL_CURRENT_SINKS 0x1F
> +#define BL_OVP_LIMIT 0x33
> +#define LED_CURRENT_RAMPING_TIME 0xBD
> +#define LED_DIMMING_TIME 0x11
> +#define LCD_BIAS_EN 0x9F
> +#define LED_CURRENT 0xF9
> +
> +#define low_3_bit(x) ((x)&0x7)
> +#define high_8_bit(x) ((x >> 3) & 0xFF)

These don't seem to be particularly useful. They are used exactly once
so I think it is better just to implement the shifts directly
in ktz8866_backlight_update_status().

> +struct ktz8866 {
> +	struct i2c_client *client;
> +	struct regmap *regmap;
> +	bool state;
> +};
> +
> +enum {
> +	LED_OFF,
> +	LED_ON,
> +};

Let's remove this emum. It is better to rename state to
led_on in order to make the code read well:

  if (ktz->led_on) ...
  ktz->led_on = true;
  ktz->led_on = false;

> +static void ktz8866_init(struct ktz8866 *ktz)
> +{
> +	/* Enable 1~5 current sinks */
> +	ktz8866_write(ktz, BL_EN, BL_CURRENT_SINKS);
> +	/* Backlight OVP 26.4V */
> +	ktz8866_write(ktz, BL_CFG1, BL_OVP_LIMIT);
> +	/* LED current ramping time 128ms */
> +	ktz8866_write(ktz, BL_CFG2, LED_CURRENT_RAMPING_TIME);
> +	/* LED on/off ramping time 1ms */
> +	ktz8866_write(ktz, BL_DIMMING, LED_DIMMING_TIME);
> +	/* Enable OUTP and OUTN via pin ENP and ENN */
> +	ktz8866_write(ktz, LCD_BIAS_CFG1, LCD_BIAS_EN);
> +	/* Backlight Full-scale LED Current 30.0mA */
> +	ktz8866_write(ktz, FULL_SCALE_CURRENT, LED_CURRENT);
> +}

Are these settings specific to the mipad 5 m/board? Many of these look
like they should be described in the devicetree rather than hardcoded
in the driver.


> +static int ktz8866_probe(struct i2c_client *client,
> +			 const struct i2c_device_id *id)
> +{
> +	struct backlight_device *backlight_dev;
> +	struct backlight_properties props;
> +	struct ktz8866 *ktz;
> +
> +	ktz = devm_kzalloc(&client->dev, sizeof(*ktz), GFP_KERNEL);
> +	if (!ktz)
> +		return -ENOMEM;
> +
> +	ktz->client = client;
> +	ktz->regmap = devm_regmap_init_i2c(client, &ktz8866_regmap_config);
> +
> +	if (IS_ERR(ktz->regmap)) {
> +		dev_err(&client->dev, "failed to init regmap\n");
> +		return PTR_ERR(ktz->regmap);
> +	}
> +
> +	memset(&props, 0, sizeof(props));
> +	props.type = BACKLIGHT_RAW;
> +	props.max_brightness = MAX_BRIGHTNESS;
> +	props.brightness = clamp_t(unsigned int, DEFAULT_BRIGHTNESS, 0,
> +				   props.max_brightness);

Please set the scale property correctly. "Unknown" is never correct for
new drivers.


> +	backlight_dev = devm_backlight_device_register(
> +		&client->dev, "ktz8866-backlight", &client->dev, ktz,
> +		&ktz8866_backlight_ops, &props);
> +
> +	if (IS_ERR(backlight_dev)) {
> +		dev_err(&client->dev, "failed to register backlight device\n");
> +		return PTR_ERR(backlight_dev);
> +	}
> +
> +	ktz8866_init(ktz);
> +
> +	i2c_set_clientdata(client, backlight_dev);
> +	backlight_update_status(backlight_dev);
> +
> +	return 0;
> +}
> diff --git a/drivers/video/backlight/ktz8866.h b/drivers/video/backlight/ktz8866.h
> new file mode 100644
> index 000000000000..b0ed8cbee608
> --- /dev/null
> +++ b/drivers/video/backlight/ktz8866.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Register definitions for Kinetic KTZ8866 backlight
> + *
> + * Copyright (C) 2022 Jianhua Lu <lujianhua000@gmail.com>
> + */
> +
> +#ifndef KTZ8866_H
> +#define KTZ8866_H
> +
> +#define DEVICE_ID 0x01
> +#define BL_CFG1 0x02
> +#define BL_CFG2 0x03
> +#define BL_BRT_LSB 0x04
> +#define BL_BRT_MSB 0x05
> +#define BL_EN 0x08
> +#define LCD_BIAS_CFG1 0x09
> +#define LCD_BIAS_CFG2 0x0A
> +#define LCD_BIAS_CFG3 0x0B
> +#define LCD_BOOST_CFG 0x0C
> +#define OUTP_CFG 0x0D
> +#define OUTN_CFG 0x0E
> +#define FLAG 0x0F
> +#define BL_OPTION1 0x10
> +#define BL_OPTION2 0x11
> +#define PWM2DIG_LSBs 0x12
> +#define PWM2DIG_MSBs 0x13
> +#define BL_DIMMING 0x14
> +#define FULL_SCALE_CURRENT 0x15
> +
> +#endif /* KTZ8866_H */

This header file is not required. Please remove and move any definitions
the driver needs into the C file.


Daniel.

      parent reply	other threads:[~2022-12-22 16:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 12:54 [PATCH v3 1/2] backlight: ktz8866: Add support for Kinetic KTZ8866 backlight Jianhua Lu
2022-12-22 12:54 ` [PATCH v3 2/2] dt-bindings: leds: backlight: Add " Jianhua Lu
2022-12-22 16:39 ` Daniel Thompson [this message]

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=Y6SIWoVFX/OlNO0n@aspen.lan \
    --to=daniel.thompson@linaro.org \
    --cc=deller@gmx.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --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=lujianhua000@gmail.com \
    --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 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).