From: Jani Nikula <jani.nikula@intel.com>
To: Lyude Paul <lyude@redhat.com>,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Cc: greg.depoire@gmail.com,
Lucas De Marchi <lucas.demarchi@intel.com>,
open list <linux-kernel@vger.kernel.org>,
David Airlie <airlied@linux.ie>,
Sean Paul <seanpaul@chromium.org>,
Dave Airlie <airlied@redhat.com>
Subject: Re: [Intel-gfx] [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations
Date: Fri, 11 Dec 2020 16:45:41 +0200 [thread overview]
Message-ID: <87eejw765m.fsf@intel.com> (raw)
In-Reply-To: <20201210012143.729402-4-lyude@redhat.com>
On Wed, 09 Dec 2020, Lyude Paul <lyude@redhat.com> wrote:
> Noticed this while moving all of the VESA backlight code in i915 over to
> DRM helpers: it would appear that we calculate the frequency value we want
> to write to DP_EDP_BACKLIGHT_FREQ_SET twice even though this value never
> actually changes during runtime. So, let's simplify things by just caching
> this value in intel_panel.backlight, and re-writing it as-needed.
This isn't a full review, just something I spotted so far. Please see
inline.
BR,
Jani.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Dave Airlie <airlied@gmail.com>
> Cc: greg.depoire@gmail.com
> ---
> .../drm/i915/display/intel_display_types.h | 1 +
> .../drm/i915/display/intel_dp_aux_backlight.c | 64 ++++++-------------
> 2 files changed, 19 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h
> index 5bc5bfbc4551..133c9cb742a7 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_types.h
> +++ b/drivers/gpu/drm/i915/display/intel_display_types.h
> @@ -259,6 +259,7 @@ struct intel_panel {
>
> /* DPCD backlight */
> u8 pwmgen_bit_count;
> + u8 pwm_freq_pre_divider;
>
> struct backlight_device *device;
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> index 4fd536801b14..94ce5ca1affa 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> @@ -129,50 +129,6 @@ intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 lev
> }
> }
>
> -/*
> - * Set PWM Frequency divider to match desired frequency in vbt.
> - * The PWM Frequency is calculated as 27Mhz / (F x P).
> - * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> - * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> - * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> - * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> - */
> -static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
> -{
> - struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> - struct intel_dp *intel_dp = intel_attached_dp(connector);
> - const u8 pn = connector->panel.backlight.pwmgen_bit_count;
> - int freq, fxp, f, fxp_actual, fxp_min, fxp_max;
> -
> - freq = dev_priv->vbt.backlight.pwm_freq_hz;
> - if (!freq) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Use panel default backlight frequency\n");
> - return false;
> - }
> -
> - fxp = DIV_ROUND_CLOSEST(KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ), freq);
> - f = clamp(DIV_ROUND_CLOSEST(fxp, 1 << pn), 1, 255);
> - fxp_actual = f << pn;
> -
> - /* Ensure frequency is within 25% of desired value */
> - fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> - fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> -
> - if (fxp_min > fxp_actual || fxp_actual > fxp_max) {
> - drm_dbg_kms(&dev_priv->drm, "Actual frequency out of range\n");
> - return false;
> - }
> -
> - if (drm_dp_dpcd_writeb(&intel_dp->aux,
> - DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Failed to write aux backlight freq\n");
> - return false;
> - }
> - return true;
> -}
> -
> static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_state,
> const struct drm_connector_state *conn_state)
> {
> @@ -213,9 +169,13 @@ static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_st
> break;
> }
>
> - if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
> - if (intel_dp_aux_set_pwm_freq(connector))
> + if (panel->backlight.pwm_freq_pre_divider) {
> + if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET,
> + panel->backlight.pwm_freq_pre_divider) == 1)
> new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
> + else
> + drm_dbg_kms(&i915->drm, "Failed to write aux backlight frequency\n");
> + }
>
> if (new_dpcd_buf != dpcd_buf) {
> if (drm_dp_dpcd_writeb(&intel_dp->aux,
> @@ -236,6 +196,14 @@ static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old
> false);
> }
>
> +/*
> + * Compute PWM frequency divider value based off the frequency provided to us by the vbt.
> + * The PWM Frequency is calculated as 27Mhz / (F x P).
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> + */
> static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> {
> struct drm_i915_private *i915 = to_i915(connector->base.dev);
> @@ -287,8 +255,10 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
>
> + /* Ensure frequency is within 25% of desired value */
> fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> +
> if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) {
> drm_dbg_kms(&i915->drm,
> "VBT defined backlight frequency out of range\n");
> @@ -309,7 +279,9 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> "Failed to write aux pwmgen bit count\n");
> return max_backlight;
> }
> +
> panel->backlight.pwmgen_bit_count = pn;
> + panel->backlight.pwm_freq_pre_divider = f;
This should be wrapped in
if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
but you do it in the next patch, so this patch is a bit broken.
>
> max_backlight = (1 << pn) - 1;
--
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: Lyude Paul <lyude@redhat.com>,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Cc: greg.depoire@gmail.com,
Lucas De Marchi <lucas.demarchi@intel.com>,
open list <linux-kernel@vger.kernel.org>,
David Airlie <airlied@linux.ie>,
Sean Paul <seanpaul@chromium.org>,
Dave Airlie <airlied@redhat.com>
Subject: Re: [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations
Date: Fri, 11 Dec 2020 16:45:41 +0200 [thread overview]
Message-ID: <87eejw765m.fsf@intel.com> (raw)
In-Reply-To: <20201210012143.729402-4-lyude@redhat.com>
On Wed, 09 Dec 2020, Lyude Paul <lyude@redhat.com> wrote:
> Noticed this while moving all of the VESA backlight code in i915 over to
> DRM helpers: it would appear that we calculate the frequency value we want
> to write to DP_EDP_BACKLIGHT_FREQ_SET twice even though this value never
> actually changes during runtime. So, let's simplify things by just caching
> this value in intel_panel.backlight, and re-writing it as-needed.
This isn't a full review, just something I spotted so far. Please see
inline.
BR,
Jani.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Dave Airlie <airlied@gmail.com>
> Cc: greg.depoire@gmail.com
> ---
> .../drm/i915/display/intel_display_types.h | 1 +
> .../drm/i915/display/intel_dp_aux_backlight.c | 64 ++++++-------------
> 2 files changed, 19 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h
> index 5bc5bfbc4551..133c9cb742a7 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_types.h
> +++ b/drivers/gpu/drm/i915/display/intel_display_types.h
> @@ -259,6 +259,7 @@ struct intel_panel {
>
> /* DPCD backlight */
> u8 pwmgen_bit_count;
> + u8 pwm_freq_pre_divider;
>
> struct backlight_device *device;
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> index 4fd536801b14..94ce5ca1affa 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> @@ -129,50 +129,6 @@ intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 lev
> }
> }
>
> -/*
> - * Set PWM Frequency divider to match desired frequency in vbt.
> - * The PWM Frequency is calculated as 27Mhz / (F x P).
> - * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> - * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> - * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> - * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> - */
> -static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
> -{
> - struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> - struct intel_dp *intel_dp = intel_attached_dp(connector);
> - const u8 pn = connector->panel.backlight.pwmgen_bit_count;
> - int freq, fxp, f, fxp_actual, fxp_min, fxp_max;
> -
> - freq = dev_priv->vbt.backlight.pwm_freq_hz;
> - if (!freq) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Use panel default backlight frequency\n");
> - return false;
> - }
> -
> - fxp = DIV_ROUND_CLOSEST(KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ), freq);
> - f = clamp(DIV_ROUND_CLOSEST(fxp, 1 << pn), 1, 255);
> - fxp_actual = f << pn;
> -
> - /* Ensure frequency is within 25% of desired value */
> - fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> - fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> -
> - if (fxp_min > fxp_actual || fxp_actual > fxp_max) {
> - drm_dbg_kms(&dev_priv->drm, "Actual frequency out of range\n");
> - return false;
> - }
> -
> - if (drm_dp_dpcd_writeb(&intel_dp->aux,
> - DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Failed to write aux backlight freq\n");
> - return false;
> - }
> - return true;
> -}
> -
> static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_state,
> const struct drm_connector_state *conn_state)
> {
> @@ -213,9 +169,13 @@ static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_st
> break;
> }
>
> - if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
> - if (intel_dp_aux_set_pwm_freq(connector))
> + if (panel->backlight.pwm_freq_pre_divider) {
> + if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET,
> + panel->backlight.pwm_freq_pre_divider) == 1)
> new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
> + else
> + drm_dbg_kms(&i915->drm, "Failed to write aux backlight frequency\n");
> + }
>
> if (new_dpcd_buf != dpcd_buf) {
> if (drm_dp_dpcd_writeb(&intel_dp->aux,
> @@ -236,6 +196,14 @@ static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old
> false);
> }
>
> +/*
> + * Compute PWM frequency divider value based off the frequency provided to us by the vbt.
> + * The PWM Frequency is calculated as 27Mhz / (F x P).
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> + */
> static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> {
> struct drm_i915_private *i915 = to_i915(connector->base.dev);
> @@ -287,8 +255,10 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
>
> + /* Ensure frequency is within 25% of desired value */
> fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> +
> if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) {
> drm_dbg_kms(&i915->drm,
> "VBT defined backlight frequency out of range\n");
> @@ -309,7 +279,9 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> "Failed to write aux pwmgen bit count\n");
> return max_backlight;
> }
> +
> panel->backlight.pwmgen_bit_count = pn;
> + panel->backlight.pwm_freq_pre_divider = f;
This should be wrapped in
if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
but you do it in the next patch, so this patch is a bit broken.
>
> max_backlight = (1 << pn) - 1;
--
Jani Nikula, Intel Open Source Graphics Center
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: Lyude Paul <lyude@redhat.com>,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Cc: "Juha-Pekka Heikkila" <juhapekka.heikkila@gmail.com>,
greg.depoire@gmail.com,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"open list" <linux-kernel@vger.kernel.org>,
"José Roberto de Souza" <jose.souza@intel.com>,
"Manasi Navare" <manasi.d.navare@intel.com>,
"David Airlie" <airlied@linux.ie>,
"Sean Paul" <seanpaul@chromium.org>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Dave Airlie" <airlied@redhat.com>
Subject: Re: [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations
Date: Fri, 11 Dec 2020 16:45:41 +0200 [thread overview]
Message-ID: <87eejw765m.fsf@intel.com> (raw)
In-Reply-To: <20201210012143.729402-4-lyude@redhat.com>
On Wed, 09 Dec 2020, Lyude Paul <lyude@redhat.com> wrote:
> Noticed this while moving all of the VESA backlight code in i915 over to
> DRM helpers: it would appear that we calculate the frequency value we want
> to write to DP_EDP_BACKLIGHT_FREQ_SET twice even though this value never
> actually changes during runtime. So, let's simplify things by just caching
> this value in intel_panel.backlight, and re-writing it as-needed.
This isn't a full review, just something I spotted so far. Please see
inline.
BR,
Jani.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Dave Airlie <airlied@gmail.com>
> Cc: greg.depoire@gmail.com
> ---
> .../drm/i915/display/intel_display_types.h | 1 +
> .../drm/i915/display/intel_dp_aux_backlight.c | 64 ++++++-------------
> 2 files changed, 19 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h
> index 5bc5bfbc4551..133c9cb742a7 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_types.h
> +++ b/drivers/gpu/drm/i915/display/intel_display_types.h
> @@ -259,6 +259,7 @@ struct intel_panel {
>
> /* DPCD backlight */
> u8 pwmgen_bit_count;
> + u8 pwm_freq_pre_divider;
>
> struct backlight_device *device;
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> index 4fd536801b14..94ce5ca1affa 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> @@ -129,50 +129,6 @@ intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 lev
> }
> }
>
> -/*
> - * Set PWM Frequency divider to match desired frequency in vbt.
> - * The PWM Frequency is calculated as 27Mhz / (F x P).
> - * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> - * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> - * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> - * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> - */
> -static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
> -{
> - struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> - struct intel_dp *intel_dp = intel_attached_dp(connector);
> - const u8 pn = connector->panel.backlight.pwmgen_bit_count;
> - int freq, fxp, f, fxp_actual, fxp_min, fxp_max;
> -
> - freq = dev_priv->vbt.backlight.pwm_freq_hz;
> - if (!freq) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Use panel default backlight frequency\n");
> - return false;
> - }
> -
> - fxp = DIV_ROUND_CLOSEST(KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ), freq);
> - f = clamp(DIV_ROUND_CLOSEST(fxp, 1 << pn), 1, 255);
> - fxp_actual = f << pn;
> -
> - /* Ensure frequency is within 25% of desired value */
> - fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> - fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> -
> - if (fxp_min > fxp_actual || fxp_actual > fxp_max) {
> - drm_dbg_kms(&dev_priv->drm, "Actual frequency out of range\n");
> - return false;
> - }
> -
> - if (drm_dp_dpcd_writeb(&intel_dp->aux,
> - DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Failed to write aux backlight freq\n");
> - return false;
> - }
> - return true;
> -}
> -
> static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_state,
> const struct drm_connector_state *conn_state)
> {
> @@ -213,9 +169,13 @@ static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_st
> break;
> }
>
> - if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
> - if (intel_dp_aux_set_pwm_freq(connector))
> + if (panel->backlight.pwm_freq_pre_divider) {
> + if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET,
> + panel->backlight.pwm_freq_pre_divider) == 1)
> new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
> + else
> + drm_dbg_kms(&i915->drm, "Failed to write aux backlight frequency\n");
> + }
>
> if (new_dpcd_buf != dpcd_buf) {
> if (drm_dp_dpcd_writeb(&intel_dp->aux,
> @@ -236,6 +196,14 @@ static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old
> false);
> }
>
> +/*
> + * Compute PWM frequency divider value based off the frequency provided to us by the vbt.
> + * The PWM Frequency is calculated as 27Mhz / (F x P).
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> + */
> static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> {
> struct drm_i915_private *i915 = to_i915(connector->base.dev);
> @@ -287,8 +255,10 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
>
> + /* Ensure frequency is within 25% of desired value */
> fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> +
> if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) {
> drm_dbg_kms(&i915->drm,
> "VBT defined backlight frequency out of range\n");
> @@ -309,7 +279,9 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> "Failed to write aux pwmgen bit count\n");
> return max_backlight;
> }
> +
> panel->backlight.pwmgen_bit_count = pn;
> + panel->backlight.pwm_freq_pre_divider = f;
This should be wrapped in
if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
but you do it in the next patch, so this patch is a bit broken.
>
> max_backlight = (1 << pn) - 1;
--
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@intel.com>
To: Lyude Paul <lyude@redhat.com>,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Cc: "Dave Airlie" <airlied@gmail.com>,
greg.depoire@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>,
"José Roberto de Souza" <jose.souza@intel.com>,
"Manasi Navare" <manasi.d.navare@intel.com>,
"Sean Paul" <seanpaul@chromium.org>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Juha-Pekka Heikkila" <juhapekka.heikkila@gmail.com>,
"Dave Airlie" <airlied@redhat.com>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations
Date: Fri, 11 Dec 2020 16:45:41 +0200 [thread overview]
Message-ID: <87eejw765m.fsf@intel.com> (raw)
In-Reply-To: <20201210012143.729402-4-lyude@redhat.com>
On Wed, 09 Dec 2020, Lyude Paul <lyude@redhat.com> wrote:
> Noticed this while moving all of the VESA backlight code in i915 over to
> DRM helpers: it would appear that we calculate the frequency value we want
> to write to DP_EDP_BACKLIGHT_FREQ_SET twice even though this value never
> actually changes during runtime. So, let's simplify things by just caching
> this value in intel_panel.backlight, and re-writing it as-needed.
This isn't a full review, just something I spotted so far. Please see
inline.
BR,
Jani.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Dave Airlie <airlied@gmail.com>
> Cc: greg.depoire@gmail.com
> ---
> .../drm/i915/display/intel_display_types.h | 1 +
> .../drm/i915/display/intel_dp_aux_backlight.c | 64 ++++++-------------
> 2 files changed, 19 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h
> index 5bc5bfbc4551..133c9cb742a7 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_types.h
> +++ b/drivers/gpu/drm/i915/display/intel_display_types.h
> @@ -259,6 +259,7 @@ struct intel_panel {
>
> /* DPCD backlight */
> u8 pwmgen_bit_count;
> + u8 pwm_freq_pre_divider;
>
> struct backlight_device *device;
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> index 4fd536801b14..94ce5ca1affa 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
> @@ -129,50 +129,6 @@ intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 lev
> }
> }
>
> -/*
> - * Set PWM Frequency divider to match desired frequency in vbt.
> - * The PWM Frequency is calculated as 27Mhz / (F x P).
> - * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> - * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> - * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> - * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> - */
> -static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
> -{
> - struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> - struct intel_dp *intel_dp = intel_attached_dp(connector);
> - const u8 pn = connector->panel.backlight.pwmgen_bit_count;
> - int freq, fxp, f, fxp_actual, fxp_min, fxp_max;
> -
> - freq = dev_priv->vbt.backlight.pwm_freq_hz;
> - if (!freq) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Use panel default backlight frequency\n");
> - return false;
> - }
> -
> - fxp = DIV_ROUND_CLOSEST(KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ), freq);
> - f = clamp(DIV_ROUND_CLOSEST(fxp, 1 << pn), 1, 255);
> - fxp_actual = f << pn;
> -
> - /* Ensure frequency is within 25% of desired value */
> - fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> - fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> -
> - if (fxp_min > fxp_actual || fxp_actual > fxp_max) {
> - drm_dbg_kms(&dev_priv->drm, "Actual frequency out of range\n");
> - return false;
> - }
> -
> - if (drm_dp_dpcd_writeb(&intel_dp->aux,
> - DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {
> - drm_dbg_kms(&dev_priv->drm,
> - "Failed to write aux backlight freq\n");
> - return false;
> - }
> - return true;
> -}
> -
> static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_state,
> const struct drm_connector_state *conn_state)
> {
> @@ -213,9 +169,13 @@ static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_st
> break;
> }
>
> - if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
> - if (intel_dp_aux_set_pwm_freq(connector))
> + if (panel->backlight.pwm_freq_pre_divider) {
> + if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET,
> + panel->backlight.pwm_freq_pre_divider) == 1)
> new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
> + else
> + drm_dbg_kms(&i915->drm, "Failed to write aux backlight frequency\n");
> + }
>
> if (new_dpcd_buf != dpcd_buf) {
> if (drm_dp_dpcd_writeb(&intel_dp->aux,
> @@ -236,6 +196,14 @@ static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old
> false);
> }
>
> +/*
> + * Compute PWM frequency divider value based off the frequency provided to us by the vbt.
> + * The PWM Frequency is calculated as 27Mhz / (F x P).
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> + */
> static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> {
> struct drm_i915_private *i915 = to_i915(connector->base.dev);
> @@ -287,8 +255,10 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
>
> + /* Ensure frequency is within 25% of desired value */
> fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4);
> fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4);
> +
> if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) {
> drm_dbg_kms(&i915->drm,
> "VBT defined backlight frequency out of range\n");
> @@ -309,7 +279,9 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector)
> "Failed to write aux pwmgen bit count\n");
> return max_backlight;
> }
> +
> panel->backlight.pwmgen_bit_count = pn;
> + panel->backlight.pwm_freq_pre_divider = f;
This should be wrapped in
if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP)
but you do it in the next patch, so this patch is a bit broken.
>
> max_backlight = (1 << pn) - 1;
--
Jani Nikula, Intel Open Source Graphics Center
next prev parent reply other threads:[~2020-12-11 14:54 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-10 1:21 [Intel-gfx] [RFC 0/5] drm: Extract DPCD backlight helpers from i915, add support in nouveau Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` [Intel-gfx] [RFC 1/5] drm/nouveau/kms/nv40-/backlight: Assign prop type once Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` [Intel-gfx] [RFC 2/5] drm/nouveau/kms: Don't probe eDP connectors more then once Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` [Intel-gfx] [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-11 14:45 ` Jani Nikula [this message]
2020-12-11 14:45 ` Jani Nikula
2020-12-11 14:45 ` Jani Nikula
2020-12-11 14:45 ` Jani Nikula
2020-12-10 1:21 ` [Intel-gfx] [RFC 4/5] drm/dp: Extract i915's eDP backlight code into DRM helpers Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-11 15:01 ` [Intel-gfx] " Jani Nikula
2020-12-11 15:01 ` Jani Nikula
2020-12-11 15:01 ` Jani Nikula
2020-12-11 15:01 ` Jani Nikula
2021-01-26 0:02 ` [Intel-gfx] " Lyude Paul
2021-01-26 0:02 ` Lyude Paul
2021-01-26 0:02 ` Lyude Paul
2021-01-26 0:02 ` Lyude Paul
2020-12-10 1:21 ` [Intel-gfx] [RFC 5/5] drm/nouveau/kms/nv50-: Add basic DPCD backlight support for nouveau Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 1:21 ` Lyude Paul
2020-12-10 3:57 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm: Extract DPCD backlight helpers from i915, add support in nouveau Patchwork
2020-12-10 4:00 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-12-10 4:03 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2020-12-10 4:28 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-12-10 7:32 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2020-12-10 18:38 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm: Extract DPCD backlight helpers from i915, add support in nouveau (rev2) Patchwork
2020-12-10 18:40 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-12-10 18:43 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2020-12-10 19:07 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-12-10 20:52 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2020-12-10 23:01 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm: Extract DPCD backlight helpers from i915, add support in nouveau (rev3) Patchwork
2020-12-10 23:03 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-12-10 23:07 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2020-12-10 23:30 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-12-11 1:20 ` [Intel-gfx] ✓ Fi.CI.IGT: " 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=87eejw765m.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=airlied@linux.ie \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=greg.depoire@gmail.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=lyude@redhat.com \
--cc=nouveau@lists.freedesktop.org \
--cc=seanpaul@chromium.org \
/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.