Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: lp55xx: Configure internal charge pump

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

authored by

Maarten Zanders and committed by
Lee Jones
54a7bef5 91e47d40

+31 -14
+5 -6
drivers/leds/leds-lp5521.c
··· 58 58 /* CONFIG register */ 59 59 #define LP5521_PWM_HF 0x40 /* PWM: 0 = 256Hz, 1 = 558Hz */ 60 60 #define LP5521_PWRSAVE_EN 0x20 /* 1 = Power save mode */ 61 - #define LP5521_CP_MODE_OFF 0 /* Charge pump (CP) off */ 62 - #define LP5521_CP_MODE_BYPASS 8 /* CP forced to bypass mode */ 63 - #define LP5521_CP_MODE_1X5 0x10 /* CP forced to 1.5x mode */ 64 - #define LP5521_CP_MODE_AUTO 0x18 /* Automatic mode selection */ 61 + #define LP5521_CP_MODE_MASK 0x18 /* Charge pump mode */ 62 + #define LP5521_CP_MODE_SHIFT 3 65 63 #define LP5521_R_TO_BATT 0x04 /* R out: 0 = CP, 1 = Vbat */ 66 64 #define LP5521_CLK_INT 0x01 /* Internal clock */ 67 - #define LP5521_DEFAULT_CFG \ 68 - (LP5521_PWM_HF | LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO) 65 + #define LP5521_DEFAULT_CFG (LP5521_PWM_HF | LP5521_PWRSAVE_EN) 69 66 70 67 /* Status */ 71 68 #define LP5521_EXT_CLK_USED 0x08 ··· 306 309 val = LP5521_DEFAULT_CFG; 307 310 if (!lp55xx_is_extclk_used(chip)) 308 311 val |= LP5521_CLK_INT; 312 + 313 + val |= (chip->pdata->charge_pump_mode << LP5521_CP_MODE_SHIFT) & LP5521_CP_MODE_MASK; 309 314 310 315 ret = lp55xx_write(chip, LP5521_REG_CONFIG, val); 311 316 if (ret)
+9 -5
drivers/leds/leds-lp5523.c
··· 57 57 #define LP5523_AUTO_INC 0x40 58 58 #define LP5523_PWR_SAVE 0x20 59 59 #define LP5523_PWM_PWR_SAVE 0x04 60 - #define LP5523_CP_AUTO 0x18 60 + #define LP5523_CP_MODE_MASK 0x18 61 + #define LP5523_CP_MODE_SHIFT 3 61 62 #define LP5523_AUTO_CLK 0x02 63 + #define LP5523_DEFAULT_CONFIG \ 64 + (LP5523_AUTO_INC | LP5523_PWR_SAVE | LP5523_AUTO_CLK | LP5523_PWM_PWR_SAVE) 62 65 63 66 #define LP5523_EN_LEDTEST 0x80 64 67 #define LP5523_LEDTEST_DONE 0x80 ··· 128 125 static int lp5523_post_init_device(struct lp55xx_chip *chip) 129 126 { 130 127 int ret; 128 + int val; 131 129 132 130 ret = lp55xx_write(chip, LP5523_REG_ENABLE, LP5523_ENABLE); 133 131 if (ret) ··· 137 133 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ 138 134 usleep_range(1000, 2000); 139 135 140 - ret = lp55xx_write(chip, LP5523_REG_CONFIG, 141 - LP5523_AUTO_INC | LP5523_PWR_SAVE | 142 - LP5523_CP_AUTO | LP5523_AUTO_CLK | 143 - LP5523_PWM_PWR_SAVE); 136 + val = LP5523_DEFAULT_CONFIG; 137 + val |= (chip->pdata->charge_pump_mode << LP5523_CP_MODE_SHIFT) & LP5523_CP_MODE_MASK; 138 + 139 + ret = lp55xx_write(chip, LP5523_REG_CONFIG, val); 144 140 if (ret) 145 141 return ret; 146 142
+9
drivers/leds/leds-lp55xx-common.c
··· 18 18 #include <linux/platform_data/leds-lp55xx.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/gpio/consumer.h> 21 + #include <dt-bindings/leds/leds-lp55xx.h> 21 22 22 23 #include "leds-lp55xx-common.h" 23 24 ··· 690 689 return ERR_PTR(-EINVAL); 691 690 } 692 691 i++; 692 + } 693 + 694 + if (of_property_read_u32(np, "ti,charge-pump-mode", &pdata->charge_pump_mode)) 695 + pdata->charge_pump_mode = LP55XX_CP_AUTO; 696 + 697 + if (pdata->charge_pump_mode > LP55XX_CP_AUTO) { 698 + dev_err(dev, "invalid charge pump mode %d\n", pdata->charge_pump_mode); 699 + return ERR_PTR(-EINVAL); 693 700 } 694 701 695 702 of_property_read_string(np, "label", &pdata->label);
+5 -3
drivers/leds/leds-lp8501.c
··· 53 53 #define LP8501_PWM_PSAVE BIT(7) 54 54 #define LP8501_AUTO_INC BIT(6) 55 55 #define LP8501_PWR_SAVE BIT(5) 56 - #define LP8501_CP_AUTO 0x18 56 + #define LP8501_CP_MODE_MASK 0x18 57 + #define LP8501_CP_MODE_SHIFT 3 57 58 #define LP8501_INT_CLK BIT(0) 58 - #define LP8501_DEFAULT_CFG \ 59 - (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE | LP8501_CP_AUTO) 59 + #define LP8501_DEFAULT_CFG (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE) 60 60 61 61 #define LP8501_REG_RESET 0x3D 62 62 #define LP8501_RESET 0xFF ··· 101 101 102 102 if (chip->pdata->clock_mode != LP55XX_CLOCK_EXT) 103 103 val |= LP8501_INT_CLK; 104 + 105 + val |= (chip->pdata->charge_pump_mode << LP8501_CP_MODE_SHIFT) & LP8501_CP_MODE_MASK; 104 106 105 107 ret = lp55xx_write(chip, LP8501_REG_CONFIG, val); 106 108 if (ret)
+3
include/linux/platform_data/leds-lp55xx.h
··· 73 73 /* Clock configuration */ 74 74 u8 clock_mode; 75 75 76 + /* Charge pump mode */ 77 + u32 charge_pump_mode; 78 + 76 79 /* optional enable GPIO */ 77 80 struct gpio_desc *enable_gpiod; 78 81