diff mbox series

drm/i915/dsi: Retrieve max brightness level from VBT

Message ID 20210824140042.3083-1-shawn.c.lee@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/dsi: Retrieve max brightness level from VBT | expand

Commit Message

Lee, Shawn C Aug. 24, 2021, 2 p.m. UTC
So far, DCS backlight driver hardcode (0xFF) for max brightness level.
MIPI DCS spec allow max 0xFFFF for set_display_brightness (51h) command.
And VBT brightness precision bits can support 8 ~ 16 bits.

We should set correct precision bits in VBT that meet panel's request.
Driver can refer to this setting then configure max brightness level
in DCS backlight driver properly.

v2: modify variable name brightness_precision_bits instead of
    max_brightness_level.

Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Vandita Kulkarni <vandita.kulkarni@intel.com>
Cc: Cooper Chiou <cooper.chiou@intel.com>
Cc: William Tseng <william.tseng@intel.com>
Signed-off-by: Lee Shawn C <shawn.c.lee@intel.com>
---
 drivers/gpu/drm/i915/display/intel_bios.c              | 3 +++
 drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c | 8 ++++++--
 drivers/gpu/drm/i915/i915_drv.h                        | 1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

Comments

Jani Nikula Aug. 24, 2021, 2:33 p.m. UTC | #1
On Tue, 24 Aug 2021, Lee Shawn C <shawn.c.lee@intel.com> wrote:
> So far, DCS backlight driver hardcode (0xFF) for max brightness level.
> MIPI DCS spec allow max 0xFFFF for set_display_brightness (51h) command.
> And VBT brightness precision bits can support 8 ~ 16 bits.
>
> We should set correct precision bits in VBT that meet panel's request.
> Driver can refer to this setting then configure max brightness level
> in DCS backlight driver properly.
>
> v2: modify variable name brightness_precision_bits instead of
>     max_brightness_level.
>
> Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Vandita Kulkarni <vandita.kulkarni@intel.com>
> Cc: Cooper Chiou <cooper.chiou@intel.com>
> Cc: William Tseng <william.tseng@intel.com>
> Signed-off-by: Lee Shawn C <shawn.c.lee@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_bios.c              | 3 +++
>  drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c | 8 ++++++--
>  drivers/gpu/drm/i915/i915_drv.h                        | 1 +
>  3 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index e86e6ed2d3bf..ccaf0a3100f7 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -483,6 +483,9 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>  			level = 255;
>  		}
>  		i915->vbt.backlight.min_brightness = min_level;
> +
> +		i915->vbt.backlight.brightness_precision_bits =
> +			backlight_data->brightness_precision_bits[panel_type];
>  	} else {
>  		level = backlight_data->level[panel_type];
>  		i915->vbt.backlight.min_brightness = entry->min_brightness;
> diff --git a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
> index 584c14c4cbd0..21ab9e1acb57 100644
> --- a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
> @@ -147,10 +147,14 @@ static void dcs_enable_backlight(const struct intel_crtc_state *crtc_state,
>  static int dcs_setup_backlight(struct intel_connector *connector,
>  			       enum pipe unused)
>  {
> +	struct drm_device *dev = connector->base.dev;
> +	struct drm_i915_private *dev_priv = to_i915(dev);
>  	struct intel_panel *panel = &connector->panel;
>  
> -	panel->backlight.max = PANEL_PWM_MAX_VALUE;
> -	panel->backlight.level = PANEL_PWM_MAX_VALUE;
> +	panel->backlight.max = (dev_priv->vbt.backlight.brightness_precision_bits > 8) \
> +			       ? (1 << dev_priv->vbt.backlight.brightness_precision_bits) - 1 \
> +			       : PANEL_PWM_MAX_VALUE;
> +	panel->backlight.level = panel->backlight.max;

If the precision is < 8, why would max be 0xff? Use GENMASK() perhaps?

BR,
Jani.


>  
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 005b1cec7007..1b42e39a7cd4 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -706,6 +706,7 @@ struct intel_vbt_data {
>  
>  	struct {
>  		u16 pwm_freq_hz;
> +		u16 brightness_precision_bits;
>  		bool present;
>  		bool active_low_pwm;
>  		u8 min_brightness;	/* min_brightness/255 of max */
Lee, Shawn C Aug. 24, 2021, 3:53 p.m. UTC | #2
On Tue, 24 Aug 2021, Jani Nikula <jani.nikula@linux.intel.com> wrote:
>On Tue, 24 Aug 2021, Lee Shawn C <shawn.c.lee@intel.com> wrote:
>> So far, DCS backlight driver hardcode (0xFF) for max brightness level.
>> MIPI DCS spec allow max 0xFFFF for set_display_brightness (51h) command.
>> And VBT brightness precision bits can support 8 ~ 16 bits.
>>
>> We should set correct precision bits in VBT that meet panel's request.
>> Driver can refer to this setting then configure max brightness level 
>> in DCS backlight driver properly.
>>
>> v2: modify variable name brightness_precision_bits instead of
>>     max_brightness_level.
>>
>> Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
>> Cc: Jani Nikula <jani.nikula@linux.intel.com>
>> Cc: Vandita Kulkarni <vandita.kulkarni@intel.com>
>> Cc: Cooper Chiou <cooper.chiou@intel.com>
>> Cc: William Tseng <william.tseng@intel.com>
>> Signed-off-by: Lee Shawn C <shawn.c.lee@intel.com>
>> ---
>>  drivers/gpu/drm/i915/display/intel_bios.c              | 3 +++
>>  drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c | 8 ++++++--
>>  drivers/gpu/drm/i915/i915_drv.h                        | 1 +
>>  3 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c 
>> b/drivers/gpu/drm/i915/display/intel_bios.c
>> index e86e6ed2d3bf..ccaf0a3100f7 100644
>> --- a/drivers/gpu/drm/i915/display/intel_bios.c
>> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
>> @@ -483,6 +483,9 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>>  			level = 255;
>>  		}
>>  		i915->vbt.backlight.min_brightness = min_level;
>> +
>> +		i915->vbt.backlight.brightness_precision_bits =
>> +			backlight_data->brightness_precision_bits[panel_type];
>>  	} else {
>>  		level = backlight_data->level[panel_type];
>>  		i915->vbt.backlight.min_brightness = entry->min_brightness; diff 
>> --git a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c 
>> b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
>> index 584c14c4cbd0..21ab9e1acb57 100644
>> --- a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
>> +++ b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
>> @@ -147,10 +147,14 @@ static void dcs_enable_backlight(const struct 
>> intel_crtc_state *crtc_state,  static int dcs_setup_backlight(struct intel_connector *connector,
>>  			       enum pipe unused)
>>  {
>> +	struct drm_device *dev = connector->base.dev;
>> +	struct drm_i915_private *dev_priv = to_i915(dev);
>>  	struct intel_panel *panel = &connector->panel;
>>  
>> -	panel->backlight.max = PANEL_PWM_MAX_VALUE;
>> -	panel->backlight.level = PANEL_PWM_MAX_VALUE;
>> +	panel->backlight.max = (dev_priv->vbt.backlight.brightness_precision_bits > 8) \
>> +			       ? (1 << dev_priv->vbt.backlight.brightness_precision_bits) - 1 \
>> +			       : PANEL_PWM_MAX_VALUE;
>> +	panel->backlight.level = panel->backlight.max;
>
>If the precision is < 8, why would max be 0xff? Use GENMASK() perhaps?
>
>BR,
>Jani.
>

On vbt structure version 234 and later, vbt support brightness_precision_bits for MIPI display.
And its value will be 8~16 that defined in bpsec #20149.

If vbt version before 234 without this parameter, vbt.backlight.brightness_precision_bits will be "0".
Driver don't know panel required 8 bits or more bits for brightness control. So assign PANEL_PWM_MAX_VALUE
(0xFF) to backlight.max. And driver assign the same value when precision_bits is "8" (support max level 255). 

Best regards,
Shawn

>
>>  
>>  	return 0;
>>  }
>> diff --git a/drivers/gpu/drm/i915/i915_drv.h 
>> b/drivers/gpu/drm/i915/i915_drv.h index 005b1cec7007..1b42e39a7cd4 
>> 100644
>> --- a/drivers/gpu/drm/i915/i915_drv.h
>> +++ b/drivers/gpu/drm/i915/i915_drv.h
>> @@ -706,6 +706,7 @@ struct intel_vbt_data {
>>  
>>  	struct {
>>  		u16 pwm_freq_hz;
>> +		u16 brightness_precision_bits;
>>  		bool present;
>>  		bool active_low_pwm;
>>  		u8 min_brightness;	/* min_brightness/255 of max */
>
>--
>Jani Nikula, Intel Open Source Graphics Center
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
index e86e6ed2d3bf..ccaf0a3100f7 100644
--- a/drivers/gpu/drm/i915/display/intel_bios.c
+++ b/drivers/gpu/drm/i915/display/intel_bios.c
@@ -483,6 +483,9 @@  parse_lfp_backlight(struct drm_i915_private *i915,
 			level = 255;
 		}
 		i915->vbt.backlight.min_brightness = min_level;
+
+		i915->vbt.backlight.brightness_precision_bits =
+			backlight_data->brightness_precision_bits[panel_type];
 	} else {
 		level = backlight_data->level[panel_type];
 		i915->vbt.backlight.min_brightness = entry->min_brightness;
diff --git a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
index 584c14c4cbd0..21ab9e1acb57 100644
--- a/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
+++ b/drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
@@ -147,10 +147,14 @@  static void dcs_enable_backlight(const struct intel_crtc_state *crtc_state,
 static int dcs_setup_backlight(struct intel_connector *connector,
 			       enum pipe unused)
 {
+	struct drm_device *dev = connector->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct intel_panel *panel = &connector->panel;
 
-	panel->backlight.max = PANEL_PWM_MAX_VALUE;
-	panel->backlight.level = PANEL_PWM_MAX_VALUE;
+	panel->backlight.max = (dev_priv->vbt.backlight.brightness_precision_bits > 8) \
+			       ? (1 << dev_priv->vbt.backlight.brightness_precision_bits) - 1 \
+			       : PANEL_PWM_MAX_VALUE;
+	panel->backlight.level = panel->backlight.max;
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 005b1cec7007..1b42e39a7cd4 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -706,6 +706,7 @@  struct intel_vbt_data {
 
 	struct {
 		u16 pwm_freq_hz;
+		u16 brightness_precision_bits;
 		bool present;
 		bool active_low_pwm;
 		u8 min_brightness;	/* min_brightness/255 of max */