Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 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 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 31 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 32 | |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 33 | #include <linux/moduleparam.h> |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 34 | #include "intel_drv.h" |
| 35 | |
| 36 | void |
Ville Syrjälä | 4c6df4b | 2013-09-02 21:13:39 +0300 | [diff] [blame] | 37 | intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode, |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 38 | struct drm_display_mode *adjusted_mode) |
| 39 | { |
Ville Syrjälä | 4c6df4b | 2013-09-02 21:13:39 +0300 | [diff] [blame] | 40 | drm_mode_copy(adjusted_mode, fixed_mode); |
Imre Deak | a52690e | 2013-08-27 12:24:09 +0300 | [diff] [blame] | 41 | |
| 42 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /* adjusted_mode has been preset to be the panel's fixed mode */ |
| 46 | void |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 47 | intel_pch_panel_fitting(struct intel_crtc *intel_crtc, |
| 48 | struct intel_crtc_config *pipe_config, |
| 49 | int fitting_mode) |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 50 | { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 51 | struct drm_display_mode *adjusted_mode; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 52 | int x, y, width, height; |
| 53 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 54 | adjusted_mode = &pipe_config->adjusted_mode; |
| 55 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 56 | x = y = width = height = 0; |
| 57 | |
| 58 | /* Native modes don't need fitting */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 59 | if (adjusted_mode->hdisplay == pipe_config->pipe_src_w && |
| 60 | adjusted_mode->vdisplay == pipe_config->pipe_src_h) |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 61 | goto done; |
| 62 | |
| 63 | switch (fitting_mode) { |
| 64 | case DRM_MODE_SCALE_CENTER: |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 65 | width = pipe_config->pipe_src_w; |
| 66 | height = pipe_config->pipe_src_h; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 67 | x = (adjusted_mode->hdisplay - width + 1)/2; |
| 68 | y = (adjusted_mode->vdisplay - height + 1)/2; |
| 69 | break; |
| 70 | |
| 71 | case DRM_MODE_SCALE_ASPECT: |
| 72 | /* Scale but preserve the aspect ratio */ |
| 73 | { |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 74 | u32 scaled_width = adjusted_mode->hdisplay |
| 75 | * pipe_config->pipe_src_h; |
| 76 | u32 scaled_height = pipe_config->pipe_src_w |
| 77 | * adjusted_mode->vdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 78 | if (scaled_width > scaled_height) { /* pillar */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 79 | width = scaled_height / pipe_config->pipe_src_h; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 80 | if (width & 1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 81 | width++; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 82 | x = (adjusted_mode->hdisplay - width + 1) / 2; |
| 83 | y = 0; |
| 84 | height = adjusted_mode->vdisplay; |
| 85 | } else if (scaled_width < scaled_height) { /* letter */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 86 | height = scaled_width / pipe_config->pipe_src_w; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 87 | if (height & 1) |
| 88 | height++; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 89 | y = (adjusted_mode->vdisplay - height + 1) / 2; |
| 90 | x = 0; |
| 91 | width = adjusted_mode->hdisplay; |
| 92 | } else { |
| 93 | x = y = 0; |
| 94 | width = adjusted_mode->hdisplay; |
| 95 | height = adjusted_mode->vdisplay; |
| 96 | } |
| 97 | } |
| 98 | break; |
| 99 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 100 | case DRM_MODE_SCALE_FULLSCREEN: |
| 101 | x = y = 0; |
| 102 | width = adjusted_mode->hdisplay; |
| 103 | height = adjusted_mode->vdisplay; |
| 104 | break; |
Jesse Barnes | ab3e67f | 2013-04-25 12:55:03 -0700 | [diff] [blame] | 105 | |
| 106 | default: |
| 107 | WARN(1, "bad panel fit mode: %d\n", fitting_mode); |
| 108 | return; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | done: |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 112 | pipe_config->pch_pfit.pos = (x << 16) | y; |
| 113 | pipe_config->pch_pfit.size = (width << 16) | height; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 114 | pipe_config->pch_pfit.enabled = pipe_config->pch_pfit.size != 0; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 115 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 116 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 117 | static void |
| 118 | centre_horizontally(struct drm_display_mode *mode, |
| 119 | int width) |
| 120 | { |
| 121 | u32 border, sync_pos, blank_width, sync_width; |
| 122 | |
| 123 | /* keep the hsync and hblank widths constant */ |
| 124 | sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 125 | blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start; |
| 126 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 127 | |
| 128 | border = (mode->hdisplay - width + 1) / 2; |
| 129 | border += border & 1; /* make the border even */ |
| 130 | |
| 131 | mode->crtc_hdisplay = width; |
| 132 | mode->crtc_hblank_start = width + border; |
| 133 | mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width; |
| 134 | |
| 135 | mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos; |
| 136 | mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width; |
| 137 | } |
| 138 | |
| 139 | static void |
| 140 | centre_vertically(struct drm_display_mode *mode, |
| 141 | int height) |
| 142 | { |
| 143 | u32 border, sync_pos, blank_width, sync_width; |
| 144 | |
| 145 | /* keep the vsync and vblank widths constant */ |
| 146 | sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 147 | blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start; |
| 148 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 149 | |
| 150 | border = (mode->vdisplay - height + 1) / 2; |
| 151 | |
| 152 | mode->crtc_vdisplay = height; |
| 153 | mode->crtc_vblank_start = height + border; |
| 154 | mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width; |
| 155 | |
| 156 | mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos; |
| 157 | mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width; |
| 158 | } |
| 159 | |
| 160 | static inline u32 panel_fitter_scaling(u32 source, u32 target) |
| 161 | { |
| 162 | /* |
| 163 | * Floating point operation is not supported. So the FACTOR |
| 164 | * is defined, which can avoid the floating point computation |
| 165 | * when calculating the panel ratio. |
| 166 | */ |
| 167 | #define ACCURACY 12 |
| 168 | #define FACTOR (1 << ACCURACY) |
| 169 | u32 ratio = source * FACTOR / target; |
| 170 | return (FACTOR * ratio + FACTOR/2) / FACTOR; |
| 171 | } |
| 172 | |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 173 | static void i965_scale_aspect(struct intel_crtc_config *pipe_config, |
| 174 | u32 *pfit_control) |
| 175 | { |
| 176 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
| 177 | u32 scaled_width = adjusted_mode->hdisplay * |
| 178 | pipe_config->pipe_src_h; |
| 179 | u32 scaled_height = pipe_config->pipe_src_w * |
| 180 | adjusted_mode->vdisplay; |
| 181 | |
| 182 | /* 965+ is easy, it does everything in hw */ |
| 183 | if (scaled_width > scaled_height) |
| 184 | *pfit_control |= PFIT_ENABLE | |
| 185 | PFIT_SCALING_PILLAR; |
| 186 | else if (scaled_width < scaled_height) |
| 187 | *pfit_control |= PFIT_ENABLE | |
| 188 | PFIT_SCALING_LETTER; |
| 189 | else if (adjusted_mode->hdisplay != pipe_config->pipe_src_w) |
| 190 | *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO; |
| 191 | } |
| 192 | |
| 193 | static void i9xx_scale_aspect(struct intel_crtc_config *pipe_config, |
| 194 | u32 *pfit_control, u32 *pfit_pgm_ratios, |
| 195 | u32 *border) |
| 196 | { |
| 197 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
| 198 | u32 scaled_width = adjusted_mode->hdisplay * |
| 199 | pipe_config->pipe_src_h; |
| 200 | u32 scaled_height = pipe_config->pipe_src_w * |
| 201 | adjusted_mode->vdisplay; |
| 202 | u32 bits; |
| 203 | |
| 204 | /* |
| 205 | * For earlier chips we have to calculate the scaling |
| 206 | * ratio by hand and program it into the |
| 207 | * PFIT_PGM_RATIO register |
| 208 | */ |
| 209 | if (scaled_width > scaled_height) { /* pillar */ |
| 210 | centre_horizontally(adjusted_mode, |
| 211 | scaled_height / |
| 212 | pipe_config->pipe_src_h); |
| 213 | |
| 214 | *border = LVDS_BORDER_ENABLE; |
| 215 | if (pipe_config->pipe_src_h != adjusted_mode->vdisplay) { |
| 216 | bits = panel_fitter_scaling(pipe_config->pipe_src_h, |
| 217 | adjusted_mode->vdisplay); |
| 218 | |
| 219 | *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 220 | bits << PFIT_VERT_SCALE_SHIFT); |
| 221 | *pfit_control |= (PFIT_ENABLE | |
| 222 | VERT_INTERP_BILINEAR | |
| 223 | HORIZ_INTERP_BILINEAR); |
| 224 | } |
| 225 | } else if (scaled_width < scaled_height) { /* letter */ |
| 226 | centre_vertically(adjusted_mode, |
| 227 | scaled_width / |
| 228 | pipe_config->pipe_src_w); |
| 229 | |
| 230 | *border = LVDS_BORDER_ENABLE; |
| 231 | if (pipe_config->pipe_src_w != adjusted_mode->hdisplay) { |
| 232 | bits = panel_fitter_scaling(pipe_config->pipe_src_w, |
| 233 | adjusted_mode->hdisplay); |
| 234 | |
| 235 | *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 236 | bits << PFIT_VERT_SCALE_SHIFT); |
| 237 | *pfit_control |= (PFIT_ENABLE | |
| 238 | VERT_INTERP_BILINEAR | |
| 239 | HORIZ_INTERP_BILINEAR); |
| 240 | } |
| 241 | } else { |
| 242 | /* Aspects match, Let hw scale both directions */ |
| 243 | *pfit_control |= (PFIT_ENABLE | |
| 244 | VERT_AUTO_SCALE | HORIZ_AUTO_SCALE | |
| 245 | VERT_INTERP_BILINEAR | |
| 246 | HORIZ_INTERP_BILINEAR); |
| 247 | } |
| 248 | } |
| 249 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 250 | void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc, |
| 251 | struct intel_crtc_config *pipe_config, |
| 252 | int fitting_mode) |
| 253 | { |
| 254 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 255 | u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 256 | struct drm_display_mode *adjusted_mode; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 257 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 258 | adjusted_mode = &pipe_config->adjusted_mode; |
| 259 | |
| 260 | /* Native modes don't need fitting */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 261 | if (adjusted_mode->hdisplay == pipe_config->pipe_src_w && |
| 262 | adjusted_mode->vdisplay == pipe_config->pipe_src_h) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 263 | goto out; |
| 264 | |
| 265 | switch (fitting_mode) { |
| 266 | case DRM_MODE_SCALE_CENTER: |
| 267 | /* |
| 268 | * For centered modes, we have to calculate border widths & |
| 269 | * heights and modify the values programmed into the CRTC. |
| 270 | */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 271 | centre_horizontally(adjusted_mode, pipe_config->pipe_src_w); |
| 272 | centre_vertically(adjusted_mode, pipe_config->pipe_src_h); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 273 | border = LVDS_BORDER_ENABLE; |
| 274 | break; |
| 275 | case DRM_MODE_SCALE_ASPECT: |
| 276 | /* Scale but preserve the aspect ratio */ |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 277 | if (INTEL_INFO(dev)->gen >= 4) |
| 278 | i965_scale_aspect(pipe_config, &pfit_control); |
| 279 | else |
| 280 | i9xx_scale_aspect(pipe_config, &pfit_control, |
| 281 | &pfit_pgm_ratios, &border); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 282 | break; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 283 | case DRM_MODE_SCALE_FULLSCREEN: |
| 284 | /* |
| 285 | * Full scaling, even if it changes the aspect ratio. |
| 286 | * Fortunately this is all done for us in hw. |
| 287 | */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 288 | if (pipe_config->pipe_src_h != adjusted_mode->vdisplay || |
| 289 | pipe_config->pipe_src_w != adjusted_mode->hdisplay) { |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 290 | pfit_control |= PFIT_ENABLE; |
| 291 | if (INTEL_INFO(dev)->gen >= 4) |
| 292 | pfit_control |= PFIT_SCALING_AUTO; |
| 293 | else |
| 294 | pfit_control |= (VERT_AUTO_SCALE | |
| 295 | VERT_INTERP_BILINEAR | |
| 296 | HORIZ_AUTO_SCALE | |
| 297 | HORIZ_INTERP_BILINEAR); |
| 298 | } |
| 299 | break; |
Jesse Barnes | ab3e67f | 2013-04-25 12:55:03 -0700 | [diff] [blame] | 300 | default: |
| 301 | WARN(1, "bad panel fit mode: %d\n", fitting_mode); |
| 302 | return; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* 965+ wants fuzzy fitting */ |
| 306 | /* FIXME: handle multiple panels by failing gracefully */ |
| 307 | if (INTEL_INFO(dev)->gen >= 4) |
| 308 | pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) | |
| 309 | PFIT_FILTER_FUZZY); |
| 310 | |
| 311 | out: |
| 312 | if ((pfit_control & PFIT_ENABLE) == 0) { |
| 313 | pfit_control = 0; |
| 314 | pfit_pgm_ratios = 0; |
| 315 | } |
| 316 | |
| 317 | /* Make sure pre-965 set dither correctly for 18bpp panels. */ |
| 318 | if (INTEL_INFO(dev)->gen < 4 && pipe_config->pipe_bpp == 18) |
| 319 | pfit_control |= PANEL_8TO6_DITHER_ENABLE; |
| 320 | |
Daniel Vetter | 2deefda | 2013-04-25 22:52:17 +0200 | [diff] [blame] | 321 | pipe_config->gmch_pfit.control = pfit_control; |
| 322 | pipe_config->gmch_pfit.pgm_ratios = pfit_pgm_ratios; |
Daniel Vetter | 68fc874 | 2013-04-25 22:52:16 +0200 | [diff] [blame] | 323 | pipe_config->gmch_pfit.lvds_border_bits = border; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 326 | static u32 intel_panel_compute_brightness(struct intel_connector *connector, |
| 327 | u32 val) |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 328 | { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 329 | struct drm_device *dev = connector->base.dev; |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 330 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 331 | struct intel_panel *panel = &connector->panel; |
| 332 | |
| 333 | WARN_ON(panel->backlight.max == 0); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 334 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 335 | if (i915.invert_brightness < 0) |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 336 | return val; |
| 337 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 338 | if (i915.invert_brightness > 0 || |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 339 | dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) { |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 340 | return panel->backlight.max - val; |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 341 | } |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 342 | |
| 343 | return val; |
| 344 | } |
| 345 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 346 | static u32 bdw_get_backlight(struct intel_connector *connector) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 347 | { |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 348 | struct drm_device *dev = connector->base.dev; |
| 349 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 350 | |
| 351 | return I915_READ(BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 352 | } |
| 353 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 354 | static u32 pch_get_backlight(struct intel_connector *connector) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 355 | { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 356 | struct drm_device *dev = connector->base.dev; |
| 357 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 358 | |
| 359 | return I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 360 | } |
| 361 | |
| 362 | static u32 i9xx_get_backlight(struct intel_connector *connector) |
| 363 | { |
| 364 | struct drm_device *dev = connector->base.dev; |
| 365 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 366 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 367 | u32 val; |
| 368 | |
| 369 | val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 370 | if (INTEL_INFO(dev)->gen < 4) |
| 371 | val >>= 1; |
| 372 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 373 | if (panel->backlight.combination_mode) { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 374 | u8 lbpc; |
| 375 | |
| 376 | pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc); |
| 377 | val *= lbpc; |
| 378 | } |
| 379 | |
| 380 | return val; |
| 381 | } |
| 382 | |
| 383 | static u32 _vlv_get_backlight(struct drm_device *dev, enum pipe pipe) |
| 384 | { |
| 385 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 386 | |
| 387 | return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 388 | } |
| 389 | |
| 390 | static u32 vlv_get_backlight(struct intel_connector *connector) |
| 391 | { |
| 392 | struct drm_device *dev = connector->base.dev; |
| 393 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 394 | |
| 395 | return _vlv_get_backlight(dev, pipe); |
| 396 | } |
| 397 | |
| 398 | static u32 intel_panel_get_backlight(struct intel_connector *connector) |
| 399 | { |
| 400 | struct drm_device *dev = connector->base.dev; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 401 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 402 | u32 val; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 403 | unsigned long flags; |
| 404 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 405 | spin_lock_irqsave(&dev_priv->backlight_lock, flags); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 406 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 407 | val = dev_priv->display.get_backlight(connector); |
| 408 | val = intel_panel_compute_brightness(connector, val); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 409 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 410 | spin_unlock_irqrestore(&dev_priv->backlight_lock, flags); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 411 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 412 | DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val); |
| 413 | return val; |
| 414 | } |
| 415 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 416 | static void bdw_set_backlight(struct intel_connector *connector, u32 level) |
Ben Widawsky | f8e1006 | 2013-11-11 11:12:57 +0200 | [diff] [blame] | 417 | { |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 418 | struct drm_device *dev = connector->base.dev; |
Ben Widawsky | f8e1006 | 2013-11-11 11:12:57 +0200 | [diff] [blame] | 419 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 420 | u32 val = I915_READ(BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 421 | I915_WRITE(BLC_PWM_PCH_CTL2, val | level); |
| 422 | } |
| 423 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 424 | static void pch_set_backlight(struct intel_connector *connector, u32 level) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 425 | { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 426 | struct drm_device *dev = connector->base.dev; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 427 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 428 | u32 tmp; |
| 429 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 430 | tmp = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 431 | I915_WRITE(BLC_PWM_CPU_CTL, tmp | level); |
| 432 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 433 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 434 | static void i9xx_set_backlight(struct intel_connector *connector, u32 level) |
| 435 | { |
| 436 | struct drm_device *dev = connector->base.dev; |
| 437 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 438 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 439 | u32 tmp, mask; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 440 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 441 | WARN_ON(panel->backlight.max == 0); |
| 442 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 443 | if (panel->backlight.combination_mode) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 444 | u8 lbpc; |
| 445 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 446 | lbpc = level * 0xfe / panel->backlight.max + 1; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 447 | level /= lbpc; |
| 448 | pci_write_config_byte(dev->pdev, PCI_LBPC, lbpc); |
| 449 | } |
| 450 | |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 451 | if (IS_GEN4(dev)) { |
| 452 | mask = BACKLIGHT_DUTY_CYCLE_MASK; |
| 453 | } else { |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 454 | level <<= 1; |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 455 | mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV; |
| 456 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 457 | |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 458 | tmp = I915_READ(BLC_PWM_CTL) & ~mask; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 459 | I915_WRITE(BLC_PWM_CTL, tmp | level); |
| 460 | } |
| 461 | |
| 462 | static void vlv_set_backlight(struct intel_connector *connector, u32 level) |
| 463 | { |
| 464 | struct drm_device *dev = connector->base.dev; |
| 465 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 466 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 467 | u32 tmp; |
| 468 | |
| 469 | tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 470 | I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level); |
| 471 | } |
| 472 | |
| 473 | static void |
| 474 | intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level) |
| 475 | { |
| 476 | struct drm_device *dev = connector->base.dev; |
| 477 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 478 | |
| 479 | DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level); |
| 480 | |
| 481 | level = intel_panel_compute_brightness(connector, level); |
| 482 | dev_priv->display.set_backlight(connector, level); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 483 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 484 | |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 485 | /* set backlight brightness to level in range [0..max] */ |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 486 | void intel_panel_set_backlight(struct intel_connector *connector, u32 level, |
| 487 | u32 max) |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 488 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 489 | struct drm_device *dev = connector->base.dev; |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 490 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 491 | struct intel_panel *panel = &connector->panel; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 492 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 493 | u32 freq; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 494 | unsigned long flags; |
| 495 | |
Ville Syrjälä | dc5a436 | 2014-01-16 18:27:15 +0200 | [diff] [blame] | 496 | if (!panel->backlight.present || pipe == INVALID_PIPE) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 497 | return; |
| 498 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 499 | spin_lock_irqsave(&dev_priv->backlight_lock, flags); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 500 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 501 | WARN_ON(panel->backlight.max == 0); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 502 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 503 | /* scale to hardware max, but be careful to not overflow */ |
| 504 | freq = panel->backlight.max; |
Aaron Lu | 22505b8 | 2013-08-02 09:16:03 +0800 | [diff] [blame] | 505 | if (freq < max) |
| 506 | level = level * freq / max; |
| 507 | else |
| 508 | level = freq / max * level; |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 509 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 510 | panel->backlight.level = level; |
| 511 | if (panel->backlight.device) |
| 512 | panel->backlight.device->props.brightness = level; |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 513 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 514 | if (panel->backlight.enabled) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 515 | intel_panel_actually_set_backlight(connector, level); |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 516 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 517 | spin_unlock_irqrestore(&dev_priv->backlight_lock, flags); |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 520 | static void pch_disable_backlight(struct intel_connector *connector) |
| 521 | { |
| 522 | struct drm_device *dev = connector->base.dev; |
| 523 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 524 | u32 tmp; |
| 525 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 526 | intel_panel_actually_set_backlight(connector, 0); |
| 527 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 528 | tmp = I915_READ(BLC_PWM_CPU_CTL2); |
| 529 | I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE); |
| 530 | |
| 531 | tmp = I915_READ(BLC_PWM_PCH_CTL1); |
| 532 | I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); |
| 533 | } |
| 534 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 535 | static void i9xx_disable_backlight(struct intel_connector *connector) |
| 536 | { |
| 537 | intel_panel_actually_set_backlight(connector, 0); |
| 538 | } |
| 539 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 540 | static void i965_disable_backlight(struct intel_connector *connector) |
| 541 | { |
| 542 | struct drm_device *dev = connector->base.dev; |
| 543 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 544 | u32 tmp; |
| 545 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 546 | intel_panel_actually_set_backlight(connector, 0); |
| 547 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 548 | tmp = I915_READ(BLC_PWM_CTL2); |
| 549 | I915_WRITE(BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE); |
| 550 | } |
| 551 | |
| 552 | static void vlv_disable_backlight(struct intel_connector *connector) |
| 553 | { |
| 554 | struct drm_device *dev = connector->base.dev; |
| 555 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 556 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 557 | u32 tmp; |
| 558 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 559 | intel_panel_actually_set_backlight(connector, 0); |
| 560 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 561 | tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 562 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE); |
| 563 | } |
| 564 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 565 | void intel_panel_disable_backlight(struct intel_connector *connector) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 566 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 567 | struct drm_device *dev = connector->base.dev; |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 568 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 569 | struct intel_panel *panel = &connector->panel; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 570 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 571 | unsigned long flags; |
| 572 | |
Ville Syrjälä | dc5a436 | 2014-01-16 18:27:15 +0200 | [diff] [blame] | 573 | if (!panel->backlight.present || pipe == INVALID_PIPE) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 574 | return; |
| 575 | |
Jani Nikula | 3f57757 | 2013-07-25 14:31:30 +0300 | [diff] [blame] | 576 | /* |
| 577 | * Do not disable backlight on the vgaswitcheroo path. When switching |
| 578 | * away from i915, the other client may depend on i915 to handle the |
| 579 | * backlight. This will leave the backlight on unnecessarily when |
| 580 | * another client is not activated. |
| 581 | */ |
| 582 | if (dev->switch_power_state == DRM_SWITCH_POWER_CHANGING) { |
| 583 | DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n"); |
| 584 | return; |
| 585 | } |
| 586 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 587 | spin_lock_irqsave(&dev_priv->backlight_lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 588 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 589 | panel->backlight.enabled = false; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 590 | dev_priv->display.disable_backlight(connector); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 591 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 592 | spin_unlock_irqrestore(&dev_priv->backlight_lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 595 | static void bdw_enable_backlight(struct intel_connector *connector) |
| 596 | { |
| 597 | struct drm_device *dev = connector->base.dev; |
| 598 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 599 | struct intel_panel *panel = &connector->panel; |
| 600 | u32 pch_ctl1, pch_ctl2; |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 601 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 602 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 603 | if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { |
| 604 | DRM_DEBUG_KMS("pch backlight already enabled\n"); |
| 605 | pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; |
| 606 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 609 | pch_ctl2 = panel->backlight.max << 16; |
| 610 | I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2); |
| 611 | |
| 612 | pch_ctl1 = 0; |
| 613 | if (panel->backlight.active_low_pwm) |
| 614 | pch_ctl1 |= BLM_PCH_POLARITY; |
| 615 | |
| 616 | /* BDW always uses the pch pwm controls. */ |
| 617 | pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE; |
| 618 | |
| 619 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 620 | POSTING_READ(BLC_PWM_PCH_CTL1); |
| 621 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE); |
| 622 | |
| 623 | /* This won't stick until the above enable. */ |
| 624 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
| 625 | } |
| 626 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 627 | static void pch_enable_backlight(struct intel_connector *connector) |
| 628 | { |
| 629 | struct drm_device *dev = connector->base.dev; |
| 630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 631 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 632 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 633 | enum transcoder cpu_transcoder = |
| 634 | intel_pipe_to_cpu_transcoder(dev_priv, pipe); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 635 | u32 cpu_ctl2, pch_ctl1, pch_ctl2; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 636 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 637 | cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2); |
| 638 | if (cpu_ctl2 & BLM_PWM_ENABLE) { |
| 639 | WARN(1, "cpu backlight already enabled\n"); |
| 640 | cpu_ctl2 &= ~BLM_PWM_ENABLE; |
| 641 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 642 | } |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 643 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 644 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 645 | if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { |
| 646 | DRM_DEBUG_KMS("pch backlight already enabled\n"); |
| 647 | pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; |
| 648 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 649 | } |
| 650 | |
| 651 | if (cpu_transcoder == TRANSCODER_EDP) |
| 652 | cpu_ctl2 = BLM_TRANSCODER_EDP; |
| 653 | else |
| 654 | cpu_ctl2 = BLM_PIPE(cpu_transcoder); |
| 655 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2); |
| 656 | POSTING_READ(BLC_PWM_CPU_CTL2); |
| 657 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE); |
| 658 | |
| 659 | /* This won't stick until the above enable. */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 660 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 661 | |
| 662 | pch_ctl2 = panel->backlight.max << 16; |
| 663 | I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2); |
| 664 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 665 | pch_ctl1 = 0; |
| 666 | if (panel->backlight.active_low_pwm) |
| 667 | pch_ctl1 |= BLM_PCH_POLARITY; |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 668 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 669 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 670 | POSTING_READ(BLC_PWM_PCH_CTL1); |
| 671 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void i9xx_enable_backlight(struct intel_connector *connector) |
| 675 | { |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 676 | struct drm_device *dev = connector->base.dev; |
| 677 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 678 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 679 | u32 ctl, freq; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 680 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 681 | ctl = I915_READ(BLC_PWM_CTL); |
| 682 | if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) { |
| 683 | WARN(1, "backlight already enabled\n"); |
| 684 | I915_WRITE(BLC_PWM_CTL, 0); |
| 685 | } |
| 686 | |
| 687 | freq = panel->backlight.max; |
| 688 | if (panel->backlight.combination_mode) |
| 689 | freq /= 0xff; |
| 690 | |
| 691 | ctl = freq << 17; |
Jani Nikula | b6ab66a | 2014-02-25 13:11:47 +0200 | [diff] [blame] | 692 | if (panel->backlight.combination_mode) |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 693 | ctl |= BLM_LEGACY_MODE; |
| 694 | if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm) |
| 695 | ctl |= BLM_POLARITY_PNV; |
| 696 | |
| 697 | I915_WRITE(BLC_PWM_CTL, ctl); |
| 698 | POSTING_READ(BLC_PWM_CTL); |
| 699 | |
| 700 | /* XXX: combine this into above write? */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 701 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static void i965_enable_backlight(struct intel_connector *connector) |
| 705 | { |
| 706 | struct drm_device *dev = connector->base.dev; |
| 707 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 708 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 709 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 710 | u32 ctl, ctl2, freq; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 711 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 712 | ctl2 = I915_READ(BLC_PWM_CTL2); |
| 713 | if (ctl2 & BLM_PWM_ENABLE) { |
| 714 | WARN(1, "backlight already enabled\n"); |
| 715 | ctl2 &= ~BLM_PWM_ENABLE; |
| 716 | I915_WRITE(BLC_PWM_CTL2, ctl2); |
| 717 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 718 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 719 | freq = panel->backlight.max; |
| 720 | if (panel->backlight.combination_mode) |
| 721 | freq /= 0xff; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 722 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 723 | ctl = freq << 16; |
| 724 | I915_WRITE(BLC_PWM_CTL, ctl); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 725 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 726 | /* XXX: combine this into above write? */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 727 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 728 | |
| 729 | ctl2 = BLM_PIPE(pipe); |
| 730 | if (panel->backlight.combination_mode) |
| 731 | ctl2 |= BLM_COMBINATION_MODE; |
| 732 | if (panel->backlight.active_low_pwm) |
| 733 | ctl2 |= BLM_POLARITY_I965; |
| 734 | I915_WRITE(BLC_PWM_CTL2, ctl2); |
| 735 | POSTING_READ(BLC_PWM_CTL2); |
| 736 | I915_WRITE(BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static void vlv_enable_backlight(struct intel_connector *connector) |
| 740 | { |
| 741 | struct drm_device *dev = connector->base.dev; |
| 742 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 743 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 744 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 745 | u32 ctl, ctl2; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 746 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 747 | ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 748 | if (ctl2 & BLM_PWM_ENABLE) { |
| 749 | WARN(1, "backlight already enabled\n"); |
| 750 | ctl2 &= ~BLM_PWM_ENABLE; |
| 751 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2); |
| 752 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 753 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 754 | ctl = panel->backlight.max << 16; |
| 755 | I915_WRITE(VLV_BLC_PWM_CTL(pipe), ctl); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 756 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 757 | /* XXX: combine this into above write? */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 758 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 759 | |
| 760 | ctl2 = 0; |
| 761 | if (panel->backlight.active_low_pwm) |
| 762 | ctl2 |= BLM_POLARITY_I965; |
| 763 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2); |
| 764 | POSTING_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 765 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 766 | } |
| 767 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 768 | void intel_panel_enable_backlight(struct intel_connector *connector) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 769 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 770 | struct drm_device *dev = connector->base.dev; |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 771 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 772 | struct intel_panel *panel = &connector->panel; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 773 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 774 | unsigned long flags; |
| 775 | |
Ville Syrjälä | dc5a436 | 2014-01-16 18:27:15 +0200 | [diff] [blame] | 776 | if (!panel->backlight.present || pipe == INVALID_PIPE) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 777 | return; |
| 778 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 779 | DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe)); |
Chris Wilson | 540b5d0 | 2013-10-13 12:56:31 +0100 | [diff] [blame] | 780 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 781 | spin_lock_irqsave(&dev_priv->backlight_lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 782 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 783 | WARN_ON(panel->backlight.max == 0); |
| 784 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 785 | if (panel->backlight.level == 0) { |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 786 | panel->backlight.level = panel->backlight.max; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 787 | if (panel->backlight.device) |
| 788 | panel->backlight.device->props.brightness = |
| 789 | panel->backlight.level; |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 790 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 791 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 792 | dev_priv->display.enable_backlight(connector); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 793 | panel->backlight.enabled = true; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 794 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 795 | spin_unlock_irqrestore(&dev_priv->backlight_lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 798 | enum drm_connector_status |
| 799 | intel_panel_detect(struct drm_device *dev) |
| 800 | { |
| 801 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 802 | |
| 803 | /* Assume that the BIOS does not lie through the OpRegion... */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 804 | if (!i915.panel_ignore_lid && dev_priv->opregion.lid_state) { |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 805 | return ioread32(dev_priv->opregion.lid_state) & 0x1 ? |
| 806 | connector_status_connected : |
| 807 | connector_status_disconnected; |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 808 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 809 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 810 | switch (i915.panel_ignore_lid) { |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 811 | case -2: |
| 812 | return connector_status_connected; |
| 813 | case -1: |
| 814 | return connector_status_disconnected; |
| 815 | default: |
| 816 | return connector_status_unknown; |
| 817 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 818 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 819 | |
Jani Nikula | 912e8b1 | 2013-09-18 17:19:45 +0300 | [diff] [blame] | 820 | #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 821 | static int intel_backlight_device_update_status(struct backlight_device *bd) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 822 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 823 | struct intel_connector *connector = bl_get_data(bd); |
| 824 | struct drm_device *dev = connector->base.dev; |
| 825 | |
| 826 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 540b5d0 | 2013-10-13 12:56:31 +0100 | [diff] [blame] | 827 | DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n", |
| 828 | bd->props.brightness, bd->props.max_brightness); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 829 | intel_panel_set_backlight(connector, bd->props.brightness, |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 830 | bd->props.max_brightness); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 831 | mutex_unlock(&dev->mode_config.mutex); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 835 | static int intel_backlight_device_get_brightness(struct backlight_device *bd) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 836 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 837 | struct intel_connector *connector = bl_get_data(bd); |
| 838 | struct drm_device *dev = connector->base.dev; |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 839 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 840 | int ret; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 841 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 842 | intel_runtime_pm_get(dev_priv); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 843 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 844 | ret = intel_panel_get_backlight(connector); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 845 | mutex_unlock(&dev->mode_config.mutex); |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 846 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 847 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 848 | return ret; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 849 | } |
| 850 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 851 | static const struct backlight_ops intel_backlight_device_ops = { |
| 852 | .update_status = intel_backlight_device_update_status, |
| 853 | .get_brightness = intel_backlight_device_get_brightness, |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 854 | }; |
| 855 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 856 | static int intel_backlight_device_register(struct intel_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 857 | { |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 858 | struct intel_panel *panel = &connector->panel; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 859 | struct backlight_properties props; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 860 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 861 | if (WARN_ON(panel->backlight.device)) |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 862 | return -ENODEV; |
| 863 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 864 | BUG_ON(panel->backlight.max == 0); |
| 865 | |
Corentin Chary | af437cf | 2012-05-22 10:29:46 +0100 | [diff] [blame] | 866 | memset(&props, 0, sizeof(props)); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 867 | props.type = BACKLIGHT_RAW; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 868 | props.brightness = panel->backlight.level; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 869 | props.max_brightness = panel->backlight.max; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 870 | |
| 871 | /* |
| 872 | * Note: using the same name independent of the connector prevents |
| 873 | * registration of multiple backlight devices in the driver. |
| 874 | */ |
| 875 | panel->backlight.device = |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 876 | backlight_device_register("intel_backlight", |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 877 | connector->base.kdev, |
| 878 | connector, |
| 879 | &intel_backlight_device_ops, &props); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 880 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 881 | if (IS_ERR(panel->backlight.device)) { |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 882 | DRM_ERROR("Failed to register backlight: %ld\n", |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 883 | PTR_ERR(panel->backlight.device)); |
| 884 | panel->backlight.device = NULL; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 885 | return -ENODEV; |
| 886 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 887 | return 0; |
| 888 | } |
| 889 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 890 | static void intel_backlight_device_unregister(struct intel_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 891 | { |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 892 | struct intel_panel *panel = &connector->panel; |
| 893 | |
| 894 | if (panel->backlight.device) { |
| 895 | backlight_device_unregister(panel->backlight.device); |
| 896 | panel->backlight.device = NULL; |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 897 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 898 | } |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 899 | #else /* CONFIG_BACKLIGHT_CLASS_DEVICE */ |
| 900 | static int intel_backlight_device_register(struct intel_connector *connector) |
| 901 | { |
| 902 | return 0; |
| 903 | } |
| 904 | static void intel_backlight_device_unregister(struct intel_connector *connector) |
| 905 | { |
| 906 | } |
| 907 | #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ |
| 908 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 909 | /* |
| 910 | * Note: The setup hooks can't assume pipe is set! |
| 911 | * |
| 912 | * XXX: Query mode clock or hardware clock and program PWM modulation frequency |
| 913 | * appropriately when it's 0. Use VBT and/or sane defaults. |
| 914 | */ |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 915 | static int bdw_setup_backlight(struct intel_connector *connector) |
| 916 | { |
| 917 | struct drm_device *dev = connector->base.dev; |
| 918 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 919 | struct intel_panel *panel = &connector->panel; |
| 920 | u32 pch_ctl1, pch_ctl2, val; |
| 921 | |
| 922 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 923 | panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; |
| 924 | |
| 925 | pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2); |
| 926 | panel->backlight.max = pch_ctl2 >> 16; |
| 927 | if (!panel->backlight.max) |
| 928 | return -ENODEV; |
| 929 | |
| 930 | val = bdw_get_backlight(connector); |
| 931 | panel->backlight.level = intel_panel_compute_brightness(connector, val); |
| 932 | |
| 933 | panel->backlight.enabled = (pch_ctl1 & BLM_PCH_PWM_ENABLE) && |
| 934 | panel->backlight.level != 0; |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 939 | static int pch_setup_backlight(struct intel_connector *connector) |
| 940 | { |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 941 | struct drm_device *dev = connector->base.dev; |
| 942 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 943 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 944 | u32 cpu_ctl2, pch_ctl1, pch_ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 945 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 946 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 947 | panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; |
| 948 | |
| 949 | pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2); |
| 950 | panel->backlight.max = pch_ctl2 >> 16; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 951 | if (!panel->backlight.max) |
| 952 | return -ENODEV; |
| 953 | |
| 954 | val = pch_get_backlight(connector); |
| 955 | panel->backlight.level = intel_panel_compute_brightness(connector, val); |
| 956 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 957 | cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2); |
| 958 | panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) && |
| 959 | (pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0; |
| 960 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | static int i9xx_setup_backlight(struct intel_connector *connector) |
| 965 | { |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 966 | struct drm_device *dev = connector->base.dev; |
| 967 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 968 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 969 | u32 ctl, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 970 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 971 | ctl = I915_READ(BLC_PWM_CTL); |
| 972 | |
Jani Nikula | b6ab66a | 2014-02-25 13:11:47 +0200 | [diff] [blame] | 973 | if (IS_GEN2(dev) || IS_I915GM(dev) || IS_I945GM(dev)) |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 974 | panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; |
| 975 | |
| 976 | if (IS_PINEVIEW(dev)) |
| 977 | panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV; |
| 978 | |
| 979 | panel->backlight.max = ctl >> 17; |
| 980 | if (panel->backlight.combination_mode) |
| 981 | panel->backlight.max *= 0xff; |
| 982 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 983 | if (!panel->backlight.max) |
| 984 | return -ENODEV; |
| 985 | |
| 986 | val = i9xx_get_backlight(connector); |
| 987 | panel->backlight.level = intel_panel_compute_brightness(connector, val); |
| 988 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 989 | panel->backlight.enabled = panel->backlight.level != 0; |
| 990 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | static int i965_setup_backlight(struct intel_connector *connector) |
| 995 | { |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 996 | struct drm_device *dev = connector->base.dev; |
| 997 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 998 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 999 | u32 ctl, ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1000 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1001 | ctl2 = I915_READ(BLC_PWM_CTL2); |
| 1002 | panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE; |
| 1003 | panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; |
| 1004 | |
| 1005 | ctl = I915_READ(BLC_PWM_CTL); |
| 1006 | panel->backlight.max = ctl >> 16; |
| 1007 | if (panel->backlight.combination_mode) |
| 1008 | panel->backlight.max *= 0xff; |
| 1009 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1010 | if (!panel->backlight.max) |
| 1011 | return -ENODEV; |
| 1012 | |
| 1013 | val = i9xx_get_backlight(connector); |
| 1014 | panel->backlight.level = intel_panel_compute_brightness(connector, val); |
| 1015 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1016 | panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) && |
| 1017 | panel->backlight.level != 0; |
| 1018 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | static int vlv_setup_backlight(struct intel_connector *connector) |
| 1023 | { |
| 1024 | struct drm_device *dev = connector->base.dev; |
| 1025 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1026 | struct intel_panel *panel = &connector->panel; |
| 1027 | enum pipe pipe; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1028 | u32 ctl, ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1029 | |
| 1030 | for_each_pipe(pipe) { |
| 1031 | u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(pipe)); |
| 1032 | |
| 1033 | /* Skip if the modulation freq is already set */ |
| 1034 | if (cur_val & ~BACKLIGHT_DUTY_CYCLE_MASK) |
| 1035 | continue; |
| 1036 | |
| 1037 | cur_val &= BACKLIGHT_DUTY_CYCLE_MASK; |
| 1038 | I915_WRITE(VLV_BLC_PWM_CTL(pipe), (0xf42 << 16) | |
| 1039 | cur_val); |
| 1040 | } |
| 1041 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1042 | ctl2 = I915_READ(VLV_BLC_PWM_CTL2(PIPE_A)); |
| 1043 | panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; |
| 1044 | |
| 1045 | ctl = I915_READ(VLV_BLC_PWM_CTL(PIPE_A)); |
| 1046 | panel->backlight.max = ctl >> 16; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1047 | if (!panel->backlight.max) |
| 1048 | return -ENODEV; |
| 1049 | |
| 1050 | val = _vlv_get_backlight(dev, PIPE_A); |
| 1051 | panel->backlight.level = intel_panel_compute_brightness(connector, val); |
| 1052 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1053 | panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) && |
| 1054 | panel->backlight.level != 0; |
| 1055 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |
| 1058 | |
Jani Nikula | 0657b6b | 2012-10-19 14:51:46 +0300 | [diff] [blame] | 1059 | int intel_panel_setup_backlight(struct drm_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1060 | { |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1061 | struct drm_device *dev = connector->dev; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1062 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1063 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1064 | struct intel_panel *panel = &intel_connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1065 | unsigned long flags; |
| 1066 | int ret; |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1067 | |
Jani Nikula | c675949 | 2014-04-09 11:31:37 +0300 | [diff] [blame] | 1068 | if (!dev_priv->vbt.backlight.present) { |
| 1069 | DRM_DEBUG_KMS("native backlight control not available per VBT\n"); |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1073 | /* set level and max in panel struct */ |
| 1074 | spin_lock_irqsave(&dev_priv->backlight_lock, flags); |
| 1075 | ret = dev_priv->display.setup_backlight(intel_connector); |
| 1076 | spin_unlock_irqrestore(&dev_priv->backlight_lock, flags); |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1077 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1078 | if (ret) { |
| 1079 | DRM_DEBUG_KMS("failed to setup backlight for connector %s\n", |
| 1080 | drm_get_connector_name(connector)); |
| 1081 | return ret; |
| 1082 | } |
| 1083 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1084 | intel_backlight_device_register(intel_connector); |
| 1085 | |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1086 | panel->backlight.present = true; |
| 1087 | |
Jani Nikula | c445b3b | 2013-11-08 16:49:01 +0200 | [diff] [blame] | 1088 | DRM_DEBUG_KMS("backlight initialized, %s, brightness %u/%u, " |
| 1089 | "sysfs interface %sregistered\n", |
| 1090 | panel->backlight.enabled ? "enabled" : "disabled", |
| 1091 | panel->backlight.level, panel->backlight.max, |
| 1092 | panel->backlight.device ? "" : "not "); |
| 1093 | |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1094 | return 0; |
| 1095 | } |
| 1096 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1097 | void intel_panel_destroy_backlight(struct drm_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1098 | { |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1099 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1100 | struct intel_panel *panel = &intel_connector->panel; |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1101 | |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1102 | panel->backlight.present = false; |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1103 | intel_backlight_device_unregister(intel_connector); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1104 | } |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1105 | |
Vandana Kannan | ec9ed19 | 2013-12-10 13:37:36 +0530 | [diff] [blame] | 1106 | /** |
| 1107 | * intel_find_panel_downclock - find the reduced downclock for LVDS in EDID |
| 1108 | * @dev: drm device |
| 1109 | * @fixed_mode : panel native mode |
| 1110 | * @connector: LVDS/eDP connector |
| 1111 | * |
| 1112 | * Return downclock_avail |
| 1113 | * Find the reduced downclock for LVDS/eDP in EDID. |
| 1114 | */ |
| 1115 | struct drm_display_mode * |
| 1116 | intel_find_panel_downclock(struct drm_device *dev, |
| 1117 | struct drm_display_mode *fixed_mode, |
| 1118 | struct drm_connector *connector) |
| 1119 | { |
| 1120 | struct drm_display_mode *scan, *tmp_mode; |
| 1121 | int temp_downclock; |
| 1122 | |
| 1123 | temp_downclock = fixed_mode->clock; |
| 1124 | tmp_mode = NULL; |
| 1125 | |
| 1126 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 1127 | /* |
| 1128 | * If one mode has the same resolution with the fixed_panel |
| 1129 | * mode while they have the different refresh rate, it means |
| 1130 | * that the reduced downclock is found. In such |
| 1131 | * case we can set the different FPx0/1 to dynamically select |
| 1132 | * between low and high frequency. |
| 1133 | */ |
| 1134 | if (scan->hdisplay == fixed_mode->hdisplay && |
| 1135 | scan->hsync_start == fixed_mode->hsync_start && |
| 1136 | scan->hsync_end == fixed_mode->hsync_end && |
| 1137 | scan->htotal == fixed_mode->htotal && |
| 1138 | scan->vdisplay == fixed_mode->vdisplay && |
| 1139 | scan->vsync_start == fixed_mode->vsync_start && |
| 1140 | scan->vsync_end == fixed_mode->vsync_end && |
| 1141 | scan->vtotal == fixed_mode->vtotal) { |
| 1142 | if (scan->clock < temp_downclock) { |
| 1143 | /* |
| 1144 | * The downclock is already found. But we |
| 1145 | * expect to find the lower downclock. |
| 1146 | */ |
| 1147 | temp_downclock = scan->clock; |
| 1148 | tmp_mode = scan; |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | if (temp_downclock < fixed_mode->clock) |
| 1154 | return drm_mode_duplicate(dev, tmp_mode); |
| 1155 | else |
| 1156 | return NULL; |
| 1157 | } |
| 1158 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1159 | /* Set up chip specific backlight functions */ |
| 1160 | void intel_panel_init_backlight_funcs(struct drm_device *dev) |
| 1161 | { |
| 1162 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1163 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1164 | if (IS_BROADWELL(dev)) { |
| 1165 | dev_priv->display.setup_backlight = bdw_setup_backlight; |
| 1166 | dev_priv->display.enable_backlight = bdw_enable_backlight; |
| 1167 | dev_priv->display.disable_backlight = pch_disable_backlight; |
| 1168 | dev_priv->display.set_backlight = bdw_set_backlight; |
| 1169 | dev_priv->display.get_backlight = bdw_get_backlight; |
| 1170 | } else if (HAS_PCH_SPLIT(dev)) { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1171 | dev_priv->display.setup_backlight = pch_setup_backlight; |
| 1172 | dev_priv->display.enable_backlight = pch_enable_backlight; |
| 1173 | dev_priv->display.disable_backlight = pch_disable_backlight; |
| 1174 | dev_priv->display.set_backlight = pch_set_backlight; |
| 1175 | dev_priv->display.get_backlight = pch_get_backlight; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1176 | } else if (IS_VALLEYVIEW(dev)) { |
| 1177 | dev_priv->display.setup_backlight = vlv_setup_backlight; |
| 1178 | dev_priv->display.enable_backlight = vlv_enable_backlight; |
| 1179 | dev_priv->display.disable_backlight = vlv_disable_backlight; |
| 1180 | dev_priv->display.set_backlight = vlv_set_backlight; |
| 1181 | dev_priv->display.get_backlight = vlv_get_backlight; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1182 | } else if (IS_GEN4(dev)) { |
| 1183 | dev_priv->display.setup_backlight = i965_setup_backlight; |
| 1184 | dev_priv->display.enable_backlight = i965_enable_backlight; |
| 1185 | dev_priv->display.disable_backlight = i965_disable_backlight; |
| 1186 | dev_priv->display.set_backlight = i9xx_set_backlight; |
| 1187 | dev_priv->display.get_backlight = i9xx_get_backlight; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1188 | } else { |
| 1189 | dev_priv->display.setup_backlight = i9xx_setup_backlight; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 1190 | dev_priv->display.enable_backlight = i9xx_enable_backlight; |
| 1191 | dev_priv->display.disable_backlight = i9xx_disable_backlight; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1192 | dev_priv->display.set_backlight = i9xx_set_backlight; |
| 1193 | dev_priv->display.get_backlight = i9xx_get_backlight; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1197 | int intel_panel_init(struct intel_panel *panel, |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1198 | struct drm_display_mode *fixed_mode, |
| 1199 | struct drm_display_mode *downclock_mode) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1200 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1201 | panel->fixed_mode = fixed_mode; |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1202 | panel->downclock_mode = downclock_mode; |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1203 | |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | void intel_panel_fini(struct intel_panel *panel) |
| 1208 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1209 | struct intel_connector *intel_connector = |
| 1210 | container_of(panel, struct intel_connector, panel); |
| 1211 | |
| 1212 | if (panel->fixed_mode) |
| 1213 | drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode); |
Vandana Kannan | ec9ed19 | 2013-12-10 13:37:36 +0530 | [diff] [blame] | 1214 | |
| 1215 | if (panel->downclock_mode) |
| 1216 | drm_mode_destroy(intel_connector->base.dev, |
| 1217 | panel->downclock_mode); |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1218 | } |