All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Lyude Paul <lyude@redhat.com>, intel-gfx@lists.freedesktop.org
Cc: thaytan@noraisin.net, "Vasily Khoruzhick" <anarsoul@gmail.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"Imre Deak" <imre.deak@intel.com>,
	"Manasi Navare" <manasi.d.navare@intel.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Sean Paul" <seanpaul@chromium.org>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Chris Wilson" <chris@chris-wilson.co.uk>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>,
	"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 1/4] drm/i915: Keep track of pwm-related backlight hooks separately
Date: Fri, 08 Jan 2021 17:05:16 +0200	[thread overview]
Message-ID: <87r1mvxydv.fsf@intel.com> (raw)
In-Reply-To: <20210107225207.28091-2-lyude@redhat.com>

On Thu, 07 Jan 2021, Lyude Paul <lyude@redhat.com> wrote:
> @@ -1628,37 +1633,32 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
>  	panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
>  
>  	pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2);
> -	panel->backlight.max = pch_ctl2 >> 16;
> +	panel->backlight.pwm_level_max = pch_ctl2 >> 16;
>  
>  	cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2);
>  
> -	if (!panel->backlight.max)
> -		panel->backlight.max = get_backlight_max_vbt(connector);
> +	if (!panel->backlight.pwm_level_max)
> +		panel->backlight.pwm_level_max = get_backlight_max_vbt(connector);
>  
> -	if (!panel->backlight.max)
> +	if (!panel->backlight.pwm_level_max)
>  		return -ENODEV;
>  
> -	panel->backlight.min = get_backlight_min_vbt(connector);
> +	panel->backlight.pwm_level_min = get_backlight_min_vbt(connector);
>  
> -	panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
> +	panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
>  
> -	cpu_mode = panel->backlight.enabled && HAS_PCH_LPT(dev_priv) &&
> +	cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(dev_priv) &&
>  		   !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) &&
>  		   (cpu_ctl2 & BLM_PWM_ENABLE);
> -	if (cpu_mode)
> -		val = pch_get_backlight(connector);
> -	else
> -		val = lpt_get_backlight(connector);
> -	val = intel_panel_compute_brightness(connector, val);
> -	panel->backlight.level = clamp(val, panel->backlight.min,
> -				       panel->backlight.max);
>  
>  	if (cpu_mode) {
> +		val = intel_panel_sanitize_pwm_level(connector, pch_get_backlight(connector));
> +

(This really is a PITA to review, not because of how you do it but
because of the hardware and the code itself. I'm just pointing out one
thing here, but I'm not finished yet.)

I think this sanitize call is wrong here. It should be called only when
converting to and from the hw register. Here, we read directly from one
hw register and write back to another hw register.

Now, looking at the history, I think it's been wrong all the way since
commit 5b1ec9ac7ab5 ("drm/i915/backlight: Fix backlight takeover on LPT,
v3."). Probably nobody noticed, because AFAIK inverted brightness
control has only ever been an issue on some gen4 platforms...

*facepalm*

BR,
Jani.

>  		drm_dbg_kms(&dev_priv->drm,
>  			    "CPU backlight register was enabled, switching to PCH override\n");
>  
>  		/* Write converted CPU PWM value to PCH override register */
> -		lpt_set_backlight(connector->base.state, panel->backlight.level);
> +		lpt_set_backlight(connector->base.state, val);
>  		intel_de_write(dev_priv, BLC_PWM_PCH_CTL1,
>  			       pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE);
>  

-- 
Jani Nikula, Intel Open Source Graphics Center

WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Lyude Paul <lyude@redhat.com>, intel-gfx@lists.freedesktop.org
Cc: thaytan@noraisin.net, Dave Airlie <airlied@redhat.com>,
	Arnd Bergmann <arnd@arndb.de>, David Airlie <airlied@linux.ie>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	Vasily Khoruzhick <anarsoul@gmail.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Sean Paul <seanpaul@chromium.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Manasi Navare <manasi.d.navare@intel.com>
Subject: Re: [PATCH v5 1/4] drm/i915: Keep track of pwm-related backlight hooks separately
Date: Fri, 08 Jan 2021 17:05:16 +0200	[thread overview]
Message-ID: <87r1mvxydv.fsf@intel.com> (raw)
In-Reply-To: <20210107225207.28091-2-lyude@redhat.com>

On Thu, 07 Jan 2021, Lyude Paul <lyude@redhat.com> wrote:
> @@ -1628,37 +1633,32 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
>  	panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
>  
>  	pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2);
> -	panel->backlight.max = pch_ctl2 >> 16;
> +	panel->backlight.pwm_level_max = pch_ctl2 >> 16;
>  
>  	cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2);
>  
> -	if (!panel->backlight.max)
> -		panel->backlight.max = get_backlight_max_vbt(connector);
> +	if (!panel->backlight.pwm_level_max)
> +		panel->backlight.pwm_level_max = get_backlight_max_vbt(connector);
>  
> -	if (!panel->backlight.max)
> +	if (!panel->backlight.pwm_level_max)
>  		return -ENODEV;
>  
> -	panel->backlight.min = get_backlight_min_vbt(connector);
> +	panel->backlight.pwm_level_min = get_backlight_min_vbt(connector);
>  
> -	panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
> +	panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
>  
> -	cpu_mode = panel->backlight.enabled && HAS_PCH_LPT(dev_priv) &&
> +	cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(dev_priv) &&
>  		   !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) &&
>  		   (cpu_ctl2 & BLM_PWM_ENABLE);
> -	if (cpu_mode)
> -		val = pch_get_backlight(connector);
> -	else
> -		val = lpt_get_backlight(connector);
> -	val = intel_panel_compute_brightness(connector, val);
> -	panel->backlight.level = clamp(val, panel->backlight.min,
> -				       panel->backlight.max);
>  
>  	if (cpu_mode) {
> +		val = intel_panel_sanitize_pwm_level(connector, pch_get_backlight(connector));
> +

(This really is a PITA to review, not because of how you do it but
because of the hardware and the code itself. I'm just pointing out one
thing here, but I'm not finished yet.)

I think this sanitize call is wrong here. It should be called only when
converting to and from the hw register. Here, we read directly from one
hw register and write back to another hw register.

Now, looking at the history, I think it's been wrong all the way since
commit 5b1ec9ac7ab5 ("drm/i915/backlight: Fix backlight takeover on LPT,
v3."). Probably nobody noticed, because AFAIK inverted brightness
control has only ever been an issue on some gen4 platforms...

*facepalm*

BR,
Jani.

>  		drm_dbg_kms(&dev_priv->drm,
>  			    "CPU backlight register was enabled, switching to PCH override\n");
>  
>  		/* Write converted CPU PWM value to PCH override register */
> -		lpt_set_backlight(connector->base.state, panel->backlight.level);
> +		lpt_set_backlight(connector->base.state, val);
>  		intel_de_write(dev_priv, BLC_PWM_PCH_CTL1,
>  			       pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE);
>  

-- 
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Lyude Paul <lyude@redhat.com>, intel-gfx@lists.freedesktop.org
Cc: Dave Airlie <airlied@redhat.com>, Arnd Bergmann <arnd@arndb.de>,
	David Airlie <airlied@linux.ie>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	Vasily Khoruzhick <anarsoul@gmail.com>,
	Sean Paul <seanpaul@chromium.org>
Subject: Re: [Intel-gfx] [PATCH v5 1/4] drm/i915: Keep track of pwm-related backlight hooks separately
Date: Fri, 08 Jan 2021 17:05:16 +0200	[thread overview]
Message-ID: <87r1mvxydv.fsf@intel.com> (raw)
In-Reply-To: <20210107225207.28091-2-lyude@redhat.com>

On Thu, 07 Jan 2021, Lyude Paul <lyude@redhat.com> wrote:
> @@ -1628,37 +1633,32 @@ static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unus
>  	panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
>  
>  	pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2);
> -	panel->backlight.max = pch_ctl2 >> 16;
> +	panel->backlight.pwm_level_max = pch_ctl2 >> 16;
>  
>  	cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2);
>  
> -	if (!panel->backlight.max)
> -		panel->backlight.max = get_backlight_max_vbt(connector);
> +	if (!panel->backlight.pwm_level_max)
> +		panel->backlight.pwm_level_max = get_backlight_max_vbt(connector);
>  
> -	if (!panel->backlight.max)
> +	if (!panel->backlight.pwm_level_max)
>  		return -ENODEV;
>  
> -	panel->backlight.min = get_backlight_min_vbt(connector);
> +	panel->backlight.pwm_level_min = get_backlight_min_vbt(connector);
>  
> -	panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
> +	panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
>  
> -	cpu_mode = panel->backlight.enabled && HAS_PCH_LPT(dev_priv) &&
> +	cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(dev_priv) &&
>  		   !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) &&
>  		   (cpu_ctl2 & BLM_PWM_ENABLE);
> -	if (cpu_mode)
> -		val = pch_get_backlight(connector);
> -	else
> -		val = lpt_get_backlight(connector);
> -	val = intel_panel_compute_brightness(connector, val);
> -	panel->backlight.level = clamp(val, panel->backlight.min,
> -				       panel->backlight.max);
>  
>  	if (cpu_mode) {
> +		val = intel_panel_sanitize_pwm_level(connector, pch_get_backlight(connector));
> +

(This really is a PITA to review, not because of how you do it but
because of the hardware and the code itself. I'm just pointing out one
thing here, but I'm not finished yet.)

I think this sanitize call is wrong here. It should be called only when
converting to and from the hw register. Here, we read directly from one
hw register and write back to another hw register.

Now, looking at the history, I think it's been wrong all the way since
commit 5b1ec9ac7ab5 ("drm/i915/backlight: Fix backlight takeover on LPT,
v3."). Probably nobody noticed, because AFAIK inverted brightness
control has only ever been an issue on some gen4 platforms...

*facepalm*

BR,
Jani.

>  		drm_dbg_kms(&dev_priv->drm,
>  			    "CPU backlight register was enabled, switching to PCH override\n");
>  
>  		/* Write converted CPU PWM value to PCH override register */
> -		lpt_set_backlight(connector->base.state, panel->backlight.level);
> +		lpt_set_backlight(connector->base.state, val);
>  		intel_de_write(dev_priv, BLC_PWM_PCH_CTL1,
>  			       pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE);
>  

-- 
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2021-01-08 15:06 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 22:52 [Intel-gfx] [PATCH v5 0/4] drm/i915: Add support for Intel's eDP backlight controls Lyude Paul
2021-01-07 22:52 ` [PATCH v5 1/4] drm/i915: Keep track of pwm-related backlight hooks separately Lyude Paul
2021-01-07 22:52   ` [Intel-gfx] " Lyude Paul
2021-01-07 22:52   ` Lyude Paul
2021-01-08 15:05   ` Jani Nikula [this message]
2021-01-08 15:05     ` [Intel-gfx] " Jani Nikula
2021-01-08 15:05     ` Jani Nikula
2021-01-11 19:02   ` Jani Nikula
2021-01-11 19:02     ` [Intel-gfx] " Jani Nikula
2021-01-11 19:02     ` Jani Nikula
2021-01-12  8:11   ` Vasily Khoruzhick
2021-01-12  8:11     ` [Intel-gfx] " Vasily Khoruzhick
2021-01-12  8:11     ` Vasily Khoruzhick
2021-01-07 22:52 ` [PATCH v5 2/4] drm/i915/dp: Enable Intel's HDR backlight interface (only SDR for now) Lyude Paul
2021-01-07 22:52   ` [Intel-gfx] " Lyude Paul
2021-01-07 22:52   ` Lyude Paul
2021-01-11 19:06   ` Jani Nikula
2021-01-11 19:06     ` [Intel-gfx] " Jani Nikula
2021-01-11 19:06     ` Jani Nikula
2021-01-07 22:52 ` [PATCH v5 3/4] drm/i915/dp: Allow forcing specific interfaces through enable_dpcd_backlight Lyude Paul
2021-01-07 22:52   ` [Intel-gfx] " Lyude Paul
2021-01-07 22:52   ` Lyude Paul
2021-01-11 19:07   ` Jani Nikula
2021-01-11 19:07     ` [Intel-gfx] " Jani Nikula
2021-01-11 19:07     ` Jani Nikula
2021-01-07 22:52 ` [PATCH v5 4/4] drm/dp: Revert "drm/dp: Introduce EDID-based quirks" Lyude Paul
2021-01-07 22:52   ` [Intel-gfx] " Lyude Paul
2021-01-07 22:52   ` Lyude Paul
2021-01-11 19:07   ` Jani Nikula
2021-01-11 19:07     ` [Intel-gfx] " Jani Nikula
2021-01-11 19:07     ` Jani Nikula
2021-01-11 19:08     ` Jani Nikula
2021-01-11 19:08       ` [Intel-gfx] " Jani Nikula
2021-01-11 19:08       ` Jani Nikula
2021-01-08  0:12 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: Add support for Intel's eDP backlight controls (rev8) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1mvxydv.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=anarsoul@gmail.com \
    --cc=arnd@arndb.de \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=lyude@redhat.com \
    --cc=manasi.d.navare@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=seanpaul@chromium.org \
    --cc=thaytan@noraisin.net \
    --cc=ville.syrjala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.