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