LCOV - code coverage report
Current view: top level - drivers/gpu/drm/i915/display - intel_panel.c (source / functions) Hit Total Coverage
Test: combined.info Lines: 0 1071 0.0 %
Date: 2022-04-01 14:35:51 Functions: 0 73 0.0 %
Branches: 0 410 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright © 2006-2010 Intel Corporation
       3                 :            :  * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
       4                 :            :  *
       5                 :            :  * Permission is hereby granted, free of charge, to any person obtaining a
       6                 :            :  * copy of this software and associated documentation files (the "Software"),
       7                 :            :  * to deal in the Software without restriction, including without limitation
       8                 :            :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       9                 :            :  * and/or sell copies of the Software, and to permit persons to whom the
      10                 :            :  * Software is furnished to do so, subject to the following conditions:
      11                 :            :  *
      12                 :            :  * The above copyright notice and this permission notice (including the next
      13                 :            :  * paragraph) shall be included in all copies or substantial portions of the
      14                 :            :  * Software.
      15                 :            :  *
      16                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      17                 :            :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      18                 :            :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      19                 :            :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      20                 :            :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      21                 :            :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      22                 :            :  * DEALINGS IN THE SOFTWARE.
      23                 :            :  *
      24                 :            :  * Authors:
      25                 :            :  *      Eric Anholt <eric@anholt.net>
      26                 :            :  *      Dave Airlie <airlied@linux.ie>
      27                 :            :  *      Jesse Barnes <jesse.barnes@intel.com>
      28                 :            :  *      Chris Wilson <chris@chris-wilson.co.uk>
      29                 :            :  */
      30                 :            : 
      31                 :            : #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
      32                 :            : 
      33                 :            : #include <linux/kernel.h>
      34                 :            : #include <linux/moduleparam.h>
      35                 :            : #include <linux/pwm.h>
      36                 :            : 
      37                 :            : #include "intel_connector.h"
      38                 :            : #include "intel_display_types.h"
      39                 :            : #include "intel_dp_aux_backlight.h"
      40                 :            : #include "intel_dsi_dcs_backlight.h"
      41                 :            : #include "intel_panel.h"
      42                 :            : 
      43                 :            : #define CRC_PMIC_PWM_PERIOD_NS  21333
      44                 :            : 
      45                 :            : void
      46                 :          0 : intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
      47                 :            :                        struct drm_display_mode *adjusted_mode)
      48                 :            : {
      49                 :          0 :         drm_mode_copy(adjusted_mode, fixed_mode);
      50                 :            : 
      51                 :          0 :         drm_mode_set_crtcinfo(adjusted_mode, 0);
      52                 :          0 : }
      53                 :            : 
      54                 :          0 : static bool is_downclock_mode(const struct drm_display_mode *downclock_mode,
      55                 :            :                               const struct drm_display_mode *fixed_mode)
      56                 :            : {
      57                 :          0 :         return drm_mode_match(downclock_mode, fixed_mode,
      58                 :            :                               DRM_MODE_MATCH_TIMINGS |
      59                 :            :                               DRM_MODE_MATCH_FLAGS |
      60         [ #  # ]:          0 :                               DRM_MODE_MATCH_3D_FLAGS) &&
      61         [ #  # ]:          0 :                 downclock_mode->clock < fixed_mode->clock;
      62                 :            : }
      63                 :            : 
      64                 :            : struct drm_display_mode *
      65                 :          0 : intel_panel_edid_downclock_mode(struct intel_connector *connector,
      66                 :            :                                 const struct drm_display_mode *fixed_mode)
      67                 :            : {
      68                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
      69                 :          0 :         const struct drm_display_mode *scan, *best_mode = NULL;
      70                 :          0 :         struct drm_display_mode *downclock_mode;
      71                 :          0 :         int best_clock = fixed_mode->clock;
      72                 :            : 
      73         [ #  # ]:          0 :         list_for_each_entry(scan, &connector->base.probed_modes, head) {
      74                 :            :                 /*
      75                 :            :                  * If one mode has the same resolution with the fixed_panel
      76                 :            :                  * mode while they have the different refresh rate, it means
      77                 :            :                  * that the reduced downclock is found. In such
      78                 :            :                  * case we can set the different FPx0/1 to dynamically select
      79                 :            :                  * between low and high frequency.
      80                 :            :                  */
      81         [ #  # ]:          0 :                 if (is_downclock_mode(scan, fixed_mode) &&
      82         [ #  # ]:          0 :                     scan->clock < best_clock) {
      83                 :            :                         /*
      84                 :            :                          * The downclock is already found. But we
      85                 :            :                          * expect to find the lower downclock.
      86                 :            :                          */
      87                 :          0 :                         best_clock = scan->clock;
      88                 :          0 :                         best_mode = scan;
      89                 :            :                 }
      90                 :            :         }
      91                 :            : 
      92         [ #  # ]:          0 :         if (!best_mode)
      93                 :            :                 return NULL;
      94                 :            : 
      95                 :          0 :         downclock_mode = drm_mode_duplicate(&dev_priv->drm, best_mode);
      96         [ #  # ]:          0 :         if (!downclock_mode)
      97                 :            :                 return NULL;
      98                 :            : 
      99                 :          0 :         DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using downclock mode from EDID: ",
     100                 :            :                       connector->base.base.id, connector->base.name);
     101                 :          0 :         drm_mode_debug_printmodeline(downclock_mode);
     102                 :            : 
     103                 :          0 :         return downclock_mode;
     104                 :            : }
     105                 :            : 
     106                 :            : struct drm_display_mode *
     107                 :          0 : intel_panel_edid_fixed_mode(struct intel_connector *connector)
     108                 :            : {
     109         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     110                 :          0 :         const struct drm_display_mode *scan;
     111                 :          0 :         struct drm_display_mode *fixed_mode;
     112                 :            : 
     113         [ #  # ]:          0 :         if (list_empty(&connector->base.probed_modes))
     114                 :            :                 return NULL;
     115                 :            : 
     116                 :            :         /* prefer fixed mode from EDID if available */
     117         [ #  # ]:          0 :         list_for_each_entry(scan, &connector->base.probed_modes, head) {
     118         [ #  # ]:          0 :                 if ((scan->type & DRM_MODE_TYPE_PREFERRED) == 0)
     119                 :          0 :                         continue;
     120                 :            : 
     121                 :          0 :                 fixed_mode = drm_mode_duplicate(&dev_priv->drm, scan);
     122         [ #  # ]:          0 :                 if (!fixed_mode)
     123                 :            :                         return NULL;
     124                 :            : 
     125                 :          0 :                 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using preferred mode from EDID: ",
     126                 :            :                               connector->base.base.id, connector->base.name);
     127                 :          0 :                 drm_mode_debug_printmodeline(fixed_mode);
     128                 :            : 
     129                 :          0 :                 return fixed_mode;
     130                 :            :         }
     131                 :            : 
     132                 :          0 :         scan = list_first_entry(&connector->base.probed_modes,
     133                 :            :                                 typeof(*scan), head);
     134                 :            : 
     135                 :          0 :         fixed_mode = drm_mode_duplicate(&dev_priv->drm, scan);
     136         [ #  # ]:          0 :         if (!fixed_mode)
     137                 :            :                 return NULL;
     138                 :            : 
     139                 :          0 :         fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
     140                 :            : 
     141                 :          0 :         DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using first mode from EDID: ",
     142                 :            :                       connector->base.base.id, connector->base.name);
     143                 :          0 :         drm_mode_debug_printmodeline(fixed_mode);
     144                 :            : 
     145                 :          0 :         return fixed_mode;
     146                 :            : }
     147                 :            : 
     148                 :            : struct drm_display_mode *
     149                 :          0 : intel_panel_vbt_fixed_mode(struct intel_connector *connector)
     150                 :            : {
     151         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     152                 :          0 :         struct drm_display_info *info = &connector->base.display_info;
     153                 :          0 :         struct drm_display_mode *fixed_mode;
     154                 :            : 
     155         [ #  # ]:          0 :         if (!dev_priv->vbt.lfp_lvds_vbt_mode)
     156                 :            :                 return NULL;
     157                 :            : 
     158                 :          0 :         fixed_mode = drm_mode_duplicate(&dev_priv->drm,
     159                 :            :                                         dev_priv->vbt.lfp_lvds_vbt_mode);
     160         [ #  # ]:          0 :         if (!fixed_mode)
     161                 :            :                 return NULL;
     162                 :            : 
     163                 :          0 :         fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
     164                 :            : 
     165                 :          0 :         DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using mode from VBT: ",
     166                 :            :                       connector->base.base.id, connector->base.name);
     167                 :          0 :         drm_mode_debug_printmodeline(fixed_mode);
     168                 :            : 
     169                 :          0 :         info->width_mm = fixed_mode->width_mm;
     170                 :          0 :         info->height_mm = fixed_mode->height_mm;
     171                 :            : 
     172                 :          0 :         return fixed_mode;
     173                 :            : }
     174                 :            : 
     175                 :            : /* adjusted_mode has been preset to be the panel's fixed mode */
     176                 :            : void
     177                 :          0 : intel_pch_panel_fitting(struct intel_crtc *intel_crtc,
     178                 :            :                         struct intel_crtc_state *pipe_config,
     179                 :            :                         int fitting_mode)
     180                 :            : {
     181                 :          0 :         const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
     182                 :          0 :         int x = 0, y = 0, width = 0, height = 0;
     183                 :            : 
     184                 :            :         /* Native modes don't need fitting */
     185         [ #  # ]:          0 :         if (adjusted_mode->crtc_hdisplay == pipe_config->pipe_src_w &&
     186         [ #  # ]:          0 :             adjusted_mode->crtc_vdisplay == pipe_config->pipe_src_h &&
     187         [ #  # ]:          0 :             pipe_config->output_format != INTEL_OUTPUT_FORMAT_YCBCR420)
     188                 :          0 :                 goto done;
     189                 :            : 
     190   [ #  #  #  # ]:          0 :         switch (fitting_mode) {
     191                 :          0 :         case DRM_MODE_SCALE_CENTER:
     192                 :          0 :                 width = pipe_config->pipe_src_w;
     193                 :          0 :                 height = pipe_config->pipe_src_h;
     194                 :          0 :                 x = (adjusted_mode->crtc_hdisplay - width + 1)/2;
     195                 :          0 :                 y = (adjusted_mode->crtc_vdisplay - height + 1)/2;
     196                 :          0 :                 break;
     197                 :            : 
     198                 :          0 :         case DRM_MODE_SCALE_ASPECT:
     199                 :            :                 /* Scale but preserve the aspect ratio */
     200                 :            :                 {
     201                 :          0 :                         u32 scaled_width = adjusted_mode->crtc_hdisplay
     202                 :          0 :                                 * pipe_config->pipe_src_h;
     203                 :          0 :                         u32 scaled_height = pipe_config->pipe_src_w
     204                 :          0 :                                 * adjusted_mode->crtc_vdisplay;
     205         [ #  # ]:          0 :                         if (scaled_width > scaled_height) { /* pillar */
     206                 :          0 :                                 width = scaled_height / pipe_config->pipe_src_h;
     207         [ #  # ]:          0 :                                 if (width & 1)
     208                 :          0 :                                         width++;
     209                 :          0 :                                 x = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
     210                 :          0 :                                 y = 0;
     211                 :          0 :                                 height = adjusted_mode->crtc_vdisplay;
     212         [ #  # ]:          0 :                         } else if (scaled_width < scaled_height) { /* letter */
     213                 :          0 :                                 height = scaled_width / pipe_config->pipe_src_w;
     214         [ #  # ]:          0 :                                 if (height & 1)
     215                 :          0 :                                     height++;
     216                 :          0 :                                 y = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
     217                 :          0 :                                 x = 0;
     218                 :          0 :                                 width = adjusted_mode->crtc_hdisplay;
     219                 :            :                         } else {
     220                 :            :                                 x = y = 0;
     221                 :            :                                 width = adjusted_mode->crtc_hdisplay;
     222                 :            :                                 height = adjusted_mode->crtc_vdisplay;
     223                 :            :                         }
     224                 :            :                 }
     225                 :            :                 break;
     226                 :            : 
     227                 :          0 :         case DRM_MODE_SCALE_FULLSCREEN:
     228                 :          0 :                 x = y = 0;
     229                 :          0 :                 width = adjusted_mode->crtc_hdisplay;
     230                 :          0 :                 height = adjusted_mode->crtc_vdisplay;
     231                 :          0 :                 break;
     232                 :            : 
     233                 :            :         default:
     234                 :          0 :                 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
     235                 :          0 :                 return;
     236                 :            :         }
     237                 :            : 
     238                 :          0 : done:
     239                 :          0 :         pipe_config->pch_pfit.pos = (x << 16) | y;
     240                 :          0 :         pipe_config->pch_pfit.size = (width << 16) | height;
     241                 :          0 :         pipe_config->pch_pfit.enabled = pipe_config->pch_pfit.size != 0;
     242                 :            : }
     243                 :            : 
     244                 :            : static void
     245                 :          0 : centre_horizontally(struct drm_display_mode *adjusted_mode,
     246                 :            :                     int width)
     247                 :            : {
     248                 :          0 :         u32 border, sync_pos, blank_width, sync_width;
     249                 :            : 
     250                 :            :         /* keep the hsync and hblank widths constant */
     251                 :          0 :         sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
     252                 :          0 :         blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
     253                 :          0 :         sync_pos = (blank_width - sync_width + 1) / 2;
     254                 :            : 
     255                 :          0 :         border = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
     256                 :          0 :         border += border & 1; /* make the border even */
     257                 :            : 
     258                 :          0 :         adjusted_mode->crtc_hdisplay = width;
     259                 :          0 :         adjusted_mode->crtc_hblank_start = width + border;
     260                 :          0 :         adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width;
     261                 :            : 
     262                 :          0 :         adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos;
     263                 :          0 :         adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width;
     264                 :          0 : }
     265                 :            : 
     266                 :            : static void
     267                 :          0 : centre_vertically(struct drm_display_mode *adjusted_mode,
     268                 :            :                   int height)
     269                 :            : {
     270                 :          0 :         u32 border, sync_pos, blank_width, sync_width;
     271                 :            : 
     272                 :            :         /* keep the vsync and vblank widths constant */
     273                 :          0 :         sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
     274                 :          0 :         blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start;
     275                 :          0 :         sync_pos = (blank_width - sync_width + 1) / 2;
     276                 :            : 
     277                 :          0 :         border = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
     278                 :            : 
     279                 :          0 :         adjusted_mode->crtc_vdisplay = height;
     280                 :          0 :         adjusted_mode->crtc_vblank_start = height + border;
     281                 :          0 :         adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width;
     282                 :            : 
     283                 :          0 :         adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos;
     284                 :          0 :         adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width;
     285                 :            : }
     286                 :            : 
     287                 :          0 : static inline u32 panel_fitter_scaling(u32 source, u32 target)
     288                 :            : {
     289                 :            :         /*
     290                 :            :          * Floating point operation is not supported. So the FACTOR
     291                 :            :          * is defined, which can avoid the floating point computation
     292                 :            :          * when calculating the panel ratio.
     293                 :            :          */
     294                 :            : #define ACCURACY 12
     295                 :            : #define FACTOR (1 << ACCURACY)
     296                 :          0 :         u32 ratio = source * FACTOR / target;
     297                 :          0 :         return (FACTOR * ratio + FACTOR/2) / FACTOR;
     298                 :            : }
     299                 :            : 
     300                 :          0 : static void i965_scale_aspect(struct intel_crtc_state *pipe_config,
     301                 :            :                               u32 *pfit_control)
     302                 :            : {
     303                 :          0 :         const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
     304                 :          0 :         u32 scaled_width = adjusted_mode->crtc_hdisplay *
     305                 :          0 :                 pipe_config->pipe_src_h;
     306                 :          0 :         u32 scaled_height = pipe_config->pipe_src_w *
     307                 :          0 :                 adjusted_mode->crtc_vdisplay;
     308                 :            : 
     309                 :            :         /* 965+ is easy, it does everything in hw */
     310                 :          0 :         if (scaled_width > scaled_height)
     311                 :          0 :                 *pfit_control |= PFIT_ENABLE |
     312                 :            :                         PFIT_SCALING_PILLAR;
     313         [ #  # ]:          0 :         else if (scaled_width < scaled_height)
     314                 :          0 :                 *pfit_control |= PFIT_ENABLE |
     315                 :            :                         PFIT_SCALING_LETTER;
     316         [ #  # ]:          0 :         else if (adjusted_mode->crtc_hdisplay != pipe_config->pipe_src_w)
     317                 :          0 :                 *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
     318                 :            : }
     319                 :            : 
     320                 :          0 : static void i9xx_scale_aspect(struct intel_crtc_state *pipe_config,
     321                 :            :                               u32 *pfit_control, u32 *pfit_pgm_ratios,
     322                 :            :                               u32 *border)
     323                 :            : {
     324                 :          0 :         struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
     325                 :          0 :         u32 scaled_width = adjusted_mode->crtc_hdisplay *
     326                 :          0 :                 pipe_config->pipe_src_h;
     327                 :          0 :         u32 scaled_height = pipe_config->pipe_src_w *
     328                 :          0 :                 adjusted_mode->crtc_vdisplay;
     329                 :          0 :         u32 bits;
     330                 :            : 
     331                 :            :         /*
     332                 :            :          * For earlier chips we have to calculate the scaling
     333                 :            :          * ratio by hand and program it into the
     334                 :            :          * PFIT_PGM_RATIO register
     335                 :            :          */
     336         [ #  # ]:          0 :         if (scaled_width > scaled_height) { /* pillar */
     337                 :          0 :                 centre_horizontally(adjusted_mode,
     338                 :          0 :                                     scaled_height /
     339                 :          0 :                                     pipe_config->pipe_src_h);
     340                 :            : 
     341                 :          0 :                 *border = LVDS_BORDER_ENABLE;
     342         [ #  # ]:          0 :                 if (pipe_config->pipe_src_h != adjusted_mode->crtc_vdisplay) {
     343                 :          0 :                         bits = panel_fitter_scaling(pipe_config->pipe_src_h,
     344                 :            :                                                     adjusted_mode->crtc_vdisplay);
     345                 :            : 
     346                 :          0 :                         *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
     347                 :          0 :                                              bits << PFIT_VERT_SCALE_SHIFT);
     348                 :          0 :                         *pfit_control |= (PFIT_ENABLE |
     349                 :            :                                           VERT_INTERP_BILINEAR |
     350                 :            :                                           HORIZ_INTERP_BILINEAR);
     351                 :            :                 }
     352         [ #  # ]:          0 :         } else if (scaled_width < scaled_height) { /* letter */
     353                 :          0 :                 centre_vertically(adjusted_mode,
     354                 :          0 :                                   scaled_width /
     355                 :          0 :                                   pipe_config->pipe_src_w);
     356                 :            : 
     357                 :          0 :                 *border = LVDS_BORDER_ENABLE;
     358         [ #  # ]:          0 :                 if (pipe_config->pipe_src_w != adjusted_mode->crtc_hdisplay) {
     359                 :          0 :                         bits = panel_fitter_scaling(pipe_config->pipe_src_w,
     360                 :            :                                                     adjusted_mode->crtc_hdisplay);
     361                 :            : 
     362                 :          0 :                         *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
     363                 :          0 :                                              bits << PFIT_VERT_SCALE_SHIFT);
     364                 :          0 :                         *pfit_control |= (PFIT_ENABLE |
     365                 :            :                                           VERT_INTERP_BILINEAR |
     366                 :            :                                           HORIZ_INTERP_BILINEAR);
     367                 :            :                 }
     368                 :            :         } else {
     369                 :            :                 /* Aspects match, Let hw scale both directions */
     370                 :          0 :                 *pfit_control |= (PFIT_ENABLE |
     371                 :            :                                   VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
     372                 :            :                                   VERT_INTERP_BILINEAR |
     373                 :            :                                   HORIZ_INTERP_BILINEAR);
     374                 :            :         }
     375                 :          0 : }
     376                 :            : 
     377                 :          0 : void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc,
     378                 :            :                               struct intel_crtc_state *pipe_config,
     379                 :            :                               int fitting_mode)
     380                 :            : {
     381         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
     382                 :          0 :         u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
     383                 :          0 :         struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
     384                 :            : 
     385                 :            :         /* Native modes don't need fitting */
     386         [ #  # ]:          0 :         if (adjusted_mode->crtc_hdisplay == pipe_config->pipe_src_w &&
     387         [ #  # ]:          0 :             adjusted_mode->crtc_vdisplay == pipe_config->pipe_src_h)
     388                 :          0 :                 goto out;
     389                 :            : 
     390   [ #  #  #  # ]:          0 :         switch (fitting_mode) {
     391                 :          0 :         case DRM_MODE_SCALE_CENTER:
     392                 :            :                 /*
     393                 :            :                  * For centered modes, we have to calculate border widths &
     394                 :            :                  * heights and modify the values programmed into the CRTC.
     395                 :            :                  */
     396                 :          0 :                 centre_horizontally(adjusted_mode, pipe_config->pipe_src_w);
     397                 :          0 :                 centre_vertically(adjusted_mode, pipe_config->pipe_src_h);
     398                 :          0 :                 border = LVDS_BORDER_ENABLE;
     399                 :          0 :                 break;
     400                 :          0 :         case DRM_MODE_SCALE_ASPECT:
     401                 :            :                 /* Scale but preserve the aspect ratio */
     402         [ #  # ]:          0 :                 if (INTEL_GEN(dev_priv) >= 4)
     403         [ #  # ]:          0 :                         i965_scale_aspect(pipe_config, &pfit_control);
     404                 :            :                 else
     405                 :          0 :                         i9xx_scale_aspect(pipe_config, &pfit_control,
     406                 :            :                                           &pfit_pgm_ratios, &border);
     407                 :            :                 break;
     408                 :          0 :         case DRM_MODE_SCALE_FULLSCREEN:
     409                 :            :                 /*
     410                 :            :                  * Full scaling, even if it changes the aspect ratio.
     411                 :            :                  * Fortunately this is all done for us in hw.
     412                 :            :                  */
     413   [ #  #  #  # ]:          0 :                 if (pipe_config->pipe_src_h != adjusted_mode->crtc_vdisplay ||
     414                 :            :                     pipe_config->pipe_src_w != adjusted_mode->crtc_hdisplay) {
     415                 :          0 :                         pfit_control |= PFIT_ENABLE;
     416         [ #  # ]:          0 :                         if (INTEL_GEN(dev_priv) >= 4)
     417                 :            :                                 pfit_control |= PFIT_SCALING_AUTO;
     418                 :            :                         else
     419                 :          0 :                                 pfit_control |= (VERT_AUTO_SCALE |
     420                 :            :                                                  VERT_INTERP_BILINEAR |
     421                 :            :                                                  HORIZ_AUTO_SCALE |
     422                 :            :                                                  HORIZ_INTERP_BILINEAR);
     423                 :            :                 }
     424                 :            :                 break;
     425                 :            :         default:
     426                 :          0 :                 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
     427                 :          0 :                 return;
     428                 :            :         }
     429                 :            : 
     430                 :            :         /* 965+ wants fuzzy fitting */
     431                 :            :         /* FIXME: handle multiple panels by failing gracefully */
     432         [ #  # ]:          0 :         if (INTEL_GEN(dev_priv) >= 4)
     433                 :          0 :                 pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
     434                 :            :                                  PFIT_FILTER_FUZZY);
     435                 :            : 
     436                 :          0 : out:
     437         [ #  # ]:          0 :         if ((pfit_control & PFIT_ENABLE) == 0) {
     438                 :          0 :                 pfit_control = 0;
     439                 :          0 :                 pfit_pgm_ratios = 0;
     440                 :            :         }
     441                 :            : 
     442                 :            :         /* Make sure pre-965 set dither correctly for 18bpp panels. */
     443   [ #  #  #  # ]:          0 :         if (INTEL_GEN(dev_priv) < 4 && pipe_config->pipe_bpp == 18)
     444                 :          0 :                 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
     445                 :            : 
     446                 :          0 :         pipe_config->gmch_pfit.control = pfit_control;
     447                 :          0 :         pipe_config->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
     448                 :          0 :         pipe_config->gmch_pfit.lvds_border_bits = border;
     449                 :            : }
     450                 :            : 
     451                 :            : /**
     452                 :            :  * scale - scale values from one range to another
     453                 :            :  * @source_val: value in range [@source_min..@source_max]
     454                 :            :  * @source_min: minimum legal value for @source_val
     455                 :            :  * @source_max: maximum legal value for @source_val
     456                 :            :  * @target_min: corresponding target value for @source_min
     457                 :            :  * @target_max: corresponding target value for @source_max
     458                 :            :  *
     459                 :            :  * Return @source_val in range [@source_min..@source_max] scaled to range
     460                 :            :  * [@target_min..@target_max].
     461                 :            :  */
     462                 :          0 : static u32 scale(u32 source_val,
     463                 :            :                  u32 source_min, u32 source_max,
     464                 :            :                  u32 target_min, u32 target_max)
     465                 :            : {
     466                 :          0 :         u64 target_val;
     467                 :            : 
     468         [ #  # ]:          0 :         WARN_ON(source_min > source_max);
     469         [ #  # ]:          0 :         WARN_ON(target_min > target_max);
     470                 :            : 
     471                 :            :         /* defensive */
     472                 :          0 :         source_val = clamp(source_val, source_min, source_max);
     473                 :            : 
     474                 :            :         /* avoid overflows */
     475                 :          0 :         target_val = mul_u32_u32(source_val - source_min,
     476                 :            :                                  target_max - target_min);
     477                 :          0 :         target_val = DIV_ROUND_CLOSEST_ULL(target_val, source_max - source_min);
     478                 :          0 :         target_val += target_min;
     479                 :            : 
     480                 :          0 :         return target_val;
     481                 :            : }
     482                 :            : 
     483                 :            : /* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */
     484                 :          0 : static inline u32 scale_user_to_hw(struct intel_connector *connector,
     485                 :            :                                    u32 user_level, u32 user_max)
     486                 :            : {
     487                 :          0 :         struct intel_panel *panel = &connector->panel;
     488                 :            : 
     489                 :          0 :         return scale(user_level, 0, user_max,
     490                 :            :                      panel->backlight.min, panel->backlight.max);
     491                 :            : }
     492                 :            : 
     493                 :            : /* Scale user_level in range [0..user_max] to [0..hw_max], clamping the result
     494                 :            :  * to [hw_min..hw_max]. */
     495                 :          0 : static inline u32 clamp_user_to_hw(struct intel_connector *connector,
     496                 :            :                                    u32 user_level, u32 user_max)
     497                 :            : {
     498                 :          0 :         struct intel_panel *panel = &connector->panel;
     499                 :          0 :         u32 hw_level;
     500                 :            : 
     501                 :          0 :         hw_level = scale(user_level, 0, user_max, 0, panel->backlight.max);
     502                 :          0 :         hw_level = clamp(hw_level, panel->backlight.min, panel->backlight.max);
     503                 :            : 
     504                 :          0 :         return hw_level;
     505                 :            : }
     506                 :            : 
     507                 :            : /* Scale hw_level in range [hw_min..hw_max] to [0..user_max]. */
     508                 :          0 : static inline u32 scale_hw_to_user(struct intel_connector *connector,
     509                 :            :                                    u32 hw_level, u32 user_max)
     510                 :            : {
     511                 :          0 :         struct intel_panel *panel = &connector->panel;
     512                 :            : 
     513                 :          0 :         return scale(hw_level, panel->backlight.min, panel->backlight.max,
     514                 :            :                      0, user_max);
     515                 :            : }
     516                 :            : 
     517                 :          0 : static u32 intel_panel_compute_brightness(struct intel_connector *connector,
     518                 :            :                                           u32 val)
     519                 :            : {
     520         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     521                 :          0 :         struct intel_panel *panel = &connector->panel;
     522                 :            : 
     523         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
     524                 :            : 
     525         [ #  # ]:          0 :         if (i915_modparams.invert_brightness < 0)
     526                 :            :                 return val;
     527                 :            : 
     528         [ #  # ]:          0 :         if (i915_modparams.invert_brightness > 0 ||
     529         [ #  # ]:          0 :             dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) {
     530                 :          0 :                 return panel->backlight.max - val + panel->backlight.min;
     531                 :            :         }
     532                 :            : 
     533                 :            :         return val;
     534                 :            : }
     535                 :            : 
     536                 :          0 : static u32 lpt_get_backlight(struct intel_connector *connector)
     537                 :            : {
     538                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     539                 :            : 
     540                 :          0 :         return I915_READ(BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK;
     541                 :            : }
     542                 :            : 
     543                 :          0 : static u32 pch_get_backlight(struct intel_connector *connector)
     544                 :            : {
     545                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     546                 :            : 
     547                 :          0 :         return I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
     548                 :            : }
     549                 :            : 
     550                 :          0 : static u32 i9xx_get_backlight(struct intel_connector *connector)
     551                 :            : {
     552                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     553                 :          0 :         struct intel_panel *panel = &connector->panel;
     554                 :          0 :         u32 val;
     555                 :            : 
     556                 :          0 :         val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
     557         [ #  # ]:          0 :         if (INTEL_GEN(dev_priv) < 4)
     558                 :          0 :                 val >>= 1;
     559                 :            : 
     560         [ #  # ]:          0 :         if (panel->backlight.combination_mode) {
     561                 :          0 :                 u8 lbpc;
     562                 :            : 
     563                 :          0 :                 pci_read_config_byte(dev_priv->drm.pdev, LBPC, &lbpc);
     564                 :          0 :                 val *= lbpc;
     565                 :            :         }
     566                 :            : 
     567                 :          0 :         return val;
     568                 :            : }
     569                 :            : 
     570                 :          0 : static u32 _vlv_get_backlight(struct drm_i915_private *dev_priv, enum pipe pipe)
     571                 :            : {
     572   [ #  #  #  # ]:          0 :         if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
     573                 :            :                 return 0;
     574                 :            : 
     575                 :          0 :         return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK;
     576                 :            : }
     577                 :            : 
     578                 :          0 : static u32 vlv_get_backlight(struct intel_connector *connector)
     579                 :            : {
     580                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     581                 :          0 :         enum pipe pipe = intel_connector_get_pipe(connector);
     582                 :            : 
     583                 :          0 :         return _vlv_get_backlight(dev_priv, pipe);
     584                 :            : }
     585                 :            : 
     586                 :          0 : static u32 bxt_get_backlight(struct intel_connector *connector)
     587                 :            : {
     588                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     589                 :          0 :         struct intel_panel *panel = &connector->panel;
     590                 :            : 
     591                 :          0 :         return I915_READ(BXT_BLC_PWM_DUTY(panel->backlight.controller));
     592                 :            : }
     593                 :            : 
     594                 :          0 : static u32 pwm_get_backlight(struct intel_connector *connector)
     595                 :            : {
     596                 :          0 :         struct intel_panel *panel = &connector->panel;
     597                 :          0 :         int duty_ns;
     598                 :            : 
     599                 :          0 :         duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
     600                 :          0 :         return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
     601                 :            : }
     602                 :            : 
     603                 :          0 : static void lpt_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     604                 :            : {
     605                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     606                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     607                 :            : 
     608                 :          0 :         u32 val = I915_READ(BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK;
     609                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL2, val | level);
     610                 :          0 : }
     611                 :            : 
     612                 :          0 : static void pch_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     613                 :            : {
     614                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     615                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     616                 :          0 :         u32 tmp;
     617                 :            : 
     618                 :          0 :         tmp = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
     619                 :          0 :         I915_WRITE(BLC_PWM_CPU_CTL, tmp | level);
     620                 :          0 : }
     621                 :            : 
     622                 :          0 : static void i9xx_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     623                 :            : {
     624                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     625         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     626                 :          0 :         struct intel_panel *panel = &connector->panel;
     627                 :          0 :         u32 tmp, mask;
     628                 :            : 
     629         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
     630                 :            : 
     631         [ #  # ]:          0 :         if (panel->backlight.combination_mode) {
     632                 :          0 :                 u8 lbpc;
     633                 :            : 
     634                 :          0 :                 lbpc = level * 0xfe / panel->backlight.max + 1;
     635                 :          0 :                 level /= lbpc;
     636                 :          0 :                 pci_write_config_byte(dev_priv->drm.pdev, LBPC, lbpc);
     637                 :            :         }
     638                 :            : 
     639         [ #  # ]:          0 :         if (IS_GEN(dev_priv, 4)) {
     640                 :            :                 mask = BACKLIGHT_DUTY_CYCLE_MASK;
     641                 :            :         } else {
     642                 :          0 :                 level <<= 1;
     643                 :          0 :                 mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV;
     644                 :            :         }
     645                 :            : 
     646                 :          0 :         tmp = I915_READ(BLC_PWM_CTL) & ~mask;
     647                 :          0 :         I915_WRITE(BLC_PWM_CTL, tmp | level);
     648                 :          0 : }
     649                 :            : 
     650                 :          0 : static void vlv_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     651                 :            : {
     652                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     653                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     654                 :          0 :         enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe;
     655                 :          0 :         u32 tmp;
     656                 :            : 
     657                 :          0 :         tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK;
     658                 :          0 :         I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
     659                 :          0 : }
     660                 :            : 
     661                 :          0 : static void bxt_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     662                 :            : {
     663                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     664                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     665                 :          0 :         struct intel_panel *panel = &connector->panel;
     666                 :            : 
     667                 :          0 :         I915_WRITE(BXT_BLC_PWM_DUTY(panel->backlight.controller), level);
     668                 :          0 : }
     669                 :            : 
     670                 :          0 : static void pwm_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     671                 :            : {
     672                 :          0 :         struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel;
     673                 :          0 :         int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
     674                 :            : 
     675                 :          0 :         pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
     676                 :          0 : }
     677                 :            : 
     678                 :            : static void
     679                 :          0 : intel_panel_actually_set_backlight(const struct drm_connector_state *conn_state, u32 level)
     680                 :            : {
     681                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     682                 :          0 :         struct intel_panel *panel = &connector->panel;
     683                 :            : 
     684                 :          0 :         DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level);
     685                 :            : 
     686                 :          0 :         level = intel_panel_compute_brightness(connector, level);
     687                 :          0 :         panel->backlight.set(conn_state, level);
     688                 :          0 : }
     689                 :            : 
     690                 :            : /* set backlight brightness to level in range [0..max], assuming hw min is
     691                 :            :  * respected.
     692                 :            :  */
     693                 :          0 : void intel_panel_set_backlight_acpi(const struct drm_connector_state *conn_state,
     694                 :            :                                     u32 user_level, u32 user_max)
     695                 :            : {
     696                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     697         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     698                 :          0 :         struct intel_panel *panel = &connector->panel;
     699                 :          0 :         u32 hw_level;
     700                 :            : 
     701                 :            :         /*
     702                 :            :          * Lack of crtc may occur during driver init because
     703                 :            :          * connection_mutex isn't held across the entire backlight
     704                 :            :          * setup + modeset readout, and the BIOS can issue the
     705                 :            :          * requests at any time.
     706                 :            :          */
     707   [ #  #  #  # ]:          0 :         if (!panel->backlight.present || !conn_state->crtc)
     708                 :            :                 return;
     709                 :            : 
     710                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
     711                 :            : 
     712         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
     713                 :            : 
     714                 :          0 :         hw_level = clamp_user_to_hw(connector, user_level, user_max);
     715                 :          0 :         panel->backlight.level = hw_level;
     716                 :            : 
     717         [ #  # ]:          0 :         if (panel->backlight.device)
     718                 :          0 :                 panel->backlight.device->props.brightness =
     719                 :          0 :                         scale_hw_to_user(connector,
     720                 :            :                                          panel->backlight.level,
     721                 :          0 :                                          panel->backlight.device->props.max_brightness);
     722                 :            : 
     723         [ #  # ]:          0 :         if (panel->backlight.enabled)
     724                 :          0 :                 intel_panel_actually_set_backlight(conn_state, hw_level);
     725                 :            : 
     726                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
     727                 :            : }
     728                 :            : 
     729                 :          0 : static void lpt_disable_backlight(const struct drm_connector_state *old_conn_state)
     730                 :            : {
     731                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     732                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     733                 :          0 :         u32 tmp;
     734                 :            : 
     735                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     736                 :            : 
     737                 :            :         /*
     738                 :            :          * Although we don't support or enable CPU PWM with LPT/SPT based
     739                 :            :          * systems, it may have been enabled prior to loading the
     740                 :            :          * driver. Disable to avoid warnings on LCPLL disable.
     741                 :            :          *
     742                 :            :          * This needs rework if we need to add support for CPU PWM on PCH split
     743                 :            :          * platforms.
     744                 :            :          */
     745                 :          0 :         tmp = I915_READ(BLC_PWM_CPU_CTL2);
     746         [ #  # ]:          0 :         if (tmp & BLM_PWM_ENABLE) {
     747                 :          0 :                 DRM_DEBUG_KMS("cpu backlight was enabled, disabling\n");
     748                 :          0 :                 I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE);
     749                 :            :         }
     750                 :            : 
     751                 :          0 :         tmp = I915_READ(BLC_PWM_PCH_CTL1);
     752                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE);
     753                 :          0 : }
     754                 :            : 
     755                 :          0 : static void pch_disable_backlight(const struct drm_connector_state *old_conn_state)
     756                 :            : {
     757                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     758                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     759                 :          0 :         u32 tmp;
     760                 :            : 
     761                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     762                 :            : 
     763                 :          0 :         tmp = I915_READ(BLC_PWM_CPU_CTL2);
     764                 :          0 :         I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE);
     765                 :            : 
     766                 :          0 :         tmp = I915_READ(BLC_PWM_PCH_CTL1);
     767                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE);
     768                 :          0 : }
     769                 :            : 
     770                 :          0 : static void i9xx_disable_backlight(const struct drm_connector_state *old_conn_state)
     771                 :            : {
     772                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     773                 :          0 : }
     774                 :            : 
     775                 :          0 : static void i965_disable_backlight(const struct drm_connector_state *old_conn_state)
     776                 :            : {
     777                 :          0 :         struct drm_i915_private *dev_priv = to_i915(old_conn_state->connector->dev);
     778                 :          0 :         u32 tmp;
     779                 :            : 
     780                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     781                 :            : 
     782                 :          0 :         tmp = I915_READ(BLC_PWM_CTL2);
     783                 :          0 :         I915_WRITE(BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE);
     784                 :          0 : }
     785                 :            : 
     786                 :          0 : static void vlv_disable_backlight(const struct drm_connector_state *old_conn_state)
     787                 :            : {
     788                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     789                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     790                 :          0 :         enum pipe pipe = to_intel_crtc(old_conn_state->crtc)->pipe;
     791                 :          0 :         u32 tmp;
     792                 :            : 
     793                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     794                 :            : 
     795                 :          0 :         tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe));
     796                 :          0 :         I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
     797                 :          0 : }
     798                 :            : 
     799                 :          0 : static void bxt_disable_backlight(const struct drm_connector_state *old_conn_state)
     800                 :            : {
     801                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     802                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     803                 :          0 :         struct intel_panel *panel = &connector->panel;
     804                 :          0 :         u32 tmp, val;
     805                 :            : 
     806                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     807                 :            : 
     808                 :          0 :         tmp = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
     809                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
     810                 :            :                         tmp & ~BXT_BLC_PWM_ENABLE);
     811                 :            : 
     812         [ #  # ]:          0 :         if (panel->backlight.controller == 1) {
     813                 :          0 :                 val = I915_READ(UTIL_PIN_CTL);
     814                 :          0 :                 val &= ~UTIL_PIN_ENABLE;
     815                 :          0 :                 I915_WRITE(UTIL_PIN_CTL, val);
     816                 :            :         }
     817                 :          0 : }
     818                 :            : 
     819                 :          0 : static void cnp_disable_backlight(const struct drm_connector_state *old_conn_state)
     820                 :            : {
     821                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     822                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     823                 :          0 :         struct intel_panel *panel = &connector->panel;
     824                 :          0 :         u32 tmp;
     825                 :            : 
     826                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     827                 :            : 
     828                 :          0 :         tmp = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
     829                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
     830                 :            :                    tmp & ~BXT_BLC_PWM_ENABLE);
     831                 :          0 : }
     832                 :            : 
     833                 :          0 : static void pwm_disable_backlight(const struct drm_connector_state *old_conn_state)
     834                 :            : {
     835                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     836                 :          0 :         struct intel_panel *panel = &connector->panel;
     837                 :            : 
     838                 :            :         /* Disable the backlight */
     839                 :          0 :         intel_panel_actually_set_backlight(old_conn_state, 0);
     840                 :          0 :         usleep_range(2000, 3000);
     841                 :          0 :         pwm_disable(panel->backlight.pwm);
     842                 :          0 : }
     843                 :            : 
     844                 :          0 : void intel_panel_disable_backlight(const struct drm_connector_state *old_conn_state)
     845                 :            : {
     846                 :          0 :         struct intel_connector *connector = to_intel_connector(old_conn_state->connector);
     847         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     848                 :          0 :         struct intel_panel *panel = &connector->panel;
     849                 :            : 
     850         [ #  # ]:          0 :         if (!panel->backlight.present)
     851                 :            :                 return;
     852                 :            : 
     853                 :            :         /*
     854                 :            :          * Do not disable backlight on the vga_switcheroo path. When switching
     855                 :            :          * away from i915, the other client may depend on i915 to handle the
     856                 :            :          * backlight. This will leave the backlight on unnecessarily when
     857                 :            :          * another client is not activated.
     858                 :            :          */
     859         [ #  # ]:          0 :         if (dev_priv->drm.switch_power_state == DRM_SWITCH_POWER_CHANGING) {
     860                 :          0 :                 DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
     861                 :          0 :                 return;
     862                 :            :         }
     863                 :            : 
     864                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
     865                 :            : 
     866         [ #  # ]:          0 :         if (panel->backlight.device)
     867                 :          0 :                 panel->backlight.device->props.power = FB_BLANK_POWERDOWN;
     868                 :          0 :         panel->backlight.enabled = false;
     869                 :          0 :         panel->backlight.disable(old_conn_state);
     870                 :            : 
     871                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
     872                 :            : }
     873                 :            : 
     874                 :          0 : static void lpt_enable_backlight(const struct intel_crtc_state *crtc_state,
     875                 :            :                                  const struct drm_connector_state *conn_state)
     876                 :            : {
     877                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     878                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     879                 :          0 :         struct intel_panel *panel = &connector->panel;
     880                 :          0 :         u32 pch_ctl1, pch_ctl2, schicken;
     881                 :            : 
     882                 :          0 :         pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
     883         [ #  # ]:          0 :         if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
     884                 :          0 :                 DRM_DEBUG_KMS("pch backlight already enabled\n");
     885                 :          0 :                 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
     886                 :          0 :                 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
     887                 :            :         }
     888                 :            : 
     889         [ #  # ]:          0 :         if (HAS_PCH_LPT(dev_priv)) {
     890                 :          0 :                 schicken = I915_READ(SOUTH_CHICKEN2);
     891         [ #  # ]:          0 :                 if (panel->backlight.alternate_pwm_increment)
     892                 :          0 :                         schicken |= LPT_PWM_GRANULARITY;
     893                 :            :                 else
     894                 :          0 :                         schicken &= ~LPT_PWM_GRANULARITY;
     895                 :          0 :                 I915_WRITE(SOUTH_CHICKEN2, schicken);
     896                 :            :         } else {
     897                 :          0 :                 schicken = I915_READ(SOUTH_CHICKEN1);
     898         [ #  # ]:          0 :                 if (panel->backlight.alternate_pwm_increment)
     899                 :          0 :                         schicken |= SPT_PWM_GRANULARITY;
     900                 :            :                 else
     901                 :          0 :                         schicken &= ~SPT_PWM_GRANULARITY;
     902                 :          0 :                 I915_WRITE(SOUTH_CHICKEN1, schicken);
     903                 :            :         }
     904                 :            : 
     905                 :          0 :         pch_ctl2 = panel->backlight.max << 16;
     906                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
     907                 :            : 
     908                 :          0 :         pch_ctl1 = 0;
     909         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
     910                 :          0 :                 pch_ctl1 |= BLM_PCH_POLARITY;
     911                 :            : 
     912                 :            :         /* After LPT, override is the default. */
     913         [ #  # ]:          0 :         if (HAS_PCH_LPT(dev_priv))
     914                 :          0 :                 pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE;
     915                 :            : 
     916                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
     917                 :          0 :         POSTING_READ(BLC_PWM_PCH_CTL1);
     918                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
     919                 :            : 
     920                 :            :         /* This won't stick until the above enable. */
     921                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
     922                 :          0 : }
     923                 :            : 
     924                 :          0 : static void pch_enable_backlight(const struct intel_crtc_state *crtc_state,
     925                 :            :                                  const struct drm_connector_state *conn_state)
     926                 :            : {
     927                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     928                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     929                 :          0 :         struct intel_panel *panel = &connector->panel;
     930                 :          0 :         enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
     931                 :          0 :         u32 cpu_ctl2, pch_ctl1, pch_ctl2;
     932                 :            : 
     933                 :          0 :         cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
     934         [ #  # ]:          0 :         if (cpu_ctl2 & BLM_PWM_ENABLE) {
     935                 :          0 :                 DRM_DEBUG_KMS("cpu backlight already enabled\n");
     936                 :          0 :                 cpu_ctl2 &= ~BLM_PWM_ENABLE;
     937                 :          0 :                 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
     938                 :            :         }
     939                 :            : 
     940                 :          0 :         pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
     941         [ #  # ]:          0 :         if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
     942                 :          0 :                 DRM_DEBUG_KMS("pch backlight already enabled\n");
     943                 :          0 :                 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
     944                 :          0 :                 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
     945                 :            :         }
     946                 :            : 
     947         [ #  # ]:          0 :         if (cpu_transcoder == TRANSCODER_EDP)
     948                 :            :                 cpu_ctl2 = BLM_TRANSCODER_EDP;
     949                 :            :         else
     950                 :          0 :                 cpu_ctl2 = BLM_PIPE(cpu_transcoder);
     951                 :          0 :         I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
     952                 :          0 :         POSTING_READ(BLC_PWM_CPU_CTL2);
     953                 :          0 :         I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE);
     954                 :            : 
     955                 :            :         /* This won't stick until the above enable. */
     956                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
     957                 :            : 
     958                 :          0 :         pch_ctl2 = panel->backlight.max << 16;
     959                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
     960                 :            : 
     961                 :          0 :         pch_ctl1 = 0;
     962         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
     963                 :          0 :                 pch_ctl1 |= BLM_PCH_POLARITY;
     964                 :            : 
     965                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
     966                 :          0 :         POSTING_READ(BLC_PWM_PCH_CTL1);
     967                 :          0 :         I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
     968                 :          0 : }
     969                 :            : 
     970                 :          0 : static void i9xx_enable_backlight(const struct intel_crtc_state *crtc_state,
     971                 :            :                                   const struct drm_connector_state *conn_state)
     972                 :            : {
     973                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
     974                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
     975                 :          0 :         struct intel_panel *panel = &connector->panel;
     976                 :          0 :         u32 ctl, freq;
     977                 :            : 
     978                 :          0 :         ctl = I915_READ(BLC_PWM_CTL);
     979         [ #  # ]:          0 :         if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) {
     980                 :          0 :                 DRM_DEBUG_KMS("backlight already enabled\n");
     981                 :          0 :                 I915_WRITE(BLC_PWM_CTL, 0);
     982                 :            :         }
     983                 :            : 
     984                 :          0 :         freq = panel->backlight.max;
     985         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
     986                 :          0 :                 freq /= 0xff;
     987                 :            : 
     988                 :          0 :         ctl = freq << 17;
     989         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
     990                 :          0 :                 ctl |= BLM_LEGACY_MODE;
     991   [ #  #  #  # ]:          0 :         if (IS_PINEVIEW(dev_priv) && panel->backlight.active_low_pwm)
     992                 :          0 :                 ctl |= BLM_POLARITY_PNV;
     993                 :            : 
     994                 :          0 :         I915_WRITE(BLC_PWM_CTL, ctl);
     995                 :          0 :         POSTING_READ(BLC_PWM_CTL);
     996                 :            : 
     997                 :            :         /* XXX: combine this into above write? */
     998                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
     999                 :            : 
    1000                 :            :         /*
    1001                 :            :          * Needed to enable backlight on some 855gm models. BLC_HIST_CTL is
    1002                 :            :          * 855gm only, but checking for gen2 is safe, as 855gm is the only gen2
    1003                 :            :          * that has backlight.
    1004                 :            :          */
    1005         [ #  # ]:          0 :         if (IS_GEN(dev_priv, 2))
    1006                 :          0 :                 I915_WRITE(BLC_HIST_CTL, BLM_HISTOGRAM_ENABLE);
    1007                 :          0 : }
    1008                 :            : 
    1009                 :          0 : static void i965_enable_backlight(const struct intel_crtc_state *crtc_state,
    1010                 :            :                                   const struct drm_connector_state *conn_state)
    1011                 :            : {
    1012                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1013                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1014                 :          0 :         struct intel_panel *panel = &connector->panel;
    1015                 :          0 :         enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe;
    1016                 :          0 :         u32 ctl, ctl2, freq;
    1017                 :            : 
    1018                 :          0 :         ctl2 = I915_READ(BLC_PWM_CTL2);
    1019         [ #  # ]:          0 :         if (ctl2 & BLM_PWM_ENABLE) {
    1020                 :          0 :                 DRM_DEBUG_KMS("backlight already enabled\n");
    1021                 :          0 :                 ctl2 &= ~BLM_PWM_ENABLE;
    1022                 :          0 :                 I915_WRITE(BLC_PWM_CTL2, ctl2);
    1023                 :            :         }
    1024                 :            : 
    1025                 :          0 :         freq = panel->backlight.max;
    1026         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
    1027                 :          0 :                 freq /= 0xff;
    1028                 :            : 
    1029                 :          0 :         ctl = freq << 16;
    1030                 :          0 :         I915_WRITE(BLC_PWM_CTL, ctl);
    1031                 :            : 
    1032                 :          0 :         ctl2 = BLM_PIPE(pipe);
    1033         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
    1034                 :          0 :                 ctl2 |= BLM_COMBINATION_MODE;
    1035         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
    1036                 :          0 :                 ctl2 |= BLM_POLARITY_I965;
    1037                 :          0 :         I915_WRITE(BLC_PWM_CTL2, ctl2);
    1038                 :          0 :         POSTING_READ(BLC_PWM_CTL2);
    1039                 :          0 :         I915_WRITE(BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE);
    1040                 :            : 
    1041                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
    1042                 :          0 : }
    1043                 :            : 
    1044                 :          0 : static void vlv_enable_backlight(const struct intel_crtc_state *crtc_state,
    1045                 :            :                                  const struct drm_connector_state *conn_state)
    1046                 :            : {
    1047                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1048                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1049                 :          0 :         struct intel_panel *panel = &connector->panel;
    1050                 :          0 :         enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe;
    1051                 :          0 :         u32 ctl, ctl2;
    1052                 :            : 
    1053                 :          0 :         ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
    1054         [ #  # ]:          0 :         if (ctl2 & BLM_PWM_ENABLE) {
    1055                 :          0 :                 DRM_DEBUG_KMS("backlight already enabled\n");
    1056                 :          0 :                 ctl2 &= ~BLM_PWM_ENABLE;
    1057                 :          0 :                 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
    1058                 :            :         }
    1059                 :            : 
    1060                 :          0 :         ctl = panel->backlight.max << 16;
    1061                 :          0 :         I915_WRITE(VLV_BLC_PWM_CTL(pipe), ctl);
    1062                 :            : 
    1063                 :            :         /* XXX: combine this into above write? */
    1064                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
    1065                 :            : 
    1066                 :          0 :         ctl2 = 0;
    1067         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
    1068                 :          0 :                 ctl2 |= BLM_POLARITY_I965;
    1069                 :          0 :         I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
    1070                 :          0 :         POSTING_READ(VLV_BLC_PWM_CTL2(pipe));
    1071                 :          0 :         I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
    1072                 :          0 : }
    1073                 :            : 
    1074                 :          0 : static void bxt_enable_backlight(const struct intel_crtc_state *crtc_state,
    1075                 :            :                                  const struct drm_connector_state *conn_state)
    1076                 :            : {
    1077                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1078         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1079                 :          0 :         struct intel_panel *panel = &connector->panel;
    1080                 :          0 :         enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe;
    1081                 :          0 :         u32 pwm_ctl, val;
    1082                 :            : 
    1083                 :            :         /* Controller 1 uses the utility pin. */
    1084         [ #  # ]:          0 :         if (panel->backlight.controller == 1) {
    1085                 :          0 :                 val = I915_READ(UTIL_PIN_CTL);
    1086         [ #  # ]:          0 :                 if (val & UTIL_PIN_ENABLE) {
    1087                 :          0 :                         DRM_DEBUG_KMS("util pin already enabled\n");
    1088                 :          0 :                         val &= ~UTIL_PIN_ENABLE;
    1089                 :          0 :                         I915_WRITE(UTIL_PIN_CTL, val);
    1090                 :            :                 }
    1091                 :            : 
    1092                 :          0 :                 val = 0;
    1093         [ #  # ]:          0 :                 if (panel->backlight.util_pin_active_low)
    1094                 :          0 :                         val |= UTIL_PIN_POLARITY;
    1095                 :          0 :                 I915_WRITE(UTIL_PIN_CTL, val | UTIL_PIN_PIPE(pipe) |
    1096                 :            :                                 UTIL_PIN_MODE_PWM | UTIL_PIN_ENABLE);
    1097                 :            :         }
    1098                 :            : 
    1099                 :          0 :         pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1100         [ #  # ]:          0 :         if (pwm_ctl & BXT_BLC_PWM_ENABLE) {
    1101                 :          0 :                 DRM_DEBUG_KMS("backlight already enabled\n");
    1102                 :          0 :                 pwm_ctl &= ~BXT_BLC_PWM_ENABLE;
    1103                 :          0 :                 I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
    1104                 :            :                                 pwm_ctl);
    1105                 :            :         }
    1106                 :            : 
    1107                 :          0 :         I915_WRITE(BXT_BLC_PWM_FREQ(panel->backlight.controller),
    1108                 :            :                         panel->backlight.max);
    1109                 :            : 
    1110                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
    1111                 :            : 
    1112                 :          0 :         pwm_ctl = 0;
    1113         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
    1114                 :          0 :                 pwm_ctl |= BXT_BLC_PWM_POLARITY;
    1115                 :            : 
    1116                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), pwm_ctl);
    1117                 :          0 :         POSTING_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1118                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
    1119                 :            :                         pwm_ctl | BXT_BLC_PWM_ENABLE);
    1120                 :          0 : }
    1121                 :            : 
    1122                 :          0 : static void cnp_enable_backlight(const struct intel_crtc_state *crtc_state,
    1123                 :            :                                  const struct drm_connector_state *conn_state)
    1124                 :            : {
    1125                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1126                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1127                 :          0 :         struct intel_panel *panel = &connector->panel;
    1128                 :          0 :         u32 pwm_ctl;
    1129                 :            : 
    1130                 :          0 :         pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1131         [ #  # ]:          0 :         if (pwm_ctl & BXT_BLC_PWM_ENABLE) {
    1132                 :          0 :                 DRM_DEBUG_KMS("backlight already enabled\n");
    1133                 :          0 :                 pwm_ctl &= ~BXT_BLC_PWM_ENABLE;
    1134                 :          0 :                 I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
    1135                 :            :                            pwm_ctl);
    1136                 :            :         }
    1137                 :            : 
    1138                 :          0 :         I915_WRITE(BXT_BLC_PWM_FREQ(panel->backlight.controller),
    1139                 :            :                    panel->backlight.max);
    1140                 :            : 
    1141                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
    1142                 :            : 
    1143                 :          0 :         pwm_ctl = 0;
    1144         [ #  # ]:          0 :         if (panel->backlight.active_low_pwm)
    1145                 :          0 :                 pwm_ctl |= BXT_BLC_PWM_POLARITY;
    1146                 :            : 
    1147                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), pwm_ctl);
    1148                 :          0 :         POSTING_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1149                 :          0 :         I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller),
    1150                 :            :                    pwm_ctl | BXT_BLC_PWM_ENABLE);
    1151                 :          0 : }
    1152                 :            : 
    1153                 :          0 : static void pwm_enable_backlight(const struct intel_crtc_state *crtc_state,
    1154                 :            :                                  const struct drm_connector_state *conn_state)
    1155                 :            : {
    1156                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1157                 :          0 :         struct intel_panel *panel = &connector->panel;
    1158                 :            : 
    1159                 :          0 :         pwm_enable(panel->backlight.pwm);
    1160                 :          0 :         intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
    1161                 :          0 : }
    1162                 :            : 
    1163                 :          0 : static void __intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state,
    1164                 :            :                                            const struct drm_connector_state *conn_state)
    1165                 :            : {
    1166                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1167                 :          0 :         struct intel_panel *panel = &connector->panel;
    1168                 :            : 
    1169         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
    1170                 :            : 
    1171         [ #  # ]:          0 :         if (panel->backlight.level <= panel->backlight.min) {
    1172                 :          0 :                 panel->backlight.level = panel->backlight.max;
    1173         [ #  # ]:          0 :                 if (panel->backlight.device)
    1174                 :          0 :                         panel->backlight.device->props.brightness =
    1175                 :          0 :                                 scale_hw_to_user(connector,
    1176                 :            :                                                  panel->backlight.level,
    1177                 :          0 :                                                  panel->backlight.device->props.max_brightness);
    1178                 :            :         }
    1179                 :            : 
    1180                 :          0 :         panel->backlight.enable(crtc_state, conn_state);
    1181                 :          0 :         panel->backlight.enabled = true;
    1182         [ #  # ]:          0 :         if (panel->backlight.device)
    1183                 :          0 :                 panel->backlight.device->props.power = FB_BLANK_UNBLANK;
    1184                 :          0 : }
    1185                 :            : 
    1186                 :          0 : void intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state,
    1187                 :            :                                   const struct drm_connector_state *conn_state)
    1188                 :            : {
    1189                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1190         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1191                 :          0 :         struct intel_panel *panel = &connector->panel;
    1192                 :          0 :         enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe;
    1193                 :            : 
    1194         [ #  # ]:          0 :         if (!panel->backlight.present)
    1195                 :            :                 return;
    1196                 :            : 
    1197                 :          0 :         DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
    1198                 :            : 
    1199                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
    1200                 :            : 
    1201                 :          0 :         __intel_panel_enable_backlight(crtc_state, conn_state);
    1202                 :            : 
    1203                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
    1204                 :            : }
    1205                 :            : 
    1206                 :            : #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
    1207                 :          0 : static u32 intel_panel_get_backlight(struct intel_connector *connector)
    1208                 :            : {
    1209                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1210                 :          0 :         struct intel_panel *panel = &connector->panel;
    1211                 :          0 :         u32 val = 0;
    1212                 :            : 
    1213                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
    1214                 :            : 
    1215         [ #  # ]:          0 :         if (panel->backlight.enabled) {
    1216                 :          0 :                 val = panel->backlight.get(connector);
    1217                 :          0 :                 val = intel_panel_compute_brightness(connector, val);
    1218                 :            :         }
    1219                 :            : 
    1220                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
    1221                 :            : 
    1222                 :          0 :         DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val);
    1223                 :          0 :         return val;
    1224                 :            : }
    1225                 :            : 
    1226                 :            : /* set backlight brightness to level in range [0..max], scaling wrt hw min */
    1227                 :          0 : static void intel_panel_set_backlight(const struct drm_connector_state *conn_state,
    1228                 :            :                                       u32 user_level, u32 user_max)
    1229                 :            : {
    1230                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1231         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1232                 :          0 :         struct intel_panel *panel = &connector->panel;
    1233                 :          0 :         u32 hw_level;
    1234                 :            : 
    1235         [ #  # ]:          0 :         if (!panel->backlight.present)
    1236                 :            :                 return;
    1237                 :            : 
    1238                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
    1239                 :            : 
    1240         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
    1241                 :            : 
    1242                 :          0 :         hw_level = scale_user_to_hw(connector, user_level, user_max);
    1243                 :          0 :         panel->backlight.level = hw_level;
    1244                 :            : 
    1245         [ #  # ]:          0 :         if (panel->backlight.enabled)
    1246                 :          0 :                 intel_panel_actually_set_backlight(conn_state, hw_level);
    1247                 :            : 
    1248                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
    1249                 :            : }
    1250                 :            : 
    1251                 :          0 : static int intel_backlight_device_update_status(struct backlight_device *bd)
    1252                 :            : {
    1253                 :          0 :         struct intel_connector *connector = bl_get_data(bd);
    1254                 :          0 :         struct intel_panel *panel = &connector->panel;
    1255                 :          0 :         struct drm_device *dev = connector->base.dev;
    1256                 :            : 
    1257                 :          0 :         drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
    1258                 :          0 :         DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n",
    1259                 :            :                       bd->props.brightness, bd->props.max_brightness);
    1260                 :          0 :         intel_panel_set_backlight(connector->base.state, bd->props.brightness,
    1261                 :          0 :                                   bd->props.max_brightness);
    1262                 :            : 
    1263                 :            :         /*
    1264                 :            :          * Allow flipping bl_power as a sub-state of enabled. Sadly the
    1265                 :            :          * backlight class device does not make it easy to to differentiate
    1266                 :            :          * between callbacks for brightness and bl_power, so our backlight_power
    1267                 :            :          * callback needs to take this into account.
    1268                 :            :          */
    1269         [ #  # ]:          0 :         if (panel->backlight.enabled) {
    1270         [ #  # ]:          0 :                 if (panel->backlight.power) {
    1271         [ #  # ]:          0 :                         bool enable = bd->props.power == FB_BLANK_UNBLANK &&
    1272         [ #  # ]:          0 :                                 bd->props.brightness != 0;
    1273                 :          0 :                         panel->backlight.power(connector, enable);
    1274                 :            :                 }
    1275                 :            :         } else {
    1276                 :          0 :                 bd->props.power = FB_BLANK_POWERDOWN;
    1277                 :            :         }
    1278                 :            : 
    1279                 :          0 :         drm_modeset_unlock(&dev->mode_config.connection_mutex);
    1280                 :          0 :         return 0;
    1281                 :            : }
    1282                 :            : 
    1283                 :          0 : static int intel_backlight_device_get_brightness(struct backlight_device *bd)
    1284                 :            : {
    1285                 :          0 :         struct intel_connector *connector = bl_get_data(bd);
    1286                 :          0 :         struct drm_device *dev = connector->base.dev;
    1287                 :          0 :         struct drm_i915_private *dev_priv = to_i915(dev);
    1288                 :          0 :         intel_wakeref_t wakeref;
    1289                 :          0 :         int ret = 0;
    1290                 :            : 
    1291         [ #  # ]:          0 :         with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
    1292                 :          0 :                 u32 hw_level;
    1293                 :            : 
    1294                 :          0 :                 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
    1295                 :            : 
    1296                 :          0 :                 hw_level = intel_panel_get_backlight(connector);
    1297                 :          0 :                 ret = scale_hw_to_user(connector,
    1298                 :          0 :                                        hw_level, bd->props.max_brightness);
    1299                 :            : 
    1300                 :          0 :                 drm_modeset_unlock(&dev->mode_config.connection_mutex);
    1301                 :            :         }
    1302                 :            : 
    1303                 :          0 :         return ret;
    1304                 :            : }
    1305                 :            : 
    1306                 :            : static const struct backlight_ops intel_backlight_device_ops = {
    1307                 :            :         .update_status = intel_backlight_device_update_status,
    1308                 :            :         .get_brightness = intel_backlight_device_get_brightness,
    1309                 :            : };
    1310                 :            : 
    1311                 :          0 : int intel_backlight_device_register(struct intel_connector *connector)
    1312                 :            : {
    1313                 :          0 :         struct intel_panel *panel = &connector->panel;
    1314                 :          0 :         struct backlight_properties props;
    1315                 :            : 
    1316   [ #  #  #  # ]:          0 :         if (WARN_ON(panel->backlight.device))
    1317                 :            :                 return -ENODEV;
    1318                 :            : 
    1319         [ #  # ]:          0 :         if (!panel->backlight.present)
    1320                 :            :                 return 0;
    1321                 :            : 
    1322         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
    1323                 :            : 
    1324                 :          0 :         memset(&props, 0, sizeof(props));
    1325                 :          0 :         props.type = BACKLIGHT_RAW;
    1326                 :            : 
    1327                 :            :         /*
    1328                 :            :          * Note: Everything should work even if the backlight device max
    1329                 :            :          * presented to the userspace is arbitrarily chosen.
    1330                 :            :          */
    1331                 :          0 :         props.max_brightness = panel->backlight.max;
    1332                 :          0 :         props.brightness = scale_hw_to_user(connector,
    1333                 :            :                                             panel->backlight.level,
    1334                 :            :                                             props.max_brightness);
    1335                 :            : 
    1336         [ #  # ]:          0 :         if (panel->backlight.enabled)
    1337                 :          0 :                 props.power = FB_BLANK_UNBLANK;
    1338                 :            :         else
    1339                 :          0 :                 props.power = FB_BLANK_POWERDOWN;
    1340                 :            : 
    1341                 :            :         /*
    1342                 :            :          * Note: using the same name independent of the connector prevents
    1343                 :            :          * registration of multiple backlight devices in the driver.
    1344                 :            :          */
    1345                 :          0 :         panel->backlight.device =
    1346                 :          0 :                 backlight_device_register("intel_backlight",
    1347                 :            :                                           connector->base.kdev,
    1348                 :            :                                           connector,
    1349                 :            :                                           &intel_backlight_device_ops, &props);
    1350                 :            : 
    1351         [ #  # ]:          0 :         if (IS_ERR(panel->backlight.device)) {
    1352                 :          0 :                 DRM_ERROR("Failed to register backlight: %ld\n",
    1353                 :            :                           PTR_ERR(panel->backlight.device));
    1354                 :          0 :                 panel->backlight.device = NULL;
    1355                 :          0 :                 return -ENODEV;
    1356                 :            :         }
    1357                 :            : 
    1358                 :          0 :         DRM_DEBUG_KMS("Connector %s backlight sysfs interface registered\n",
    1359                 :            :                       connector->base.name);
    1360                 :            : 
    1361                 :          0 :         return 0;
    1362                 :            : }
    1363                 :            : 
    1364                 :          0 : void intel_backlight_device_unregister(struct intel_connector *connector)
    1365                 :            : {
    1366                 :          0 :         struct intel_panel *panel = &connector->panel;
    1367                 :            : 
    1368         [ #  # ]:          0 :         if (panel->backlight.device) {
    1369                 :          0 :                 backlight_device_unregister(panel->backlight.device);
    1370                 :          0 :                 panel->backlight.device = NULL;
    1371                 :            :         }
    1372                 :          0 : }
    1373                 :            : #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
    1374                 :            : 
    1375                 :            : /*
    1376                 :            :  * CNP: PWM clock frequency is 19.2 MHz or 24 MHz.
    1377                 :            :  *      PWM increment = 1
    1378                 :            :  */
    1379                 :          0 : static u32 cnp_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1380                 :            : {
    1381                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1382                 :            : 
    1383                 :          0 :         return DIV_ROUND_CLOSEST(KHz(dev_priv->rawclk_freq), pwm_freq_hz);
    1384                 :            : }
    1385                 :            : 
    1386                 :            : /*
    1387                 :            :  * BXT: PWM clock frequency = 19.2 MHz.
    1388                 :            :  */
    1389                 :          0 : static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1390                 :            : {
    1391                 :          0 :         return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz);
    1392                 :            : }
    1393                 :            : 
    1394                 :            : /*
    1395                 :            :  * SPT: This value represents the period of the PWM stream in clock periods
    1396                 :            :  * multiplied by 16 (default increment) or 128 (alternate increment selected in
    1397                 :            :  * SCHICKEN_1 bit 0). PWM clock is 24 MHz.
    1398                 :            :  */
    1399                 :          0 : static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1400                 :            : {
    1401                 :          0 :         struct intel_panel *panel = &connector->panel;
    1402                 :          0 :         u32 mul;
    1403                 :            : 
    1404         [ #  # ]:          0 :         if (panel->backlight.alternate_pwm_increment)
    1405                 :            :                 mul = 128;
    1406                 :            :         else
    1407                 :          0 :                 mul = 16;
    1408                 :            : 
    1409                 :          0 :         return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul);
    1410                 :            : }
    1411                 :            : 
    1412                 :            : /*
    1413                 :            :  * LPT: This value represents the period of the PWM stream in clock periods
    1414                 :            :  * multiplied by 128 (default increment) or 16 (alternate increment, selected in
    1415                 :            :  * LPT SOUTH_CHICKEN2 register bit 5).
    1416                 :            :  */
    1417                 :          0 : static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1418                 :            : {
    1419         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1420                 :          0 :         struct intel_panel *panel = &connector->panel;
    1421                 :          0 :         u32 mul, clock;
    1422                 :            : 
    1423         [ #  # ]:          0 :         if (panel->backlight.alternate_pwm_increment)
    1424                 :            :                 mul = 16;
    1425                 :            :         else
    1426                 :          0 :                 mul = 128;
    1427                 :            : 
    1428         [ #  # ]:          0 :         if (HAS_PCH_LPT_H(dev_priv))
    1429                 :            :                 clock = MHz(135); /* LPT:H */
    1430                 :            :         else
    1431                 :          0 :                 clock = MHz(24); /* LPT:LP */
    1432                 :            : 
    1433                 :          0 :         return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
    1434                 :            : }
    1435                 :            : 
    1436                 :            : /*
    1437                 :            :  * ILK/SNB/IVB: This value represents the period of the PWM stream in PCH
    1438                 :            :  * display raw clocks multiplied by 128.
    1439                 :            :  */
    1440                 :          0 : static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1441                 :            : {
    1442                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1443                 :            : 
    1444                 :          0 :         return DIV_ROUND_CLOSEST(KHz(dev_priv->rawclk_freq), pwm_freq_hz * 128);
    1445                 :            : }
    1446                 :            : 
    1447                 :            : /*
    1448                 :            :  * Gen2: This field determines the number of time base events (display core
    1449                 :            :  * clock frequency/32) in total for a complete cycle of modulated backlight
    1450                 :            :  * control.
    1451                 :            :  *
    1452                 :            :  * Gen3: A time base event equals the display core clock ([DevPNV] HRAW clock)
    1453                 :            :  * divided by 32.
    1454                 :            :  */
    1455                 :          0 : static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1456                 :            : {
    1457         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1458                 :          0 :         int clock;
    1459                 :            : 
    1460         [ #  # ]:          0 :         if (IS_PINEVIEW(dev_priv))
    1461                 :          0 :                 clock = KHz(dev_priv->rawclk_freq);
    1462                 :            :         else
    1463                 :          0 :                 clock = KHz(dev_priv->cdclk.hw.cdclk);
    1464                 :            : 
    1465                 :          0 :         return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32);
    1466                 :            : }
    1467                 :            : 
    1468                 :            : /*
    1469                 :            :  * Gen4: This value represents the period of the PWM stream in display core
    1470                 :            :  * clocks ([DevCTG] HRAW clocks) multiplied by 128.
    1471                 :            :  *
    1472                 :            :  */
    1473                 :          0 : static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1474                 :            : {
    1475         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1476                 :          0 :         int clock;
    1477                 :            : 
    1478   [ #  #  #  # ]:          0 :         if (IS_G4X(dev_priv))
    1479                 :          0 :                 clock = KHz(dev_priv->rawclk_freq);
    1480                 :            :         else
    1481                 :          0 :                 clock = KHz(dev_priv->cdclk.hw.cdclk);
    1482                 :            : 
    1483                 :          0 :         return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128);
    1484                 :            : }
    1485                 :            : 
    1486                 :            : /*
    1487                 :            :  * VLV: This value represents the period of the PWM stream in display core
    1488                 :            :  * clocks ([DevCTG] 200MHz HRAW clocks) multiplied by 128 or 25MHz S0IX clocks
    1489                 :            :  * multiplied by 16. CHV uses a 19.2MHz S0IX clock.
    1490                 :            :  */
    1491                 :          0 : static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
    1492                 :            : {
    1493                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1494                 :          0 :         int mul, clock;
    1495                 :            : 
    1496         [ #  # ]:          0 :         if ((I915_READ(CBR1_VLV) & CBR_PWM_CLOCK_MUX_SELECT) == 0) {
    1497         [ #  # ]:          0 :                 if (IS_CHERRYVIEW(dev_priv))
    1498                 :            :                         clock = KHz(19200);
    1499                 :            :                 else
    1500                 :          0 :                         clock = MHz(25);
    1501                 :            :                 mul = 16;
    1502                 :            :         } else {
    1503                 :          0 :                 clock = KHz(dev_priv->rawclk_freq);
    1504                 :          0 :                 mul = 128;
    1505                 :            :         }
    1506                 :            : 
    1507                 :          0 :         return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
    1508                 :            : }
    1509                 :            : 
    1510                 :          0 : static u32 get_backlight_max_vbt(struct intel_connector *connector)
    1511                 :            : {
    1512         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1513                 :          0 :         struct intel_panel *panel = &connector->panel;
    1514                 :          0 :         u16 pwm_freq_hz = dev_priv->vbt.backlight.pwm_freq_hz;
    1515                 :          0 :         u32 pwm;
    1516                 :            : 
    1517         [ #  # ]:          0 :         if (!panel->backlight.hz_to_pwm) {
    1518                 :          0 :                 DRM_DEBUG_KMS("backlight frequency conversion not supported\n");
    1519                 :          0 :                 return 0;
    1520                 :            :         }
    1521                 :            : 
    1522         [ #  # ]:          0 :         if (pwm_freq_hz) {
    1523                 :          0 :                 DRM_DEBUG_KMS("VBT defined backlight frequency %u Hz\n",
    1524                 :            :                               pwm_freq_hz);
    1525                 :            :         } else {
    1526                 :          0 :                 pwm_freq_hz = 200;
    1527                 :          0 :                 DRM_DEBUG_KMS("default backlight frequency %u Hz\n",
    1528                 :            :                               pwm_freq_hz);
    1529                 :            :         }
    1530                 :            : 
    1531                 :          0 :         pwm = panel->backlight.hz_to_pwm(connector, pwm_freq_hz);
    1532         [ #  # ]:          0 :         if (!pwm) {
    1533                 :          0 :                 DRM_DEBUG_KMS("backlight frequency conversion failed\n");
    1534                 :          0 :                 return 0;
    1535                 :            :         }
    1536                 :            : 
    1537                 :            :         return pwm;
    1538                 :            : }
    1539                 :            : 
    1540                 :            : /*
    1541                 :            :  * Note: The setup hooks can't assume pipe is set!
    1542                 :            :  */
    1543                 :          0 : static u32 get_backlight_min_vbt(struct intel_connector *connector)
    1544                 :            : {
    1545         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1546                 :          0 :         struct intel_panel *panel = &connector->panel;
    1547                 :          0 :         int min;
    1548                 :            : 
    1549         [ #  # ]:          0 :         WARN_ON(panel->backlight.max == 0);
    1550                 :            : 
    1551                 :            :         /*
    1552                 :            :          * XXX: If the vbt value is 255, it makes min equal to max, which leads
    1553                 :            :          * to problems. There are such machines out there. Either our
    1554                 :            :          * interpretation is wrong or the vbt has bogus data. Or both. Safeguard
    1555                 :            :          * against this by letting the minimum be at most (arbitrarily chosen)
    1556                 :            :          * 25% of the max.
    1557                 :            :          */
    1558                 :          0 :         min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64);
    1559         [ #  # ]:          0 :         if (min != dev_priv->vbt.backlight.min_brightness) {
    1560                 :          0 :                 DRM_DEBUG_KMS("clamping VBT min backlight %d/255 to %d/255\n",
    1561                 :            :                               dev_priv->vbt.backlight.min_brightness, min);
    1562                 :            :         }
    1563                 :            : 
    1564                 :            :         /* vbt value is a coefficient in range [0..255] */
    1565                 :          0 :         return scale(min, 0, 255, 0, panel->backlight.max);
    1566                 :            : }
    1567                 :            : 
    1568                 :          0 : static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1569                 :            : {
    1570         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1571                 :          0 :         struct intel_panel *panel = &connector->panel;
    1572                 :          0 :         u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
    1573                 :          0 :         bool alt, cpu_mode;
    1574                 :            : 
    1575         [ #  # ]:          0 :         if (HAS_PCH_LPT(dev_priv))
    1576                 :          0 :                 alt = I915_READ(SOUTH_CHICKEN2) & LPT_PWM_GRANULARITY;
    1577                 :            :         else
    1578                 :          0 :                 alt = I915_READ(SOUTH_CHICKEN1) & SPT_PWM_GRANULARITY;
    1579                 :          0 :         panel->backlight.alternate_pwm_increment = alt;
    1580                 :            : 
    1581                 :          0 :         pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
    1582                 :          0 :         panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
    1583                 :            : 
    1584                 :          0 :         pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
    1585                 :          0 :         panel->backlight.max = pch_ctl2 >> 16;
    1586                 :            : 
    1587                 :          0 :         cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
    1588                 :            : 
    1589         [ #  # ]:          0 :         if (!panel->backlight.max)
    1590                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1591                 :            : 
    1592         [ #  # ]:          0 :         if (!panel->backlight.max)
    1593                 :            :                 return -ENODEV;
    1594                 :            : 
    1595                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1596                 :            : 
    1597                 :          0 :         panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE;
    1598                 :            : 
    1599         [ #  # ]:          0 :         cpu_mode = panel->backlight.enabled && HAS_PCH_LPT(dev_priv) &&
    1600   [ #  #  #  #  :          0 :                    !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) &&
                   #  # ]
    1601                 :            :                    (cpu_ctl2 & BLM_PWM_ENABLE);
    1602         [ #  # ]:          0 :         if (cpu_mode)
    1603                 :          0 :                 val = pch_get_backlight(connector);
    1604                 :            :         else
    1605                 :          0 :                 val = lpt_get_backlight(connector);
    1606                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1607                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1608                 :            :                                        panel->backlight.max);
    1609                 :            : 
    1610         [ #  # ]:          0 :         if (cpu_mode) {
    1611                 :          0 :                 DRM_DEBUG_KMS("CPU backlight register was enabled, switching to PCH override\n");
    1612                 :            : 
    1613                 :            :                 /* Write converted CPU PWM value to PCH override register */
    1614                 :          0 :                 lpt_set_backlight(connector->base.state, panel->backlight.level);
    1615                 :          0 :                 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE);
    1616                 :            : 
    1617                 :          0 :                 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 & ~BLM_PWM_ENABLE);
    1618                 :            :         }
    1619                 :            : 
    1620                 :            :         return 0;
    1621                 :            : }
    1622                 :            : 
    1623                 :          0 : static int pch_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1624                 :            : {
    1625                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1626                 :          0 :         struct intel_panel *panel = &connector->panel;
    1627                 :          0 :         u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
    1628                 :            : 
    1629                 :          0 :         pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
    1630                 :          0 :         panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
    1631                 :            : 
    1632                 :          0 :         pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
    1633                 :          0 :         panel->backlight.max = pch_ctl2 >> 16;
    1634                 :            : 
    1635         [ #  # ]:          0 :         if (!panel->backlight.max)
    1636                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1637                 :            : 
    1638         [ #  # ]:          0 :         if (!panel->backlight.max)
    1639                 :            :                 return -ENODEV;
    1640                 :            : 
    1641                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1642                 :            : 
    1643                 :          0 :         val = pch_get_backlight(connector);
    1644                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1645                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1646                 :            :                                        panel->backlight.max);
    1647                 :            : 
    1648                 :          0 :         cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
    1649                 :          0 :         panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) &&
    1650                 :            :                 (pch_ctl1 & BLM_PCH_PWM_ENABLE);
    1651                 :            : 
    1652                 :          0 :         return 0;
    1653                 :            : }
    1654                 :            : 
    1655                 :          0 : static int i9xx_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1656                 :            : {
    1657                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1658                 :          0 :         struct intel_panel *panel = &connector->panel;
    1659                 :          0 :         u32 ctl, val;
    1660                 :            : 
    1661                 :          0 :         ctl = I915_READ(BLC_PWM_CTL);
    1662                 :            : 
    1663   [ #  #  #  #  :          0 :         if (IS_GEN(dev_priv, 2) || IS_I915GM(dev_priv) || IS_I945GM(dev_priv))
                   #  # ]
    1664                 :          0 :                 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
    1665                 :            : 
    1666         [ #  # ]:          0 :         if (IS_PINEVIEW(dev_priv))
    1667                 :          0 :                 panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV;
    1668                 :            : 
    1669                 :          0 :         panel->backlight.max = ctl >> 17;
    1670                 :            : 
    1671         [ #  # ]:          0 :         if (!panel->backlight.max) {
    1672                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1673                 :          0 :                 panel->backlight.max >>= 1;
    1674                 :            :         }
    1675                 :            : 
    1676         [ #  # ]:          0 :         if (!panel->backlight.max)
    1677                 :            :                 return -ENODEV;
    1678                 :            : 
    1679         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
    1680                 :          0 :                 panel->backlight.max *= 0xff;
    1681                 :            : 
    1682                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1683                 :            : 
    1684                 :          0 :         val = i9xx_get_backlight(connector);
    1685                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1686                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1687                 :            :                                        panel->backlight.max);
    1688                 :            : 
    1689                 :          0 :         panel->backlight.enabled = val != 0;
    1690                 :            : 
    1691                 :          0 :         return 0;
    1692                 :            : }
    1693                 :            : 
    1694                 :          0 : static int i965_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1695                 :            : {
    1696                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1697                 :          0 :         struct intel_panel *panel = &connector->panel;
    1698                 :          0 :         u32 ctl, ctl2, val;
    1699                 :            : 
    1700                 :          0 :         ctl2 = I915_READ(BLC_PWM_CTL2);
    1701                 :          0 :         panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE;
    1702                 :          0 :         panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
    1703                 :            : 
    1704                 :          0 :         ctl = I915_READ(BLC_PWM_CTL);
    1705                 :          0 :         panel->backlight.max = ctl >> 16;
    1706                 :            : 
    1707         [ #  # ]:          0 :         if (!panel->backlight.max)
    1708                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1709                 :            : 
    1710         [ #  # ]:          0 :         if (!panel->backlight.max)
    1711                 :            :                 return -ENODEV;
    1712                 :            : 
    1713         [ #  # ]:          0 :         if (panel->backlight.combination_mode)
    1714                 :          0 :                 panel->backlight.max *= 0xff;
    1715                 :            : 
    1716                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1717                 :            : 
    1718                 :          0 :         val = i9xx_get_backlight(connector);
    1719                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1720                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1721                 :            :                                        panel->backlight.max);
    1722                 :            : 
    1723                 :          0 :         panel->backlight.enabled = ctl2 & BLM_PWM_ENABLE;
    1724                 :            : 
    1725                 :          0 :         return 0;
    1726                 :            : }
    1727                 :            : 
    1728                 :          0 : static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe)
    1729                 :            : {
    1730         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1731                 :          0 :         struct intel_panel *panel = &connector->panel;
    1732                 :          0 :         u32 ctl, ctl2, val;
    1733                 :            : 
    1734   [ #  #  #  # ]:          0 :         if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
    1735                 :            :                 return -ENODEV;
    1736                 :            : 
    1737                 :          0 :         ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
    1738                 :          0 :         panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
    1739                 :            : 
    1740                 :          0 :         ctl = I915_READ(VLV_BLC_PWM_CTL(pipe));
    1741                 :          0 :         panel->backlight.max = ctl >> 16;
    1742                 :            : 
    1743         [ #  # ]:          0 :         if (!panel->backlight.max)
    1744                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1745                 :            : 
    1746         [ #  # ]:          0 :         if (!panel->backlight.max)
    1747                 :            :                 return -ENODEV;
    1748                 :            : 
    1749                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1750                 :            : 
    1751                 :          0 :         val = _vlv_get_backlight(dev_priv, pipe);
    1752                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1753                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1754                 :            :                                        panel->backlight.max);
    1755                 :            : 
    1756                 :          0 :         panel->backlight.enabled = ctl2 & BLM_PWM_ENABLE;
    1757                 :            : 
    1758                 :          0 :         return 0;
    1759                 :            : }
    1760                 :            : 
    1761                 :            : static int
    1762                 :          0 : bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1763                 :            : {
    1764                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1765                 :          0 :         struct intel_panel *panel = &connector->panel;
    1766                 :          0 :         u32 pwm_ctl, val;
    1767                 :            : 
    1768                 :          0 :         panel->backlight.controller = dev_priv->vbt.backlight.controller;
    1769                 :            : 
    1770                 :          0 :         pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1771                 :            : 
    1772                 :            :         /* Controller 1 uses the utility pin. */
    1773         [ #  # ]:          0 :         if (panel->backlight.controller == 1) {
    1774                 :          0 :                 val = I915_READ(UTIL_PIN_CTL);
    1775                 :          0 :                 panel->backlight.util_pin_active_low =
    1776                 :          0 :                                         val & UTIL_PIN_POLARITY;
    1777                 :            :         }
    1778                 :            : 
    1779                 :          0 :         panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY;
    1780                 :          0 :         panel->backlight.max =
    1781                 :          0 :                 I915_READ(BXT_BLC_PWM_FREQ(panel->backlight.controller));
    1782                 :            : 
    1783         [ #  # ]:          0 :         if (!panel->backlight.max)
    1784                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1785                 :            : 
    1786         [ #  # ]:          0 :         if (!panel->backlight.max)
    1787                 :            :                 return -ENODEV;
    1788                 :            : 
    1789                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1790                 :            : 
    1791                 :          0 :         val = bxt_get_backlight(connector);
    1792                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1793                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1794                 :            :                                        panel->backlight.max);
    1795                 :            : 
    1796                 :          0 :         panel->backlight.enabled = pwm_ctl & BXT_BLC_PWM_ENABLE;
    1797                 :            : 
    1798                 :          0 :         return 0;
    1799                 :            : }
    1800                 :            : 
    1801                 :            : static int
    1802                 :          0 : cnp_setup_backlight(struct intel_connector *connector, enum pipe unused)
    1803                 :            : {
    1804                 :          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1805                 :          0 :         struct intel_panel *panel = &connector->panel;
    1806                 :          0 :         u32 pwm_ctl, val;
    1807                 :            : 
    1808                 :            :         /*
    1809                 :            :          * CNP has the BXT implementation of backlight, but with only one
    1810                 :            :          * controller. TODO: ICP has multiple controllers but we only use
    1811                 :            :          * controller 0 for now.
    1812                 :            :          */
    1813                 :          0 :         panel->backlight.controller = 0;
    1814                 :            : 
    1815                 :          0 :         pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller));
    1816                 :            : 
    1817                 :          0 :         panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY;
    1818                 :          0 :         panel->backlight.max =
    1819                 :          0 :                 I915_READ(BXT_BLC_PWM_FREQ(panel->backlight.controller));
    1820                 :            : 
    1821         [ #  # ]:          0 :         if (!panel->backlight.max)
    1822                 :          0 :                 panel->backlight.max = get_backlight_max_vbt(connector);
    1823                 :            : 
    1824         [ #  # ]:          0 :         if (!panel->backlight.max)
    1825                 :            :                 return -ENODEV;
    1826                 :            : 
    1827                 :          0 :         panel->backlight.min = get_backlight_min_vbt(connector);
    1828                 :            : 
    1829                 :          0 :         val = bxt_get_backlight(connector);
    1830                 :          0 :         val = intel_panel_compute_brightness(connector, val);
    1831                 :          0 :         panel->backlight.level = clamp(val, panel->backlight.min,
    1832                 :            :                                        panel->backlight.max);
    1833                 :            : 
    1834                 :          0 :         panel->backlight.enabled = pwm_ctl & BXT_BLC_PWM_ENABLE;
    1835                 :            : 
    1836                 :          0 :         return 0;
    1837                 :            : }
    1838                 :            : 
    1839                 :          0 : static int pwm_setup_backlight(struct intel_connector *connector,
    1840                 :            :                                enum pipe pipe)
    1841                 :            : {
    1842                 :          0 :         struct drm_device *dev = connector->base.dev;
    1843         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(dev);
    1844                 :          0 :         struct intel_panel *panel = &connector->panel;
    1845                 :          0 :         const char *desc;
    1846                 :          0 :         int retval;
    1847                 :            : 
    1848                 :            :         /* Get the right PWM chip for DSI backlight according to VBT */
    1849         [ #  # ]:          0 :         if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
    1850                 :          0 :                 panel->backlight.pwm = pwm_get(dev->dev, "pwm_pmic_backlight");
    1851                 :          0 :                 desc = "PMIC";
    1852                 :            :         } else {
    1853                 :          0 :                 panel->backlight.pwm = pwm_get(dev->dev, "pwm_soc_backlight");
    1854                 :          0 :                 desc = "SoC";
    1855                 :            :         }
    1856                 :            : 
    1857         [ #  # ]:          0 :         if (IS_ERR(panel->backlight.pwm)) {
    1858                 :          0 :                 DRM_ERROR("Failed to get the %s PWM chip\n", desc);
    1859                 :          0 :                 panel->backlight.pwm = NULL;
    1860                 :          0 :                 return -ENODEV;
    1861                 :            :         }
    1862                 :            : 
    1863                 :            :         /*
    1864                 :            :          * FIXME: pwm_apply_args() should be removed when switching to
    1865                 :            :          * the atomic PWM API.
    1866                 :            :          */
    1867                 :          0 :         pwm_apply_args(panel->backlight.pwm);
    1868                 :            : 
    1869                 :          0 :         retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
    1870                 :            :                             CRC_PMIC_PWM_PERIOD_NS);
    1871                 :          0 :         if (retval < 0) {
    1872                 :          0 :                 DRM_ERROR("Failed to configure the pwm chip\n");
    1873                 :          0 :                 pwm_put(panel->backlight.pwm);
    1874                 :          0 :                 panel->backlight.pwm = NULL;
    1875                 :          0 :                 return retval;
    1876                 :            :         }
    1877                 :            : 
    1878                 :            :         panel->backlight.min = 0; /* 0% */
    1879                 :            :         panel->backlight.max = 100; /* 100% */
    1880                 :            :         panel->backlight.level = DIV_ROUND_UP(
    1881                 :            :                                  pwm_get_duty_cycle(panel->backlight.pwm) * 100,
    1882                 :            :                                  CRC_PMIC_PWM_PERIOD_NS);
    1883                 :            :         panel->backlight.enabled = panel->backlight.level != 0;
    1884                 :            : 
    1885                 :            :         DRM_INFO("Using %s PWM for LCD backlight control\n", desc);
    1886                 :            :         return 0;
    1887                 :            : }
    1888                 :            : 
    1889                 :          0 : void intel_panel_update_backlight(struct intel_encoder *encoder,
    1890                 :            :                                   const struct intel_crtc_state *crtc_state,
    1891                 :            :                                   const struct drm_connector_state *conn_state)
    1892                 :            : {
    1893                 :          0 :         struct intel_connector *connector = to_intel_connector(conn_state->connector);
    1894         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1895                 :          0 :         struct intel_panel *panel = &connector->panel;
    1896                 :            : 
    1897         [ #  # ]:          0 :         if (!panel->backlight.present)
    1898                 :            :                 return;
    1899                 :            : 
    1900                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
    1901         [ #  # ]:          0 :         if (!panel->backlight.enabled)
    1902                 :          0 :                 __intel_panel_enable_backlight(crtc_state, conn_state);
    1903                 :            : 
    1904                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
    1905                 :            : }
    1906                 :            : 
    1907                 :          0 : int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
    1908                 :            : {
    1909         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->dev);
    1910                 :          0 :         struct intel_connector *intel_connector = to_intel_connector(connector);
    1911                 :          0 :         struct intel_panel *panel = &intel_connector->panel;
    1912                 :          0 :         int ret;
    1913                 :            : 
    1914         [ #  # ]:          0 :         if (!dev_priv->vbt.backlight.present) {
    1915         [ #  # ]:          0 :                 if (dev_priv->quirks & QUIRK_BACKLIGHT_PRESENT) {
    1916                 :          0 :                         DRM_DEBUG_KMS("no backlight present per VBT, but present per quirk\n");
    1917                 :            :                 } else {
    1918                 :          0 :                         DRM_DEBUG_KMS("no backlight present per VBT\n");
    1919                 :          0 :                         return 0;
    1920                 :            :                 }
    1921                 :            :         }
    1922                 :            : 
    1923                 :            :         /* ensure intel_panel has been initialized first */
    1924   [ #  #  #  # ]:          0 :         if (WARN_ON(!panel->backlight.setup))
    1925                 :            :                 return -ENODEV;
    1926                 :            : 
    1927                 :            :         /* set level and max in panel struct */
    1928                 :          0 :         mutex_lock(&dev_priv->backlight_lock);
    1929                 :          0 :         ret = panel->backlight.setup(intel_connector, pipe);
    1930                 :          0 :         mutex_unlock(&dev_priv->backlight_lock);
    1931                 :            : 
    1932         [ #  # ]:          0 :         if (ret) {
    1933                 :          0 :                 DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
    1934                 :            :                               connector->name);
    1935                 :          0 :                 return ret;
    1936                 :            :         }
    1937                 :            : 
    1938                 :          0 :         panel->backlight.present = true;
    1939                 :            : 
    1940         [ #  # ]:          0 :         DRM_DEBUG_KMS("Connector %s backlight initialized, %s, brightness %u/%u\n",
    1941                 :            :                       connector->name,
    1942                 :            :                       enableddisabled(panel->backlight.enabled),
    1943                 :            :                       panel->backlight.level, panel->backlight.max);
    1944                 :            : 
    1945                 :          0 :         return 0;
    1946                 :            : }
    1947                 :            : 
    1948                 :          0 : static void intel_panel_destroy_backlight(struct intel_panel *panel)
    1949                 :            : {
    1950                 :            :         /* dispose of the pwm */
    1951                 :          0 :         if (panel->backlight.pwm)
    1952                 :            :                 pwm_put(panel->backlight.pwm);
    1953                 :            : 
    1954                 :          0 :         panel->backlight.present = false;
    1955                 :            : }
    1956                 :            : 
    1957                 :            : /* Set up chip specific backlight functions */
    1958                 :            : static void
    1959                 :          0 : intel_panel_init_backlight_funcs(struct intel_panel *panel)
    1960                 :            : {
    1961                 :          0 :         struct intel_connector *connector =
    1962                 :          0 :                 container_of(panel, struct intel_connector, panel);
    1963         [ #  # ]:          0 :         struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
    1964                 :            : 
    1965   [ #  #  #  # ]:          0 :         if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP &&
    1966                 :          0 :             intel_dp_aux_init_backlight_funcs(connector) == 0)
    1967                 :            :                 return;
    1968                 :            : 
    1969   [ #  #  #  # ]:          0 :         if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI &&
    1970                 :          0 :             intel_dsi_dcs_init_backlight_funcs(connector) == 0)
    1971                 :            :                 return;
    1972                 :            : 
    1973   [ #  #  #  # ]:          0 :         if (IS_GEN9_LP(dev_priv)) {
    1974                 :          0 :                 panel->backlight.setup = bxt_setup_backlight;
    1975                 :          0 :                 panel->backlight.enable = bxt_enable_backlight;
    1976                 :          0 :                 panel->backlight.disable = bxt_disable_backlight;
    1977                 :          0 :                 panel->backlight.set = bxt_set_backlight;
    1978                 :          0 :                 panel->backlight.get = bxt_get_backlight;
    1979                 :          0 :                 panel->backlight.hz_to_pwm = bxt_hz_to_pwm;
    1980         [ #  # ]:          0 :         } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP) {
    1981                 :          0 :                 panel->backlight.setup = cnp_setup_backlight;
    1982                 :          0 :                 panel->backlight.enable = cnp_enable_backlight;
    1983                 :          0 :                 panel->backlight.disable = cnp_disable_backlight;
    1984                 :          0 :                 panel->backlight.set = bxt_set_backlight;
    1985                 :          0 :                 panel->backlight.get = bxt_get_backlight;
    1986                 :          0 :                 panel->backlight.hz_to_pwm = cnp_hz_to_pwm;
    1987         [ #  # ]:          0 :         } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_LPT) {
    1988                 :          0 :                 panel->backlight.setup = lpt_setup_backlight;
    1989                 :          0 :                 panel->backlight.enable = lpt_enable_backlight;
    1990                 :          0 :                 panel->backlight.disable = lpt_disable_backlight;
    1991                 :          0 :                 panel->backlight.set = lpt_set_backlight;
    1992                 :          0 :                 panel->backlight.get = lpt_get_backlight;
    1993         [ #  # ]:          0 :                 if (HAS_PCH_LPT(dev_priv))
    1994                 :          0 :                         panel->backlight.hz_to_pwm = lpt_hz_to_pwm;
    1995                 :            :                 else
    1996                 :          0 :                         panel->backlight.hz_to_pwm = spt_hz_to_pwm;
    1997         [ #  # ]:          0 :         } else if (HAS_PCH_SPLIT(dev_priv)) {
    1998                 :          0 :                 panel->backlight.setup = pch_setup_backlight;
    1999                 :          0 :                 panel->backlight.enable = pch_enable_backlight;
    2000                 :          0 :                 panel->backlight.disable = pch_disable_backlight;
    2001                 :          0 :                 panel->backlight.set = pch_set_backlight;
    2002                 :          0 :                 panel->backlight.get = pch_get_backlight;
    2003                 :          0 :                 panel->backlight.hz_to_pwm = pch_hz_to_pwm;
    2004   [ #  #  #  # ]:          0 :         } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
    2005         [ #  # ]:          0 :                 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI) {
    2006                 :          0 :                         panel->backlight.setup = pwm_setup_backlight;
    2007                 :          0 :                         panel->backlight.enable = pwm_enable_backlight;
    2008                 :          0 :                         panel->backlight.disable = pwm_disable_backlight;
    2009                 :          0 :                         panel->backlight.set = pwm_set_backlight;
    2010                 :          0 :                         panel->backlight.get = pwm_get_backlight;
    2011                 :            :                 } else {
    2012                 :          0 :                         panel->backlight.setup = vlv_setup_backlight;
    2013                 :          0 :                         panel->backlight.enable = vlv_enable_backlight;
    2014                 :          0 :                         panel->backlight.disable = vlv_disable_backlight;
    2015                 :          0 :                         panel->backlight.set = vlv_set_backlight;
    2016                 :          0 :                         panel->backlight.get = vlv_get_backlight;
    2017                 :          0 :                         panel->backlight.hz_to_pwm = vlv_hz_to_pwm;
    2018                 :            :                 }
    2019         [ #  # ]:          0 :         } else if (IS_GEN(dev_priv, 4)) {
    2020                 :          0 :                 panel->backlight.setup = i965_setup_backlight;
    2021                 :          0 :                 panel->backlight.enable = i965_enable_backlight;
    2022                 :          0 :                 panel->backlight.disable = i965_disable_backlight;
    2023                 :          0 :                 panel->backlight.set = i9xx_set_backlight;
    2024                 :          0 :                 panel->backlight.get = i9xx_get_backlight;
    2025                 :          0 :                 panel->backlight.hz_to_pwm = i965_hz_to_pwm;
    2026                 :            :         } else {
    2027                 :          0 :                 panel->backlight.setup = i9xx_setup_backlight;
    2028                 :          0 :                 panel->backlight.enable = i9xx_enable_backlight;
    2029                 :          0 :                 panel->backlight.disable = i9xx_disable_backlight;
    2030                 :          0 :                 panel->backlight.set = i9xx_set_backlight;
    2031                 :          0 :                 panel->backlight.get = i9xx_get_backlight;
    2032                 :          0 :                 panel->backlight.hz_to_pwm = i9xx_hz_to_pwm;
    2033                 :            :         }
    2034                 :            : }
    2035                 :            : 
    2036                 :          0 : int intel_panel_init(struct intel_panel *panel,
    2037                 :            :                      struct drm_display_mode *fixed_mode,
    2038                 :            :                      struct drm_display_mode *downclock_mode)
    2039                 :            : {
    2040                 :          0 :         intel_panel_init_backlight_funcs(panel);
    2041                 :            : 
    2042                 :          0 :         panel->fixed_mode = fixed_mode;
    2043                 :          0 :         panel->downclock_mode = downclock_mode;
    2044                 :            : 
    2045                 :          0 :         return 0;
    2046                 :            : }
    2047                 :            : 
    2048                 :          0 : void intel_panel_fini(struct intel_panel *panel)
    2049                 :            : {
    2050                 :          0 :         struct intel_connector *intel_connector =
    2051                 :          0 :                 container_of(panel, struct intel_connector, panel);
    2052                 :            : 
    2053                 :          0 :         intel_panel_destroy_backlight(panel);
    2054                 :            : 
    2055         [ #  # ]:          0 :         if (panel->fixed_mode)
    2056                 :          0 :                 drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode);
    2057                 :            : 
    2058         [ #  # ]:          0 :         if (panel->downclock_mode)
    2059                 :          0 :                 drm_mode_destroy(intel_connector->base.dev,
    2060                 :            :                                 panel->downclock_mode);
    2061                 :          0 : }

Generated by: LCOV version 1.14