diff mbox series

[3/3] drm/i915: Pick the backlight controller based on VBT on ICP+

Message ID 20230207064337.18697-4-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Fix eDP+DSI dual panel systems | expand

Commit Message

Ville Syrjälä Feb. 7, 2023, 6:43 a.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Use the second backlight controller on ICP+ if the VBT asks
us to do so.

On pre-MTP we also check the chicken bit to make sure the
pins have been correctly muxed by the firmware.

Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8016
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 .../gpu/drm/i915/display/intel_backlight.c    | 34 +++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

Comments

Jani Nikula Feb. 7, 2023, 9:32 a.m. UTC | #1
On Tue, 07 Feb 2023, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Use the second backlight controller on ICP+ if the VBT asks
> us to do so.
>
> On pre-MTP we also check the chicken bit to make sure the
> pins have been correctly muxed by the firmware.
>
> Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8016
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  .../gpu/drm/i915/display/intel_backlight.c    | 34 +++++++++++++++++--
>  1 file changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
> index 5b7da72c95b8..a4e4b7f79e4d 100644
> --- a/drivers/gpu/drm/i915/display/intel_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
> @@ -1431,6 +1431,30 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  	return 0;
>  }
>  
> +static int cnp_num_backlight_controllers(struct drm_i915_private *i915)
> +{
> +	if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
> +		return 1;
> +
> +	if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
> +		return 2;
> +
> +	return 1;
> +}

At some point I think we should clean this up between backlight and
pps. There's already intel_num_pps(). But let's get this merged as-is
now.

