From: ChiYuan Huang Date: Tue, 21 Jun 2022 10:36:28 +0000 (+0800) Subject: backlight: rt4831: Apply ocp level from devicetree X-Git-Tag: v6.1-rc5~681^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b0bce056351bb9abd06a09cffff1ff0d84ee580;p=platform%2Fkernel%2Flinux-starfive.git 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 Signed-off-by: ChiYuan Huang Reviewed-by: Daniel Thompson Signed-off-by: Lee Jones Link: https://lore.kernel.org/r/1655807788-24511-3-git-send-email-u0084500@gmail.com --- diff --git a/drivers/video/backlight/rt4831-backlight.c b/drivers/video/backlight/rt4831-backlight.c index 42155c7..eb8c59e 100644 --- a/drivers/video/backlight/rt4831-backlight.c +++ b/drivers/video/backlight/rt4831-backlight.c @@ -12,6 +12,7 @@ #define RT4831_REG_BLCFG 0x02 #define RT4831_REG_BLDIML 0x04 #define RT4831_REG_ENABLE 0x08 +#define RT4831_REG_BLOPT2 0x11 #define RT4831_BLMAX_BRIGHTNESS 2048 @@ -23,6 +24,11 @@ #define RT4831_BLDIML_MASK GENMASK(2, 0) #define RT4831_BLDIMH_MASK GENMASK(10, 3) #define RT4831_BLDIMH_SHIFT 3 +#define RT4831_BLOCP_MASK GENMASK(1, 0) + +#define RT4831_BLOCP_MINUA 900000 +#define RT4831_BLOCP_MAXUA 1800000 +#define RT4831_BLOCP_STEPUA 300000 struct rt4831_priv { struct device *dev; @@ -85,7 +91,7 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv, { struct device *dev = priv->dev; u8 propval; - u32 brightness; + u32 brightness, ocp_uA; unsigned int val = 0; int ret; @@ -120,6 +126,31 @@ static int rt4831_parse_backlight_properties(struct rt4831_priv *priv, if (ret) return ret; + /* + * This OCP level is used to protect and limit the inductor current. + * If inductor peak current reach the level, low-side MOSFET will be + * turned off. Meanwhile, the output channel current may be limited. + * To match the configured channel current, the inductor chosen must + * be higher than the OCP level. + * + * Not like the OVP level, the default 21V can be used in the most + * application. But if the chosen OCP level is smaller than needed, + * it will also affect the backlight channel output current to be + * smaller than the register setting. + */ + ret = device_property_read_u32(dev, "richtek,bled-ocp-microamp", + &ocp_uA); + if (!ret) { + ocp_uA = clamp_val(ocp_uA, RT4831_BLOCP_MINUA, + RT4831_BLOCP_MAXUA); + val = DIV_ROUND_UP(ocp_uA - RT4831_BLOCP_MINUA, + RT4831_BLOCP_STEPUA); + ret = regmap_update_bits(priv->regmap, RT4831_REG_BLOPT2, + RT4831_BLOCP_MASK, val); + if (ret) + return ret; + } + ret = device_property_read_u8(dev, "richtek,channel-use", &propval); if (ret) { dev_err(dev, "richtek,channel-use DT property missing\n");