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