> +
> +static bool cnp_backlight_controller_is_valid(struct drm_i915_private *i915, int controller)
> +{
> +	if (controller < 0 || controller >= cnp_num_backlight_controllers(i915))
> +		return false;
> +
> +	if (controller == 1 &&
> +	    INTEL_PCH_TYPE(i915) >= PCH_ICP &&
> +	    INTEL_PCH_TYPE(i915) < PCH_MTP)
> +		return intel_de_read(i915, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;

I got a bit confused that MTP has two controllers but it doesn't have
that bit. I first thought you were off by one with that < PCH_MTP. But
looks like it's correct.

Anyway,

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

> +
> +	return true;
> +}
> +
>  static int
>  cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  {
> @@ -1440,10 +1464,14 @@ cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  
>  	/*
>  	 * CNP has the BXT implementation of backlight, but with only one
> -	 * controller. TODO: ICP has multiple controllers but we only use
> -	 * controller 0 for now.
> +	 * controller. ICP+ can have two controllers, depending on pin muxing.
>  	 */
> -	panel->backlight.controller = 0;
> +	panel->backlight.controller = connector->panel.vbt.backlight.controller;
> +	if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) {
> +		drm_dbg_kms(&i915->drm, "Invalid backlight controller %d, assuming 0\n",
> +			    panel->backlight.controller);
> +		panel->backlight.controller = 0;
> +	}
>  
>  	pwm_ctl = intel_de_read(i915,
>  				BXT_BLC_PWM_CTL(panel->backlight.controller));
Rodrigo Vivi Feb. 8, 2023, 3:23 p.m. UTC | #2
On Tue, Feb 07, 2023 at 08:43:37AM +0200, Ville Syrjala wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Use the second backlight controller on ICP+ if the VBT asks
> us to do so.
> 
> On pre-MTP we also check the chicken bit to make sure the
> pins have been correctly muxed by the firmware.
> 

It looks like CC: stable was added while merging this patch.
But it doesn't go clean. build fails due to s/dev_priv/i915
and also due to the lack of ICP_SECOND_PPS_IO_SELECT that
was added by another patch.

So we need a backported version of this patch to be included
in the stable trees... how far we will go in the stable tree?

At this point of -rc7 I even wonder it will be better to stay
for 6.2 to get released and then send the backported version
to the stable ml directly...

> Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8016
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  .../gpu/drm/i915/display/intel_backlight.c    | 34 +++++++++++++++++--
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
> index 5b7da72c95b8..a4e4b7f79e4d 100644
> --- a/drivers/gpu/drm/i915/display/intel_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
> @@ -1431,6 +1431,30 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  	return 0;
>  }
>  
> +static int cnp_num_backlight_controllers(struct drm_i915_private *i915)
> +{
> +	if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
> +		return 1;
> +
> +	if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
> +		return 2;
> +
> +	return 1;
> +}
> +
> +static bool cnp_backlight_controller_is_valid(struct drm_i915_private *i915, int controller)
> +{
> +	if (controller < 0 || controller >= cnp_num_backlight_controllers(i915))
> +		return false;
> +
> +	if (controller == 1 &&
> +	    INTEL_PCH_TYPE(i915) >= PCH_ICP &&
> +	    INTEL_PCH_TYPE(i915) < PCH_MTP)
> +		return intel_de_read(i915, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;
> +
> +	return true;
> +}
> +
>  static int
>  cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  {
> @@ -1440,10 +1464,14 @@ cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>  
>  	/*
>  	 * CNP has the BXT implementation of backlight, but with only one
> -	 * controller. TODO: ICP has multiple controllers but we only use
> -	 * controller 0 for now.
> +	 * controller. ICP+ can have two controllers, depending on pin muxing.
>  	 */
> -	panel->backlight.controller = 0;
> +	panel->backlight.controller = connector->panel.vbt.backlight.controller;
> +	if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) {
> +		drm_dbg_kms(&i915->drm, "Invalid backlight controller %d, assuming 0\n",
> +			    panel->backlight.controller);
> +		panel->backlight.controller = 0;
> +	}
>  
>  	pwm_ctl = intel_de_read(i915,
>  				BXT_BLC_PWM_CTL(panel->backlight.controller));
> -- 
> 2.39.1
>
Ville Syrjälä Feb. 8, 2023, 4:19 p.m. UTC | #3
On Wed, Feb 08, 2023 at 10:23:55AM -0500, Rodrigo Vivi wrote:
> On Tue, Feb 07, 2023 at 08:43:37AM +0200, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > Use the second backlight controller on ICP+ if the VBT asks
> > us to do so.
> > 
> > On pre-MTP we also check the chicken bit to make sure the
> > pins have been correctly muxed by the firmware.
> > 
> 
> It looks like CC: stable was added while merging this patch.
> But it doesn't go clean. build fails due to s/dev_priv/i915
> and also due to the lack of ICP_SECOND_PPS_IO_SELECT that
> was added by another patch.
> 
> So we need a backported version of this patch to be included
> in the stable trees... how far we will go in the stable tree?
> 
> At this point of -rc7 I even wonder it will be better to stay
> for 6.2 to get released and then send the backported version
> to the stable ml directly...

Yeah, let's attempt the backport after 6.2 is out.

> 
> > Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8016
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  .../gpu/drm/i915/display/intel_backlight.c    | 34 +++++++++++++++++--
> >  1 file changed, 31 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
> > index 5b7da72c95b8..a4e4b7f79e4d 100644
> > --- a/drivers/gpu/drm/i915/display/intel_backlight.c
> > +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
> > @@ -1431,6 +1431,30 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
> >  	return 0;
> >  }
> >  
> > +static int cnp_num_backlight_controllers(struct drm_i915_private *i915)
> > +{
> > +	if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
> > +		return 1;
> > +
> > +	if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
> > +		return 2;
> > +
> > +	return 1;
> > +}
> > +
> > +static bool cnp_backlight_controller_is_valid(struct drm_i915_private *i915, int controller)
> > +{
> > +	if (controller < 0 || controller >= cnp_num_backlight_controllers(i915))
> > +		return false;
> > +
> > +	if (controller == 1 &&
> > +	    INTEL_PCH_TYPE(i915) >= PCH_ICP &&
> > +	    INTEL_PCH_TYPE(i915) < PCH_MTP)
> > +		return intel_de_read(i915, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;
> > +
> > +	return true;
> > +}
> > +
> >  static int
> >  cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
> >  {
> > @@ -1440,10 +1464,14 @@ cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
> >  
> >  	/*
> >  	 * CNP has the BXT implementation of backlight, but with only one
> > -	 * controller. TODO: ICP has multiple controllers but we only use
> > -	 * controller 0 for now.
> > +	 * controller. ICP+ can have two controllers, depending on pin muxing.
> >  	 */
> > -	panel->backlight.controller = 0;
> > +	panel->backlight.controller = connector->panel.vbt.backlight.controller;
> > +	if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) {
> > +		drm_dbg_kms(&i915->drm, "Invalid backlight controller %d, assuming 0\n",
> > +			    panel->backlight.controller);
> > +		panel->backlight.controller = 0;
> > +	}
> >  
> >  	pwm_ctl = intel_de_read(i915,
> >  				BXT_BLC_PWM_CTL(panel->backlight.controller));
> > -- 
> > 2.39.1
> >
Jani Nikula Feb. 9, 2023, 10:14 a.m. UTC | #4
On Wed, 08 Feb 2023, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> On Wed, Feb 08, 2023 at 10:23:55AM -0500, Rodrigo Vivi wrote:
>> On Tue, Feb 07, 2023 at 08:43:37AM +0200, Ville Syrjala wrote:
>> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> > 
>> > Use the second backlight controller on ICP+ if the VBT asks
>> > us to do so.
>> > 
>> > On pre-MTP we also check the chicken bit to make sure the
>> > pins have been correctly muxed by the firmware.
>> > 
>> 
>> It looks like CC: stable was added while merging this patch.
>> But it doesn't go clean. build fails due to s/dev_priv/i915
>> and also due to the lack of ICP_SECOND_PPS_IO_SELECT that
>> was added by another patch.
>> 
>> So we need a backported version of this patch to be included
>> in the stable trees... how far we will go in the stable tree?
>> 
>> At this point of -rc7 I even wonder it will be better to stay
>> for 6.2 to get released and then send the backported version
>> to the stable ml directly...
>
> Yeah, let's attempt the backport after 6.2 is out.

Agreed.

In any case, Cc: stable doesn't mean the commit actually backports
cleanly, but that it should be backported. Otherwise it'll just be
forgotten.


BR,
Jani.

>
>> 
>> > Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8016
>> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> > ---
>> >  .../gpu/drm/i915/display/intel_backlight.c    | 34 +++++++++++++++++--
>> >  1 file changed, 31 insertions(+), 3 deletions(-)
>> > 
>> > diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
>> > index 5b7da72c95b8..a4e4b7f79e4d 100644
>> > --- a/drivers/gpu/drm/i915/display/intel_backlight.c
>> > +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
>> > @@ -1431,6 +1431,30 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
>> >  	return 0;
>> >  }
>> >  
>> > +static int cnp_num_backlight_controllers(struct drm_i915_private *i915)
>> > +{
>> > +	if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
>> > +		return 1;
>> > +
>> > +	if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
>> > +		return 2;
>> > +
>> > +	return 1;
>> > +}
>> > +
>> > +static bool cnp_backlight_controller_is_valid(struct drm_i915_private *i915, int controller)
>> > +{
>> > +	if (controller < 0 || controller >= cnp_num_backlight_controllers(i915))
>> > +		return false;
>> > +
>> > +	if (controller == 1 &&
>> > +	    INTEL_PCH_TYPE(i915) >= PCH_ICP &&
>> > +	    INTEL_PCH_TYPE(i915) < PCH_MTP)
>> > +		return intel_de_read(i915, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;
>> > +
>> > +	return true;
>> > +}
>> > +
>> >  static int
>> >  cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>> >  {
>> > @@ -1440,10 +1464,14 @@ cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
>> >  
>> >  	/*
>> >  	 * CNP has the BXT implementation of backlight, but with only one
>> > -	 * controller. TODO: ICP has multiple controllers but we only use
>> > -	 * controller 0 for now.
>> > +	 * controller. ICP+ can have two controllers, depending on pin muxing.
>> >  	 */
>> > -	panel->backlight.controller = 0;
>> > +	panel->backlight.controller = connector->panel.vbt.backlight.controller;
>> > +	if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) {
>> > +		drm_dbg_kms(&i915->drm, "Invalid backlight controller %d, assuming 0\n",
>> > +			    panel->backlight.controller);
>> > +		panel->backlight.controller = 0;
>> > +	}
>> >  
>> >  	pwm_ctl = intel_de_read(i915,
>> >  				BXT_BLC_PWM_CTL(panel->backlight.controller));
>> > -- 
>> > 2.39.1
>> >
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
index 5b7da72c95b8..a4e4b7f79e4d 100644
--- a/drivers/gpu/drm/i915/display/intel_backlight.c
+++ b/drivers/gpu/drm/i915/display/intel_backlight.c
@@ -1431,6 +1431,30 @@  bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
 	return 0;
 }
 
