<div dir="ltr">Thanks very much for the quick reply, Lyude!<br><br>I'm happy to make the requested changes, but I wanted to clarify before falling down the wrong hole: are you suggesting that I move the intel_dp_aux_set_backlight/intel_dp_aux_get_backlight routines to the drm_dp_helper.c file?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020 at 11:13 AM Lyude Paul <<a href="mailto:lyude@redhat.com">lyude@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Just an FYI, my plan for some of this eDP backlight code is to move as much of<br>
it into helpers as possible since we need to implement the same interface in<br>
nouveau. We probably can figure out some other solution for handling this quirk<br>
if this isn't possible, but could we maybe use the panel's OUI here and add a<br>
quirk to drm_dp_helper.c instead?<br>
<br>
On Thu, 2020-09-17 at 11:09 -0600, Kevin Chowski wrote:<br>
> We have observed that Google Pixelbook's backlight hardware is<br>
> interpretting these backlight bits from the most-significant side of the<br>
> 16 bit word (if DP_EDP_PWMGEN_BIT_COUNT < 16), whereas the driver code<br>
> assumes the peripheral cares about the least-significant bits.<br>
> <br>
> Testing was done from within Chrome OS's build environment when the<br>
> patch is backported to 5.4 (the version we are newly targeting for the<br>
> Pixelbook); for the record:<br>
>    $ emerge-eve-kernelnext sys-kernel/chromeos-kernel-5_4 && \<br>
>       ./update_kernel.sh --remote=$IP<br>
> <br>
> I used `/sys/kernel/debug/dri/0/eDP-1/i915_dpcd` on my laptop to verify<br>
> that the registers were being set according to what the actual hardware<br>
> expects; I also observe that the backlight is noticeably brighter with<br>
> this patch.<br>
> <br>
> Signed-off-by: Kevin Chowski <<a href="mailto:chowski@chromium.org" target="_blank">chowski@chromium.org</a>><br>
> ---<br>
> <br>
>  .../drm/i915/display/intel_dp_aux_backlight.c | 34 +++++++++++++++++++<br>
>  drivers/gpu/drm/i915/display/intel_quirks.c   | 13 +++++++<br>
>  drivers/gpu/drm/i915/i915_drv.h               |  1 +<br>
>  3 files changed, 48 insertions(+)<br>
> <br>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c<br>
> b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c<br>
> index acbd7eb66cbe3..99c98f217356d 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c<br>
> +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c<br>
> @@ -91,6 +91,23 @@ static u32 intel_dp_aux_get_backlight(struct<br>
> intel_connector *connector)<br>
>       if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_BYTE_COUNT)<br>
>               level = (read_val[0] << 8 | read_val[1]);<br>
>  <br>
> +     if (i915->quirks & QUIRK_SHIFT_EDP_BACKLIGHT_BRIGHTNESS) {<br>
> +             if (!drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_PWMGEN_BIT_COUNT,<br>
> +                                             &read_val[0])) {<br>
> +                     DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n",<br>
> +                                     DP_EDP_PWMGEN_BIT_COUNT);<br>
> +                     return 0;<br>
> +             }<br>
> +             // Only bits 4:0 are used, 7:5 are reserved.<br>
> +             read_val[0] = read_val[0] & 0x1F;<br>
> +             if (read_val[0] > 16) {<br>
> +                     DRM_DEBUG_KMS("Invalid DP_EDP_PWNGEN_BIT_COUNT 0x%X,<br>
> expected at most 16\n",<br>
> +                                             read_val[0]);<br>
> +                     return 0;<br>
> +             }<br>
> +             level >>= 16 - read_val[0];<br>
> +     }<br>
> +<br>
>       return level;<br>
>  }<br>
>  <br>
> @@ -106,6 +123,23 @@ intel_dp_aux_set_backlight(const struct<br>
> drm_connector_state *conn_state, u32 lev<br>
>       struct drm_i915_private *i915 = dp_to_i915(intel_dp);<br>
>       u8 vals[2] = { 0x0 };<br>
>  <br>
> +     if (i915->quirks & QUIRK_SHIFT_EDP_BACKLIGHT_BRIGHTNESS) {<br>
> +             if (!drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_PWMGEN_BIT_COUNT,<br>
> +                                             &vals[0])) {<br>
> +                     DRM_DEBUG_KMS("Failed to write aux backlight level:<br>
> Failed to read DPCD register 0x%x\n",<br>
> +                                       DP_EDP_PWMGEN_BIT_COUNT);<br>
> +                     return;<br>
> +             }<br>
> +             // Only bits 4:0 are used, 7:5 are reserved.<br>
> +             vals[0] = vals[0] & 0x1F;<br>
> +             if (vals[0] > 16) {<br>
> +                     DRM_DEBUG_KMS("Failed to write aux backlight level:<br>
> Invalid DP_EDP_PWNGEN_BIT_COUNT 0x%X, expected at most 16\n",<br>
> +                                             vals[0]);<br>
> +                     return;<br>
> +             }<br>
> +             level <<= (16 - vals[0]) & 0xFFFF;<br>
> +     }<br>
> +<br>
>       vals[0] = level;<br>
>  <br>
>       /* Write the MSB and/or LSB */<br>
> diff --git a/drivers/gpu/drm/i915/display/intel_quirks.c<br>
> b/drivers/gpu/drm/i915/display/intel_quirks.c<br>
> index 46beb155d835f..63b27d49b2864 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_quirks.c<br>
> +++ b/drivers/gpu/drm/i915/display/intel_quirks.c<br>
> @@ -53,6 +53,16 @@ static void quirk_increase_ddi_disabled_time(struct<br>
> drm_i915_private *i915)<br>
>       drm_info(&i915->drm, "Applying Increase DDI Disabled quirk\n");<br>
>  }<br>
>  <br>
> +/*<br>
> + * Some eDP backlight hardware uses the most-significant bits of the<br>
> brightness<br>
> + * register, so brightness values must be shifted first.<br>
> + */<br>
> +static void quirk_shift_edp_backlight_brightness(struct drm_i915_private<br>
> *i915)<br>
> +{<br>
> +     i915->quirks |= QUIRK_SHIFT_EDP_BACKLIGHT_BRIGHTNESS;<br>
> +     DRM_INFO("Applying shift eDP backlight brightness quirk\n");<br>
> +}<br>
> +<br>
>  struct intel_quirk {<br>
>       int device;<br>
>       int subsystem_vendor;<br>
> @@ -156,6 +166,9 @@ static struct intel_quirk intel_quirks[] = {<br>
>       /* ASRock ITX*/<br>
>       { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },<br>
>       { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },<br>
> +<br>
> +     /* Google Pixelbook */<br>
> +     { 0x591E, 0x8086, 0x2212, quirk_shift_edp_backlight_brightness },<br>
>  };<br>
>  <br>
>  void intel_init_quirks(struct drm_i915_private *i915)<br>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h<br>
> index e4f7f6518945b..cc93bede4fab8 100644<br>
> --- a/drivers/gpu/drm/i915/i915_drv.h<br>
> +++ b/drivers/gpu/drm/i915/i915_drv.h<br>
> @@ -525,6 +525,7 @@ struct i915_psr {<br>
>  #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)<br>
>  #define QUIRK_INCREASE_T12_DELAY (1<<6)<br>
>  #define QUIRK_INCREASE_DDI_DISABLED_TIME (1<<7)<br>
> +#define QUIRK_SHIFT_EDP_BACKLIGHT_BRIGHTNESS (1<<8)<br>
>  <br>
>  struct intel_fbdev;<br>
>  struct intel_fbc_work;<br>
-- <br>
Sincerely,<br>
      Lyude Paul (she/her)<br>
      Software Engineer at Red Hat<br>
<br>
</blockquote></div>