leds: lp55xx: Configure internal charge pump
authorMaarten Zanders <maarten.zanders@mind.be>
Fri, 21 Apr 2023 07:53:05 +0000 (09:53 +0200)
committerLee Jones <lee@kernel.org>
Thu, 25 May 2023 11:16:05 +0000 (12:16 +0100)
The LP55xx range of devices have an internal charge pump which
can (automatically) increase the output voltage towards the
LED's, boosting the output voltage to 4.5V.

Implement this option from the devicetree. When the setting
is not present it will operate in automatic mode as before.

Tested on LP55231. Datasheet analysis shows that LP5521, LP5523
and LP8501 are identical in topology and are modified in the
same way.

Signed-off-by: Maarten Zanders <maarten.zanders@mind.be>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20230421075305.37597-3-maarten.zanders@mind.be
drivers/leds/leds-lp5521.c
drivers/leds/leds-lp5523.c
drivers/leds/leds-lp55xx-common.c
drivers/leds/leds-lp8501.c
include/linux/platform_data/leds-lp55xx.h

index a004af8e22c742396b8a227ccb589c0a75a61a1a..acd37d0f0e26484bde215f1bc601971144edab21 100644 (file)
 /* CONFIG register */
 #define LP5521_PWM_HF                  0x40    /* PWM: 0 = 256Hz, 1 = 558Hz */
 #define LP5521_PWRSAVE_EN              0x20    /* 1 = Power save mode */
-#define LP5521_CP_MODE_OFF             0       /* Charge pump (CP) off */
-#define LP5521_CP_MODE_BYPASS          8       /* CP forced to bypass mode */
-#define LP5521_CP_MODE_1X5             0x10    /* CP forced to 1.5x mode */
-#define LP5521_CP_MODE_AUTO            0x18    /* Automatic mode selection */
+#define LP5521_CP_MODE_MASK            0x18    /* Charge pump mode */
+#define LP5521_CP_MODE_SHIFT           3
 #define LP5521_R_TO_BATT               0x04    /* R out: 0 = CP, 1 = Vbat */
 #define LP5521_CLK_INT                 0x01    /* Internal clock */
-#define LP5521_DEFAULT_CFG             \
-       (LP5521_PWM_HF | LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO)
+#define LP5521_DEFAULT_CFG             (LP5521_PWM_HF | LP5521_PWRSAVE_EN)
 
 /* Status */
 #define LP5521_EXT_CLK_USED            0x08
@@ -310,6 +307,8 @@ static int lp5521_post_init_device(struct lp55xx_chip *chip)
        if (!lp55xx_is_extclk_used(chip))
                val |= LP5521_CLK_INT;
 
+       val |= (chip->pdata->charge_pump_mode << LP5521_CP_MODE_SHIFT) & LP5521_CP_MODE_MASK;
+
        ret = lp55xx_write(chip, LP5521_REG_CONFIG, val);
        if (ret)
                return ret;
index 55da914b8e5cac2931a6789c86538b89c5cfa612..a8df22938bdb6778798a7bb07bbac14277c9271a 100644 (file)
 #define LP5523_AUTO_INC                        0x40
 #define LP5523_PWR_SAVE                        0x20
 #define LP5523_PWM_PWR_SAVE            0x04
-#define LP5523_CP_AUTO                 0x18
+#define LP5523_CP_MODE_MASK            0x18
+#define LP5523_CP_MODE_SHIFT           3
 #define LP5523_AUTO_CLK                        0x02
+#define LP5523_DEFAULT_CONFIG \
+       (LP5523_AUTO_INC | LP5523_PWR_SAVE | LP5523_AUTO_CLK | LP5523_PWM_PWR_SAVE)
 
 #define LP5523_EN_LEDTEST              0x80
 #define LP5523_LEDTEST_DONE            0x80
@@ -125,6 +128,7 @@ static void lp5523_set_led_current(struct lp55xx_led *led, u8 led_current)
 static int lp5523_post_init_device(struct lp55xx_chip *chip)
 {
        int ret;
+       int val;
 
        ret = lp55xx_write(chip, LP5523_REG_ENABLE, LP5523_ENABLE);
        if (ret)
@@ -133,10 +137,10 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip)
        /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
        usleep_range(1000, 2000);
 
-       ret = lp55xx_write(chip, LP5523_REG_CONFIG,
-                           LP5523_AUTO_INC | LP5523_PWR_SAVE |
-                           LP5523_CP_AUTO | LP5523_AUTO_CLK |
-                           LP5523_PWM_PWR_SAVE);
+       val = LP5523_DEFAULT_CONFIG;
+       val |= (chip->pdata->charge_pump_mode << LP5523_CP_MODE_SHIFT) & LP5523_CP_MODE_MASK;
+
+       ret = lp55xx_write(chip, LP5523_REG_CONFIG, val);
        if (ret)
                return ret;
 
index c1940964067af8c09450a87bdc658b542cbdd0f0..77bb26906ea6e43ac1318f38cac8939c057b567d 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/platform_data/leds-lp55xx.h>
 #include <linux/slab.h>
 #include <linux/gpio/consumer.h>
+#include <dt-bindings/leds/leds-lp55xx.h>
 
 #include "leds-lp55xx-common.h"
 
@@ -691,6 +692,14 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
                i++;
        }
 
+       if (of_property_read_u32(np, "ti,charge-pump-mode", &pdata->charge_pump_mode))
+               pdata->charge_pump_mode = LP55XX_CP_AUTO;
+
+       if (pdata->charge_pump_mode > LP55XX_CP_AUTO) {
+               dev_err(dev, "invalid charge pump mode %d\n", pdata->charge_pump_mode);
+               return ERR_PTR(-EINVAL);
+       }
+
        of_property_read_string(np, "label", &pdata->label);
        of_property_read_u8(np, "clock-mode", &pdata->clock_mode);
 
index 165d6423a928d8e8b747aa726fdee96884585d48..878d81dace8a49e66e5ad4b9ba4c84047866bfa7 100644 (file)
 #define LP8501_PWM_PSAVE               BIT(7)
 #define LP8501_AUTO_INC                        BIT(6)
 #define LP8501_PWR_SAVE                        BIT(5)
-#define LP8501_CP_AUTO                 0x18
+#define LP8501_CP_MODE_MASK            0x18
+#define LP8501_CP_MODE_SHIFT           3
 #define LP8501_INT_CLK                 BIT(0)
-#define LP8501_DEFAULT_CFG     \
-       (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE | LP8501_CP_AUTO)
+#define LP8501_DEFAULT_CFG (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE)
 
 #define LP8501_REG_RESET               0x3D
 #define LP8501_RESET                   0xFF
@@ -102,6 +102,8 @@ static int lp8501_post_init_device(struct lp55xx_chip *chip)
        if (chip->pdata->clock_mode != LP55XX_CLOCK_EXT)
                val |= LP8501_INT_CLK;
 
+       val |= (chip->pdata->charge_pump_mode << LP8501_CP_MODE_SHIFT) & LP8501_CP_MODE_MASK;
+
        ret = lp55xx_write(chip, LP8501_REG_CONFIG, val);
        if (ret)
                return ret;
index 3441064713a3f2ae946e90fa24241b75b3936b5b..3cc8db0b12b58b87820df8d020ee7d76c6df2b46 100644 (file)
@@ -73,6 +73,9 @@ struct lp55xx_platform_data {
        /* Clock configuration */
        u8 clock_mode;
 
+       /* Charge pump mode */
+       u32 charge_pump_mode;
+
        /* optional enable GPIO */
        struct gpio_desc *enable_gpiod;