+static int cnp_num_backlight_controllers(struct drm_i915_private *i915)
+{
+	if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
+		return 1;
+
+	if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
+		return 2;
+
+	return 1;
+}
+
+static bool cnp_backlight_controller_is_valid(struct drm_i915_private *i915, int controller)
+{
+	if (controller < 0 || controller >= cnp_num_backlight_controllers(i915))
+		return false;
+
+	if (controller == 1 &&
+	    INTEL_PCH_TYPE(i915) >= PCH_ICP &&
+	    INTEL_PCH_TYPE(i915) < PCH_MTP)
+		return intel_de_read(i915, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;
+
+	return true;
+}
+
 static int
 cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
 {
@@ -1440,10 +1464,14 @@  cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
 
 	/*
 	 * CNP has the BXT implementation of backlight, but with only one
-	 * controller. TODO: ICP has multiple controllers but we only use
-	 * controller 0 for now.
+	 * controller. ICP+ can have two controllers, depending on pin muxing.
 	 */
-	panel->backlight.controller = 0;
+	panel->backlight.controller = connector->panel.vbt.backlight.controller;
+	if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) {
+		drm_dbg_kms(&i915->drm, "Invalid backlight controller %d, assuming 0\n",
+			    panel->backlight.controller);
+		panel->backlight.controller = 0;
+	}
 
 	pwm_ctl = intel_de_read(i915,
 				BXT_BLC_PWM_CTL(panel->backlight.controller));