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