Linux Framebuffer Layer development
 help / color / mirror / Atom feed
From: Luka Panio <lukapanio@gmail.com>
To: lee@kernel.org, danielt@kernel.org, jingoohan1@gmail.com
Cc: pavel@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, deller@gmx.de, griffin@kroah.com,
	junjie.cao@linux.dev, mitltlatltl@gmail.com,
	andreas@kemnade.info, dri-devel@lists.freedesktop.org,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Luka Panio <lukapanio@gmail.com>
Subject: [PATCH v2 6/6] backlight: aw99706: Add AW99703 support
Date: Sat,  5 Dec 2026 01:51:18 +0100	[thread overview]
Message-ID: <20261205005118.884885-7-lukapanio@gmail.com> (raw)
In-Reply-To: <20261205005118.884885-1-lukapanio@gmail.com>

The Awinic AW99703 is a 3-channel WLED driver with an integrated boost
converter and 11-bit brightness control over I2C. It follows the same
programming model as the AW99706 but with a different register layout,
so add it as another chip variant.

Register values follow the AW99703 datasheet (V1.6).

Signed-off-by: Luka Panio <lukapanio@gmail.com>
---
 drivers/video/backlight/Kconfig   |   6 +-
 drivers/video/backlight/aw99706.c | 194 +++++++++++++++++++++++++++++-
 2 files changed, 193 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index dbf4ca23a9b6..894e593cef6c 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -157,12 +157,12 @@ config BACKLIGHT_ATMEL_LCDC
 	  in unless the board's description says it's wired that way.
 
 config BACKLIGHT_AW99706
-	tristate "Backlight Driver for Awinic AW99706"
+	tristate "Backlight Driver for Awinic AW99706 and AW99703"
 	depends on I2C
 	select REGMAP_I2C
 	help
-	  If you have a LCD backlight connected to the WLED output of AW99706
-	  WLED output, say Y here to enable this driver.
+	  If you have a LCD backlight connected to the WLED output of an
+	  Awinic AW99706 or AW99703, say Y here to enable this driver.
 
 config BACKLIGHT_EP93XX
 	tristate "Cirrus EP93xx Backlight Driver"
diff --git a/drivers/video/backlight/aw99706.c b/drivers/video/backlight/aw99706.c
index 5e0f8ccd3c88..f898df0d4ed1 100644
--- a/drivers/video/backlight/aw99706.c
+++ b/drivers/video/backlight/aw99706.c
@@ -1,9 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * aw99706 - Backlight driver for the AWINIC AW99706
+ * aw99706 - Backlight driver for the AWINIC AW99706 and AW99703
  *
  * Copyright (C) 2025 Junjie Cao <caojunjie650@gmail.com>
  * Copyright (C) 2025 Pengyu Luo <mitltlatltl@gmail.com>
+ * Copyright (C) 2026 Luka Panio <lukapanio@gmail.com>
  *
  * Based on vendor driver:
  * Copyright (c) 2023 AWINIC Technology CO., LTD
@@ -16,6 +17,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 
 #define AW99706_MAX_BRT_LVL		4095
 #define AW99706_REG_MAX			0x1F
@@ -57,6 +59,33 @@
 #define AW99706_MTPLDOSEL_REG			0x1E
 #define AW99706_MTPRUN_REG			0x1F
 
+#define AW99703_MAX_BRT_LVL		2047
+#define AW99703_ID			0x03
+#define AW99703_HWEN_DELAY_US		3500
+
+#define AW99703_ID_REG			0x00
+#define AW99703_SFTRST_REG		0x01
+#define AW99703_MODE_REG		0x02
+#define AW99703_PDIS_MASK		BIT(4)
+#define AW99703_MAP_LINEAR_MASK		BIT(2)
+#define AW99703_WORKMODE_MASK		GENMASK(1, 0)
+#define AW99703_WORKMODE_BACKLIGHT	1
+#define AW99703_LEDCUR_REG		0x03
+#define AW99703_BLFS_MASK		GENMASK(7, 3)
+#define AW99703_CHANNEL_MASK		GENMASK(2, 0)
+#define AW99703_BSTCTR1_REG		0x04
+#define AW99703_SW_FREQ_MASK		BIT(5)
+#define AW99703_OVPSEL_MASK		GENMASK(4, 2)
+#define AW99703_OCPSEL_MASK		GENMASK(1, 0)
+#define AW99703_BSTCTR2_REG		0x05
+#define AW99703_IDCTSEL_MASK		BIT(6)
+#define AW99703_LEDLSB_REG		0x06
+#define AW99703_LEDMSB_REG		0x07
+#define AW99703_AFLOW_REG		0x0D
+#define AW99703_FLAGS2_REG		0x0F
+#define AW99703_FLAGS3_REG		0x11
+#define AW99703_REG_MAX			0x69
+
 #define RESV	U32_MAX
 
 /* Boost switching frequency table, in Hz */
