[PATCH v3 14/14] video: backlight: mt6370: Add Mediatek MT6370 support

Daniel Thompson daniel.thompson at linaro.org
Thu Jun 23 06:43:16 PDT 2022


On Thu, Jun 23, 2022 at 07:56:31PM +0800, ChiaEn Wu wrote:
> From: ChiaEn Wu <chiaen_wu at richtek.com>
> 
> Add Mediatek MT6370 Backlight support.
> 
> Signed-off-by: ChiaEn Wu <chiaen_wu at richtek.com>

> diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
> index a003e02..7cd823d 100644
> <snip>
> +static int mt6370_init_backlight_properties(struct mt6370_priv *priv,
> +					    struct backlight_properties *props)
> +{
> +	struct device *dev = priv->dev;
> +	u8 prop_val;
> +	u32 brightness, ovp_uV, ocp_uA;
> +	unsigned int mask, val;
> +	int ret;
> +
> +	/* Vendor optional properties */
> +	val = 0;
> +	if (device_property_read_bool(dev, "mediatek,bled-pwm-enable"))
> +		val |= MT6370_BL_PWM_EN_MASK;
> +
> +	if (device_property_read_bool(dev, "mediatek,bled-pwm-hys-enable"))
> +		val |= MT6370_BL_PWM_HYS_EN_MASK;
> +
> +	ret = device_property_read_u8(dev,
> +				      "mediatek,bled-pwm-hys-input-th-steps",
> +				      &prop_val);
> +	if (!ret) {
> +		prop_val = clamp_val(prop_val,
> +				     MT6370_BL_PWM_HYS_TH_MIN_STEP,
> +				     MT6370_BL_PWM_HYS_TH_MAX_STEP);
> +		/*
> +		 * prop_val =  1      -->  1 steps --> 0x00
> +		 * prop_val =  2 ~  4 -->  4 steps --> 0x01
> +		 * prop_val =  5 ~ 16 --> 16 steps --> 0x10
> +		 * prop_val = 17 ~ 64 --> 64 steps --> 0x11

                                                      ^^^^^
These numbers are binary, not hex, right? If so, the comments
should be 0b00 to 0b03 .


> +		 */
> +		prop_val = (ilog2(roundup_pow_of_two(prop_val)) + 1) >> 1;
> +		val |= prop_val << (ffs(MT6370_BL_PWM_HYS_SEL_MASK) - 1);
> +	}
> +
> +	ret = regmap_update_bits(priv->regmap, MT6370_REG_BL_PWM,
> +				 val, val);
> +	if (ret)
> +		return ret;

Overall, I like this approach! Easy to read and understand.


> <snip>
> +static int mt6370_bl_probe(struct platform_device *pdev)
> +{
> +	struct mt6370_priv *priv;
> +	struct backlight_properties props = {
> +		.type = BACKLIGHT_RAW,
> +		.scale = BACKLIGHT_SCALE_LINEAR,

Sorry, I missed this before but the KConfig comment says that the
backlight can support both linear and exponential curves.

Is there a good reason to default to linear?


Daniel.
> 



More information about the linux-arm-kernel mailing list