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

backlight: rt4831: Apply ocp level from devicetree

Add 'richtek,bled-ocp-microamp' property parsing in
device_property_init function.

This value may configure prior to the kernel driver. If it's not specified in
devicetree, keep the original setting. Else, use clamp to align the
value in min/max range and also roundup to choose the best selector.

Reported-by: Lucas Tsai <lucas_tsai@richtek.com>
Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/1655807788-24511-3-git-send-email-u0084500@gmail.com

authored by

ChiYuan Huang and committed by
Lee Jones
8b0bce05 27e5c654

+32 -1
+32 -1
drivers/video/backlight/rt4831-backlight.c
··· 12 12 #define RT4831_REG_BLCFG 0x02 13 13 #define RT4831_REG_BLDIML 0x04 14 14 #define RT4831_REG_ENABLE 0x08 15 + #define RT4831_REG_BLOPT2 0x11 15 16 16 17 #define RT4831_BLMAX_BRIGHTNESS 2048 17 18 ··· 24 23 #define RT4831_BLDIML_MASK GENMASK(2, 0) 25 24 #define RT4831_BLDIMH_MASK GENMASK(10, 3) 26 25 #define RT4831_BLDIMH_SHIFT 3 26 + #define RT4831_BLOCP_MASK GENMASK(1, 0) 27 + 28 + #define RT4831_BLOCP_MINUA 900000 29 + #define RT4831_BLOCP_MAXUA 1800000 30 + #define RT4831_BLOCP_STEPUA 300000 27 31 28 32 struct rt4831_priv { 29 33 struct device *dev; ··· 91 85 { 92 86 struct device *dev = priv->dev; 93 87 u8 propval; 94 - u32 brightness; 88 + u32 brightness, ocp_uA; 95 89 unsigned int val = 0; 96 90 int ret; 97 91 ··· 125 119 propval << RT4831_BLOVP_SHIFT); 126 120 if (ret) 127 121 return ret; 122 + 123 + /* 124 + * This OCP level is used to protect and limit the inductor current. 125 + * If inductor peak current reach the level, low-side MOSFET will be 126 + * turned off. Meanwhile, the output channel current may be limited. 127 + * To match the configured channel current, the inductor chosen must 128 + * be higher than the OCP level. 129 + * 130 + * Not like the OVP level, the default 21V can be used in the most 131 + * application. But if the chosen OCP level is smaller than needed, 132 + * it will also affect the backlight channel output current to be 133 + * smaller than the register setting. 134 + */ 135 + ret = device_property_read_u32(dev, "richtek,bled-ocp-microamp", 136 + &ocp_uA); 137 + if (!ret) { 138 + ocp_uA = clamp_val(ocp_uA, RT4831_BLOCP_MINUA, 139 + RT4831_BLOCP_MAXUA); 140 + val = DIV_ROUND_UP(ocp_uA - RT4831_BLOCP_MINUA, 141 + RT4831_BLOCP_STEPUA); 142 + ret = regmap_update_bits(priv->regmap, RT4831_REG_BLOPT2, 143 + RT4831_BLOCP_MASK, val); 144 + if (ret) 145 + return ret; 146 + } 128 147 129 148 ret = device_property_read_u8(dev, "richtek,channel-use", &propval); 130 149 if (ret) {