@@ -75,6 +104,20 @@ static const u32 aw99706_ulvo_thres_tbl[] = {
 	2200000, 5000000
 };
 
+/* AW99703 boost switching frequency table, in Hz */
+static const u32 aw99703_sw_freq_tbl[] = { 500000, 1000000 };
+
+/* AW99703 boost over-voltage protection table, in uV (1xx = 41.5 V) */
+static const u32 aw99703_ovp_tbl[] = {
+	17500000, 24000000, 31000000, 38000000, 41500000, RESV, RESV, RESV
+};
+
+/* AW99703 boost over-current protection table, in uA */
+static const u32 aw99703_ocp_tbl[] = { 900000, 1800000, 2700000, 3400000 };
+
+/* AW99703 boost inductor table, in nH */
+static const u32 aw99703_inductor_tbl[] = { 4700, 10000 };
+
 struct aw99706_dt_prop {
 	const char * const name;
 	const char * const legacy_name;
@@ -171,6 +214,48 @@ static const struct aw99706_dt_prop aw99706_dt_props[] = {
 	}
 };
 
+static const struct aw99706_dt_prop aw99703_dt_props[] = {
+	{
+		.name = "awinic,sw-freq-hz",
+		.lookup = aw99706_dt_property_lookup,
+		.lookup_tbl = aw99703_sw_freq_tbl,
+		.tbl_size = ARRAY_SIZE(aw99703_sw_freq_tbl),
+		.reg = AW99703_BSTCTR1_REG, .mask = AW99703_SW_FREQ_MASK,
+		.def_val = 1000000,
+	},
+	{
+		.name = "awinic,ovp-microvolt",
+		.lookup = aw99706_dt_property_lookup,
+		.lookup_tbl = aw99703_ovp_tbl,
+		.tbl_size = ARRAY_SIZE(aw99703_ovp_tbl),
+		.reg = AW99703_BSTCTR1_REG, .mask = AW99703_OVPSEL_MASK,
+		.def_val = 38000000,
+	},
+	{
+		.name = "awinic,ocp-microamp",
+		.lookup = aw99706_dt_property_lookup,
+		.lookup_tbl = aw99703_ocp_tbl,
+		.tbl_size = ARRAY_SIZE(aw99703_ocp_tbl),
+		.reg = AW99703_BSTCTR1_REG, .mask = AW99703_OCPSEL_MASK,
+		.def_val = 2700000,
+	},
+	{
+		.name = "awinic,inductor-nanohenry",
+		.lookup = aw99706_dt_property_lookup,
+		.lookup_tbl = aw99703_inductor_tbl,
+		.tbl_size = ARRAY_SIZE(aw99703_inductor_tbl),
+		.reg = AW99703_BSTCTR2_REG, .mask = AW99703_IDCTSEL_MASK,
+		.def_val = 4700,
+	},
+	{
+		.name = "led-max-microamp",
+		.lookup = aw99706_dt_property_range,
+		.min = 4800, .max = 29600, .step = 800,
+		.reg = AW99703_LEDCUR_REG, .mask = AW99703_BLFS_MASK,
+		.def_val = 20000,
+	},
+};
+
 struct reg_init_data {
 	u8 reg;
 	u8 mask;
@@ -179,14 +264,18 @@ struct reg_init_data {
 
 #define AW99706_MAX_INIT_REGS	8
 
+struct aw99706_device;
+
 struct aw99706_chip_data {
 	const char *bl_name;
+	void (*dt_parse_extra)(struct aw99706_device *aw);
 	const struct regmap_config *regmap_config;
 	const struct aw99706_dt_prop *dt_props;
 	u8 num_dt_props;
 	u8 id_reg;
 	u8 id;
 	u32 max_brightness;
+	unsigned int hwen_delay_us;
 	u8 brt_msb_reg;
 	u8 brt_lsb_reg;
 	u8 brt_lsb_bits;
@@ -311,6 +400,9 @@ static void aw99706_dt_parse(struct aw99706_device *aw,
 				 val << __ffs(prop->mask));
 	}
 
+	if (chip->dt_parse_extra)
+		chip->dt_parse_extra(aw);
+
 	brt = chip->max_brightness >> 1;
 	max_brt = chip->max_brightness;
 	device_property_read_u32(aw->dev, "default-brightness", &brt);
@@ -326,6 +418,38 @@ static void aw99706_dt_parse(struct aw99706_device *aw,
 	bl_props->max_brightness = max_brt;
 }
 
+static void aw99703_dt_parse_extra(struct aw99706_device *aw)
+{
+	u32 sources[3];
+	u8 channels = 0;
+	int count, i;
+
+	count = device_property_count_u32(aw->dev, "led-sources");
+	if (count > 0 && count <= ARRAY_SIZE(sources) &&
+	    !device_property_read_u32_array(aw->dev, "led-sources", sources,
+					    count)) {
+		for (i = 0; i < count; i++) {
+			if (sources[i] > 2) {
+				dev_warn(aw->dev, "invalid led-sources, enabling all strings\n");
+				channels = 0;
+				break;
+			}
+			channels |= BIT(sources[i]);
+		}
+	}
+	if (!channels)
+		channels = AW99703_CHANNEL_MASK;
+
+	aw99706_add_init(aw, AW99703_LEDCUR_REG, AW99703_CHANNEL_MASK, channels);
+
+	aw99706_add_init(aw, AW99703_MODE_REG, AW99703_PDIS_MASK,
+			 device_property_read_bool(aw->dev, "awinic,pwm-input") ?
+			 0 : AW99703_PDIS_MASK);
+
+	aw99706_add_init(aw, AW99703_MODE_REG, AW99703_MAP_LINEAR_MASK,
+			 AW99703_MAP_LINEAR_MASK);
+}
+
 static int aw99706_hw_init(struct aw99706_device *aw)
 {
 	int ret, i;
@@ -410,6 +534,36 @@ static const struct backlight_ops aw99706_bl_ops = {
 	.update_status = aw99706_bl_update_status,
 };
 
+static bool aw99703_readable_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case AW99703_ID_REG:
+	case AW99703_MODE_REG ... AW99703_FLAGS2_REG:
+	case AW99703_FLAGS3_REG:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool aw99703_writeable_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case AW99703_SFTRST_REG ... AW99703_AFLOW_REG:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static const struct regmap_config aw99703_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = AW99703_REG_MAX,
+	.writeable_reg = aw99703_writeable_reg,
+	.readable_reg = aw99703_readable_reg,
+};
+
 static const struct regmap_config aw99706_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -436,6 +590,7 @@ static int aw99706_probe(struct i2c_client *client)
 	struct aw99706_device *aw;
 	struct backlight_device *bl_dev;
 	struct backlight_properties props = {};
+	const char *name;
 	int ret = 0;
 
 	aw = devm_kzalloc_obj(dev, *aw);
@@ -456,12 +611,19 @@ static int aw99706_probe(struct i2c_client *client)
 
 	aw99706_dt_parse(aw, &props);
 
-	aw->hwen_gpio = devm_gpiod_get(aw->dev, "enable", GPIOD_OUT_LOW);
+	ret = devm_regulator_get_enable_optional(dev, "vin");
+	if (ret < 0 && ret != -ENODEV)
+		return dev_err_probe(dev, ret, "Failed to enable vin supply\n");
+
+	aw->hwen_gpio = devm_gpiod_get_optional(aw->dev, "enable",
+						GPIOD_OUT_LOW);
 	if (IS_ERR(aw->hwen_gpio))
 		return dev_err_probe(dev, PTR_ERR(aw->hwen_gpio),
 				     "Failed to get enable gpio\n");
 
 	gpiod_set_value_cansleep(aw->hwen_gpio, 1);
+	if (aw->hwen_gpio && aw->chip->hwen_delay_us)
+		fsleep(aw->chip->hwen_delay_us);
 
 	ret = aw99706_chip_id_read(aw);
 	if (ret != aw->chip->id) {
@@ -479,7 +641,10 @@ static int aw99706_probe(struct i2c_client *client)
 	props.type = BACKLIGHT_RAW;
 	props.scale = BACKLIGHT_SCALE_LINEAR;
 
-	bl_dev = devm_backlight_device_register(dev, aw->chip->bl_name, dev,
+	if (device_property_read_string(dev, "label", &name))
+		name = aw->chip->bl_name;
+
+	bl_dev = devm_backlight_device_register(dev, name, dev,
 						aw, &aw99706_bl_ops, &props);
 	if (IS_ERR(bl_dev)) {
 		ret = dev_err_probe(dev, PTR_ERR(bl_dev),
@@ -539,13 +704,34 @@ static const struct aw99706_chip_data aw99706_chip = {
 	.en_val = AW99706_BACKLIGHT_EN_MASK,
 };
 
+static const struct aw99706_chip_data aw99703_chip = {
+	.bl_name = "aw99703-backlight",
+	.dt_parse_extra = aw99703_dt_parse_extra,
+	.regmap_config = &aw99703_regmap_config,
+	.dt_props = aw99703_dt_props,
+	.num_dt_props = ARRAY_SIZE(aw99703_dt_props),
+	.id_reg = AW99703_ID_REG,
+	.id = AW99703_ID,
+	.max_brightness = AW99703_MAX_BRT_LVL,
+	.hwen_delay_us = AW99703_HWEN_DELAY_US,
+	.brt_msb_reg = AW99703_LEDMSB_REG,
+	.brt_lsb_reg = AW99703_LEDLSB_REG,
+	.brt_lsb_bits = 3,
+	.brt_lsb_first = true,
+	.en_reg = AW99703_MODE_REG,
+	.en_mask = AW99703_WORKMODE_MASK,
+	.en_val = AW99703_WORKMODE_BACKLIGHT,
+};
+
 static const struct i2c_device_id aw99706_ids[] = {
+	{ .name = "aw99703", .driver_data = (kernel_ulong_t)&aw99703_chip },
 	{ .name = "aw99706", .driver_data = (kernel_ulong_t)&aw99706_chip },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, aw99706_ids);
 
 static const struct of_device_id aw99706_match_table[] = {
+	{ .compatible = "awinic,aw99703", .data = &aw99703_chip },
 	{ .compatible = "awinic,aw99706", .data = &aw99706_chip },
 	{ }
 };
@@ -565,4 +751,4 @@ static struct i2c_driver aw99706_i2c_driver = {
 module_i2c_driver(aw99706_i2c_driver);
 
 MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("BackLight driver for aw99706");
+MODULE_DESCRIPTION("BackLight driver for aw99706 and aw99703");
-- 
2.55.0


      parent reply	other threads:[~2026-12-05  0:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  0:51 [PATCH v2 0/6] backlight: aw99706: Add Awinic AW99703 support Luka Panio
2026-12-05  0:51 ` [PATCH v2 1/6] dt-bindings: leds: backlight: aw99706: Use standard led-max-microamp Luka Panio
2026-12-05  0:51 ` [PATCH v2 2/6] dt-bindings: leds: backlight: Add Awinic AW99703 backlight Luka Panio
2026-12-05  0:51 ` [PATCH v2 3/6] backlight: aw99706: Enable the chip before reading its ID Luka Panio
2026-12-05  0:51 ` [PATCH v2 4/6] backlight: aw99706: Introduce per-chip data Luka Panio
2026-12-05  0:51 ` [PATCH v2 5/6] backlight: aw99706: Support the led-max-microamp property Luka Panio
2026-12-05  0:51 ` Luka Panio [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=20261205005118.884885-7-lukapanio@gmail.com \
    --to=lukapanio@gmail.com \
    --cc=andreas@kemnade.info \
    --cc=conor+dt@kernel.org \
    --cc=danielt@kernel.org \
    --cc=deller@gmx.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=griffin@kroah.com \
    --cc=jingoohan1@gmail.com \
    --cc=junjie.cao@linux.dev \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mitltlatltl@gmail.com \
    --cc=pavel@kernel.org \
    --cc=robh@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