[PATCH v1 1/3] video: backlight: lm3533: add more flexibility with device tree
Svyatoslav Ryhel
clamor95 at gmail.com
Wed Mar 12 19:20:12 CET 2025
Configure LM3533 based on preliminary device tree configuration.
Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
---
drivers/video/lm3533_backlight.c | 65 +++++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 6 deletions(-)
diff --git a/drivers/video/lm3533_backlight.c b/drivers/video/lm3533_backlight.c
index 6b51fa0628e..a1a7397cbdc 100644
--- a/drivers/video/lm3533_backlight.c
+++ b/drivers/video/lm3533_backlight.c
@@ -7,6 +7,7 @@
#include <backlight.h>
#include <dm.h>
+#include <dm/ofnode.h>
#include <i2c.h>
#include <log.h>
#include <linux/delay.h>
@@ -24,9 +25,23 @@
#define LM3533_OVP_FREQUENCY_PWM_POLARITY 0x2C
#define LM3533_BRIGHTNESS_REGISTER_A 0x40
+#define LM3533_BOOST_OVP_16V 16000000UL
+#define LM3533_BOOST_FREQ_500KHZ 500000UL
+
struct lm3533_backlight_priv {
struct gpio_desc enable_gpio;
u32 def_bl_lvl;
+
+ /* Core */
+ u32 boost_ovp;
+ u32 boost_freq;
+
+ /* Backlight */
+ u32 reg;
+ u16 max_current; /* 5000 - 29800 uA (800 uA step) */
+ u8 pwm; /* 0 - 0x3f */
+ bool linear;
+ bool hvled;
};
static int lm3533_backlight_enable(struct udevice *dev)
@@ -92,14 +107,12 @@ static int lm3533_backlight_set_brightness(struct udevice *dev, int percent)
return 0;
}
-static int lm3533_backlight_probe(struct udevice *dev)
+static int lm3533_backlight_of_to_plat(struct udevice *dev)
{
struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+ ofnode child;
int ret;
- if (device_get_uclass_id(dev->parent) != UCLASS_I2C)
- return -EPROTONOSUPPORT;
-
ret = gpio_request_by_name(dev, "enable-gpios", 0,
&priv->enable_gpio, GPIOD_IS_OUT);
if (ret) {
@@ -107,8 +120,47 @@ static int lm3533_backlight_probe(struct udevice *dev)
return ret;
}
- priv->def_bl_lvl = dev_read_u32_default(dev, "default-brightness-level",
- LM3533_BL_MAX_BRIGHTNESS);
+ priv->boost_ovp = dev_read_u32_default(dev, "ti,boost-ovp-microvolt",
+ LM3533_BOOST_OVP_16V);
+
+ /* boost_ovp is defined in microvolts, convert to enum value */
+ priv->boost_ovp = priv->boost_ovp / (8 * 1000 * 1000) - 2;
+
+ priv->boost_freq = dev_read_u32_default(dev, "ti,boost-freq-hz",
+ LM3533_BOOST_FREQ_500KHZ);
+
+ /* boost_freq is defined in Hz, convert to enum value */
+ priv->boost_freq = priv->boost_freq / (500 * 1000) - 1;
+
+ /* Backlight is one of children but has no dedicated driver */
+ ofnode_for_each_subnode(child, dev_ofnode(dev)) {
+ if (ofnode_device_is_compatible(child, "ti,lm3533-backlight")) {
+ const char *node_name = ofnode_get_name(child);
+
+ if (!strcmp(&node_name[10], "1"))
+ priv->reg = 1;
+ else
+ priv->reg = 0;
+
+ priv->max_current = ofnode_read_u32_default(child, "ti,max-current-microamp",
+ 5000);
+ priv->pwm = ofnode_read_u32_default(child, "ti,pwm-config-mask", 0);
+
+ priv->def_bl_lvl = ofnode_read_u32_default(child, "default-brightness",
+ LM3533_BL_MAX_BRIGHTNESS);
+
+ priv->linear = ofnode_read_bool(child, "ti,linear-mapping-mode");
+ priv->hvled = ofnode_read_bool(child, "ti,hardware-controlled");
+ }
+ }
+
+ return 0;
+}
+
+static int lm3533_backlight_probe(struct udevice *dev)
+{
+ if (device_get_uclass_id(dev->parent) != UCLASS_I2C)
+ return -EPROTONOSUPPORT;
return 0;
}
@@ -127,6 +179,7 @@ U_BOOT_DRIVER(lm3533_backlight) = {
.name = "lm3533_backlight",
.id = UCLASS_PANEL_BACKLIGHT,
.of_match = lm3533_backlight_ids,
+ .of_to_plat = lm3533_backlight_of_to_plat,
.probe = lm3533_backlight_probe,
.ops = &lm3533_backlight_ops,
.priv_auto = sizeof(struct lm3533_backlight_priv),
--
2.43.0
More information about the U-Boot
mailing list