Skip to content

Commit 8b0bce0

Browse files
ChiYuan HuangLee Jones
authored andcommitted
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 <[email protected]> Signed-off-by: ChiYuan Huang <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 27e5c65 commit 8b0bce0

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

drivers/video/backlight/rt4831-backlight.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define RT4831_REG_BLCFG 0x02
1313
#define RT4831_REG_BLDIML 0x04
1414
#define RT4831_REG_ENABLE 0x08
15+
#define RT4831_REG_BLOPT2 0x11
1516

1617
#define RT4831_BLMAX_BRIGHTNESS 2048
1718

@@ -23,6 +24,11 @@
2324
#define RT4831_BLDIML_MASK GENMASK(2, 0)
2425
#define RT4831_BLDIMH_MASK GENMASK(10, 3)
2526
#define RT4831_BLDIMH_SHIFT 3
27+
#define RT4831_BLOCP_MASK GENMASK(1, 0)
28+
29+
#define RT4831_BLOCP_MINUA 900000
30+
#define RT4831_BLOCP_MAXUA 1800000
31+
#define RT4831_BLOCP_STEPUA 300000
2632

2733
struct rt4831_priv {
2834
struct device *dev;
@@ -85,7 +91,7 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv,
8591
{
8692
struct device *dev = priv->dev;
8793
u8 propval;
88-
u32 brightness;
94+
u32 brightness, ocp_uA;
8995
unsigned int val = 0;
9096
int ret;
9197

@@ -120,6 +126,31 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv,
120126
if (ret)
121127
return ret;
122128

129+
/*
130+
* This OCP level is used to protect and limit the inductor current.
131+
* If inductor peak current reach the level, low-side MOSFET will be
132+
* turned off. Meanwhile, the output channel current may be limited.
133+
* To match the configured channel current, the inductor chosen must
134+
* be higher than the OCP level.
135+
*
136+
* Not like the OVP level, the default 21V can be used in the most
137+
* application. But if the chosen OCP level is smaller than needed,
138+
* it will also affect the backlight channel output current to be
139+
* smaller than the register setting.
140+
*/
141+
ret = device_property_read_u32(dev, "richtek,bled-ocp-microamp",
142+
&ocp_uA);
143+
if (!ret) {
144+
ocp_uA = clamp_val(ocp_uA, RT4831_BLOCP_MINUA,
145+
RT4831_BLOCP_MAXUA);
146+
val = DIV_ROUND_UP(ocp_uA - RT4831_BLOCP_MINUA,
147+
RT4831_BLOCP_STEPUA);
148+
ret = regmap_update_bits(priv->regmap, RT4831_REG_BLOPT2,
149+
RT4831_BLOCP_MASK, val);
150+
if (ret)
151+
return ret;
152+
}
153+
123154
ret = device_property_read_u8(dev, "richtek,channel-use", &propval);
124155
if (ret) {
125156
dev_err(dev, "richtek,channel-use DT property missing\n");

0 commit comments

Comments
 (0)