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