]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
video: add lm3533 backlight driver
authorSvyatoslav Ryhel <clamor95@gmail.com>
Tue, 25 Apr 2023 07:51:42 +0000 (10:51 +0300)
committerAnatolij Gustschin <agust@denx.de>
Wed, 26 Apr 2023 05:23:10 +0000 (07:23 +0200)
This is basic lm3533 driver only with bank A and backlight cell
support.

Tested-by: Andreas Westman Dorcsak <hedmoo@yahoo.com> # LG P880 T30
Tested-by: Svyatoslav Ryhel <clamor95@gmail.com> # LG P895 T30
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/video/Kconfig
drivers/video/Makefile
drivers/video/lm3533_backlight.c [new file with mode: 0644]

index 9b7abd4283536158041c59c2ed3c3d5c580ddc2c..2be73d53968828bb400ab04212f24b4f0a5a9331 100644 (file)
@@ -606,6 +606,15 @@ config ATMEL_HLCD
        help
           HLCDC supports video output to an attached LCD panel.
 
+config BACKLIGHT_LM3533
+       bool "Backlight Driver for LM3533"
+       depends on BACKLIGHT
+       select DM_I2C
+       help
+         Say Y to enable the backlight driver for National Semiconductor / TI
+         LM3533 Lighting Power chip. Only Bank A is supported as for now.
+         Supported backlight level range is from 2 to 255 with step of 1.
+
 source "drivers/video/ti/Kconfig"
 
 source "drivers/video/exynos/Kconfig"
index a609e35d22e8bbdb5074536c96a87c9ad387dcf6..0d28effb2d3a87c34c3b88a068b0ed7bbfed50f3 100644 (file)
@@ -28,6 +28,7 @@ obj-$(CONFIG_VIDEO_LOGO) += u_boot_logo.o
 
 endif
 
+obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_backlight.o
 obj-${CONFIG_EXYNOS_FB} += exynos/
 obj-${CONFIG_VIDEO_ROCKCHIP} += rockchip/
 obj-${CONFIG_VIDEO_STM32} += stm32/
diff --git a/drivers/video/lm3533_backlight.c b/drivers/video/lm3533_backlight.c
new file mode 100644 (file)
index 0000000..00297a0
--- /dev/null
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#define LOG_CATEGORY UCLASS_PANEL_BACKLIGHT
+
+#include <backlight.h>
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <log.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <asm/gpio.h>
+
+#define LM3533_BL_MIN_BRIGHTNESS                       0x02
+#define LM3533_BL_MAX_BRIGHTNESS                       0xFF
+
+#define LM3533_SINK_OUTPUT_CONFIG_1                    0x10
+#define LM3533_CONTROL_BANK_A_PWM                      0x14
+#define LM3533_CONTROL_BANK_AB_BRIGHTNESS              0x1A
+#define LM3533_CONTROL_BANK_A_FULLSCALE_CURRENT                0x1F
+#define LM3533_CONTROL_BANK_ENABLE                     0x27
+#define LM3533_OVP_FREQUENCY_PWM_POLARITY              0x2C
+#define LM3533_BRIGHTNESS_REGISTER_A                   0x40
+
+struct lm3533_backlight_priv {
+       struct gpio_desc enable_gpio;
+       u32 def_bl_lvl;
+};
+
+static int lm3533_backlight_enable(struct udevice *dev)
+{
+       struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       dm_gpio_set_value(&priv->enable_gpio, 1);
+       mdelay(5);
+
+       /* HVLED 1 & 2 are controlled by Bank A */
+       ret = dm_i2c_reg_write(dev, LM3533_SINK_OUTPUT_CONFIG_1, 0x00);
+       if (ret)
+               return ret;
+
+       /* PWM input is disabled for CABC */
+       ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_A_PWM, 0x00);
+       if (ret)
+               return ret;
+
+       /* Linear & Control Bank A is configured for register Current control */
+       ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_AB_BRIGHTNESS, 0x02);
+       if (ret)
+               return ret;
+
+       /* Full-Scale Current (20.2mA) */
+       ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_A_FULLSCALE_CURRENT, 0x13);
+       if (ret)
+               return ret;
+
+       /* Control Bank A is enable */
+       ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_ENABLE, 0x01);
+       if (ret)
+               return ret;
+
+       ret = dm_i2c_reg_write(dev, LM3533_OVP_FREQUENCY_PWM_POLARITY, 0x0A);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static int lm3533_backlight_set_brightness(struct udevice *dev, int percent)
+{
+       struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       if (percent == BACKLIGHT_DEFAULT)
+               percent = priv->def_bl_lvl;
+
+       if (percent < LM3533_BL_MIN_BRIGHTNESS)
+               percent = LM3533_BL_MIN_BRIGHTNESS;
+
+       if (percent > LM3533_BL_MAX_BRIGHTNESS)
+               percent = LM3533_BL_MAX_BRIGHTNESS;
+
+       /* Set brightness level */
+       ret = dm_i2c_reg_write(dev, LM3533_BRIGHTNESS_REGISTER_A,
+                              percent);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static int lm3533_backlight_probe(struct udevice *dev)
+{
+       struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+       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) {
+               log_err("Could not decode enable-gpios (%d)\n", ret);
+               return ret;
+       }
+
+       priv->def_bl_lvl = dev_read_u32_default(dev, "default-brightness-level",
+                                               LM3533_BL_MAX_BRIGHTNESS);
+
+       return 0;
+}
+
+static const struct backlight_ops lm3533_backlight_ops = {
+       .enable = lm3533_backlight_enable,
+       .set_brightness = lm3533_backlight_set_brightness,
+};
+
+static const struct udevice_id lm3533_backlight_ids[] = {
+       { .compatible = "ti,lm3533" },
+       { }
+};
+
+U_BOOT_DRIVER(lm3533_backlight) = {
+       .name           = "lm3533_backlight",
+       .id             = UCLASS_PANEL_BACKLIGHT,
+       .of_match       = lm3533_backlight_ids,
+       .probe          = lm3533_backlight_probe,
+       .ops            = &lm3533_backlight_ops,
+       .priv_auto      = sizeof(struct lm3533_backlight_priv),
+};