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 |
| 39 | intel_fixed_panel_mode(struct drm_display_mode *fixed_mode, |
| 40 | struct drm_display_mode *adjusted_mode) |
| 41 | { |
| 42 | adjusted_mode->hdisplay = fixed_mode->hdisplay; |
| 43 | adjusted_mode->hsync_start = fixed_mode->hsync_start; |
| 44 | adjusted_mode->hsync_end = fixed_mode->hsync_end; |
| 45 | adjusted_mode->htotal = fixed_mode->htotal; |
| 46 | |
| 47 | adjusted_mode->vdisplay = fixed_mode->vdisplay; |
| 48 | adjusted_mode->vsync_start = fixed_mode->vsync_start; |
| 49 | adjusted_mode->vsync_end = fixed_mode->vsync_end; |
| 50 | adjusted_mode->vtotal = fixed_mode->vtotal; |
| 51 | |
| 52 | adjusted_mode->clock = fixed_mode->clock; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* adjusted_mode has been preset to be the panel's fixed mode */ |
| 56 | void |
| 57 | intel_pch_panel_fitting(struct drm_device *dev, |
| 58 | int fitting_mode, |
Daniel Vetter | cb1793c | 2012-06-04 18:39:21 +0200 | [diff] [blame] | 59 | const struct drm_display_mode *mode, |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 60 | struct drm_display_mode *adjusted_mode) |
| 61 | { |
| 62 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 63 | int x, y, width, height; |
| 64 | |
| 65 | x = y = width = height = 0; |
| 66 | |
| 67 | /* Native modes don't need fitting */ |
| 68 | if (adjusted_mode->hdisplay == mode->hdisplay && |
| 69 | adjusted_mode->vdisplay == mode->vdisplay) |
| 70 | goto done; |
| 71 | |
| 72 | switch (fitting_mode) { |
| 73 | case DRM_MODE_SCALE_CENTER: |
| 74 | width = mode->hdisplay; |
| 75 | height = mode->vdisplay; |
| 76 | x = (adjusted_mode->hdisplay - width + 1)/2; |
| 77 | y = (adjusted_mode->vdisplay - height + 1)/2; |
| 78 | break; |
| 79 | |
| 80 | case DRM_MODE_SCALE_ASPECT: |
| 81 | /* Scale but preserve the aspect ratio */ |
| 82 | { |
| 83 | u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay; |
| 84 | u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay; |
| 85 | if (scaled_width > scaled_height) { /* pillar */ |
| 86 | width = scaled_height / mode->vdisplay; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 87 | if (width & 1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 88 | width++; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 89 | x = (adjusted_mode->hdisplay - width + 1) / 2; |
| 90 | y = 0; |
| 91 | height = adjusted_mode->vdisplay; |
| 92 | } else if (scaled_width < scaled_height) { /* letter */ |
| 93 | height = scaled_width / mode->hdisplay; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 94 | if (height & 1) |
| 95 | height++; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 96 | y = (adjusted_mode->vdisplay - height + 1) / 2; |
| 97 | x = 0; |
| 98 | width = adjusted_mode->hdisplay; |
| 99 | } else { |
| 100 | x = y = 0; |
| 101 | width = adjusted_mode->hdisplay; |
| 102 | height = adjusted_mode->vdisplay; |
| 103 | } |
| 104 | } |
| 105 | break; |
| 106 | |
| 107 | default: |
| 108 | case DRM_MODE_SCALE_FULLSCREEN: |
| 109 | x = y = 0; |
| 110 | width = adjusted_mode->hdisplay; |
| 111 | height = adjusted_mode->vdisplay; |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | done: |
| 116 | dev_priv->pch_pf_pos = (x << 16) | y; |
| 117 | dev_priv->pch_pf_size = (width << 16) | height; |
| 118 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 119 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame^] | 120 | static void |
| 121 | centre_horizontally(struct drm_display_mode *mode, |
| 122 | int width) |
| 123 | { |
| 124 | u32 border, sync_pos, blank_width, sync_width; |
| 125 | |
| 126 | /* keep the hsync and hblank widths constant */ |
| 127 | sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 128 | blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start; |
| 129 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 130 | |
| 131 | border = (mode->hdisplay - width + 1) / 2; |
| 132 | border += border & 1; /* make the border even */ |
| 133 | |
| 134 | mode->crtc_hdisplay = width; |
| 135 | mode->crtc_hblank_start = width + border; |
| 136 | mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width; |
| 137 | |
| 138 | mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos; |
| 139 | mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width; |
| 140 | } |
| 141 | |
| 142 | static void |
| 143 | centre_vertically(struct drm_display_mode *mode, |
| 144 | int height) |
| 145 | { |
| 146 | u32 border, sync_pos, blank_width, sync_width; |
| 147 | |
| 148 | /* keep the vsync and vblank widths constant */ |
| 149 | sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 150 | blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start; |
| 151 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 152 | |
| 153 | border = (mode->vdisplay - height + 1) / 2; |
| 154 | |
| 155 | mode->crtc_vdisplay = height; |
| 156 | mode->crtc_vblank_start = height + border; |
| 157 | mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width; |
| 158 | |
| 159 | mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos; |
| 160 | mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width; |
| 161 | } |
| 162 | |
| 163 | static inline u32 panel_fitter_scaling(u32 source, u32 target) |
| 164 | { |
| 165 | /* |
| 166 | * Floating point operation is not supported. So the FACTOR |
| 167 | * is defined, which can avoid the floating point computation |
| 168 | * when calculating the panel ratio. |
| 169 | */ |
| 170 | #define ACCURACY 12 |
| 171 | #define FACTOR (1 << ACCURACY) |
| 172 | u32 ratio = source * FACTOR / target; |
| 173 | return (FACTOR * ratio + FACTOR/2) / FACTOR; |
| 174 | } |
| 175 | |
| 176 | void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc, |
| 177 | struct intel_crtc_config *pipe_config, |
| 178 | int fitting_mode) |
| 179 | { |
| 180 | struct drm_device *dev = intel_crtc->base.dev; |
| 181 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 182 | u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0; |
| 183 | struct drm_display_mode *mode, *adjusted_mode; |
| 184 | |
| 185 | mode = &pipe_config->requested_mode; |
| 186 | adjusted_mode = &pipe_config->adjusted_mode; |
| 187 | |
| 188 | /* Native modes don't need fitting */ |
| 189 | if (adjusted_mode->hdisplay == mode->hdisplay && |
| 190 | adjusted_mode->vdisplay == mode->vdisplay) |
| 191 | goto out; |
| 192 | |
| 193 | switch (fitting_mode) { |
| 194 | case DRM_MODE_SCALE_CENTER: |
| 195 | /* |
| 196 | * For centered modes, we have to calculate border widths & |
| 197 | * heights and modify the values programmed into the CRTC. |
| 198 | */ |
| 199 | centre_horizontally(adjusted_mode, mode->hdisplay); |
| 200 | centre_vertically(adjusted_mode, mode->vdisplay); |
| 201 | border = LVDS_BORDER_ENABLE; |
| 202 | break; |
| 203 | case DRM_MODE_SCALE_ASPECT: |
| 204 | /* Scale but preserve the aspect ratio */ |
| 205 | if (INTEL_INFO(dev)->gen >= 4) { |
| 206 | u32 scaled_width = adjusted_mode->hdisplay * |
| 207 | mode->vdisplay; |
| 208 | u32 scaled_height = mode->hdisplay * |
| 209 | adjusted_mode->vdisplay; |
| 210 | |
| 211 | /* 965+ is easy, it does everything in hw */ |
| 212 | if (scaled_width > scaled_height) |
| 213 | pfit_control |= PFIT_ENABLE | |
| 214 | PFIT_SCALING_PILLAR; |
| 215 | else if (scaled_width < scaled_height) |
| 216 | pfit_control |= PFIT_ENABLE | |
| 217 | PFIT_SCALING_LETTER; |
| 218 | else if (adjusted_mode->hdisplay != mode->hdisplay) |
| 219 | pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO; |
| 220 | } else { |
| 221 | u32 scaled_width = adjusted_mode->hdisplay * |
| 222 | mode->vdisplay; |
| 223 | u32 scaled_height = mode->hdisplay * |
| 224 | adjusted_mode->vdisplay; |
| 225 | /* |
| 226 | * For earlier chips we have to calculate the scaling |
| 227 | * ratio by hand and program it into the |
| 228 | * PFIT_PGM_RATIO register |
| 229 | */ |
| 230 | if (scaled_width > scaled_height) { /* pillar */ |
| 231 | centre_horizontally(adjusted_mode, |
| 232 | scaled_height / |
| 233 | mode->vdisplay); |
| 234 | |
| 235 | border = LVDS_BORDER_ENABLE; |
| 236 | if (mode->vdisplay != adjusted_mode->vdisplay) { |
| 237 | u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay); |
| 238 | pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 239 | bits << PFIT_VERT_SCALE_SHIFT); |
| 240 | pfit_control |= (PFIT_ENABLE | |
| 241 | VERT_INTERP_BILINEAR | |
| 242 | HORIZ_INTERP_BILINEAR); |
| 243 | } |
| 244 | } else if (scaled_width < scaled_height) { /* letter */ |
| 245 | centre_vertically(adjusted_mode, |
| 246 | scaled_width / |
| 247 | mode->hdisplay); |
| 248 | |
| 249 | border = LVDS_BORDER_ENABLE; |
| 250 | if (mode->hdisplay != adjusted_mode->hdisplay) { |
| 251 | u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay); |
| 252 | pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 253 | bits << PFIT_VERT_SCALE_SHIFT); |
| 254 | pfit_control |= (PFIT_ENABLE | |
| 255 | VERT_INTERP_BILINEAR | |
| 256 | HORIZ_INTERP_BILINEAR); |
| 257 | } |
| 258 | } else { |
| 259 | /* Aspects match, Let hw scale both directions */ |
| 260 | pfit_control |= (PFIT_ENABLE | |
| 261 | VERT_AUTO_SCALE | HORIZ_AUTO_SCALE | |
| 262 | VERT_INTERP_BILINEAR | |
| 263 | HORIZ_INTERP_BILINEAR); |
| 264 | } |
| 265 | } |
| 266 | break; |
| 267 | default: |
| 268 | case DRM_MODE_SCALE_FULLSCREEN: |
| 269 | /* |
| 270 | * Full scaling, even if it changes the aspect ratio. |
| 271 | * Fortunately this is all done for us in hw. |
| 272 | */ |
| 273 | if (mode->vdisplay != adjusted_mode->vdisplay || |
| 274 | mode->hdisplay != adjusted_mode->hdisplay) { |
| 275 | pfit_control |= PFIT_ENABLE; |
| 276 | if (INTEL_INFO(dev)->gen >= 4) |
| 277 | pfit_control |= PFIT_SCALING_AUTO; |
| 278 | else |
| 279 | pfit_control |= (VERT_AUTO_SCALE | |
| 280 | VERT_INTERP_BILINEAR | |
| 281 | HORIZ_AUTO_SCALE | |
| 282 | HORIZ_INTERP_BILINEAR); |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | /* 965+ wants fuzzy fitting */ |
| 288 | /* FIXME: handle multiple panels by failing gracefully */ |
| 289 | if (INTEL_INFO(dev)->gen >= 4) |
| 290 | pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) | |
| 291 | PFIT_FILTER_FUZZY); |
| 292 | |
| 293 | out: |
| 294 | if ((pfit_control & PFIT_ENABLE) == 0) { |
| 295 | pfit_control = 0; |
| 296 | pfit_pgm_ratios = 0; |
| 297 | } |
| 298 | |
| 299 | /* Make sure pre-965 set dither correctly for 18bpp panels. */ |
| 300 | if (INTEL_INFO(dev)->gen < 4 && pipe_config->pipe_bpp == 18) |
| 301 | pfit_control |= PANEL_8TO6_DITHER_ENABLE; |
| 302 | |
| 303 | if (pfit_control != pipe_config->pfit_control || |
| 304 | pfit_pgm_ratios != pipe_config->pfit_pgm_ratios) { |
| 305 | pipe_config->pfit_control = pfit_control; |
| 306 | pipe_config->pfit_pgm_ratios = pfit_pgm_ratios; |
| 307 | } |
| 308 | dev_priv->lvds_border_bits = border; |
| 309 | } |
| 310 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 311 | static int is_backlight_combination_mode(struct drm_device *dev) |
| 312 | { |
| 313 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 314 | |
| 315 | if (INTEL_INFO(dev)->gen >= 4) |
| 316 | return I915_READ(BLC_PWM_CTL2) & BLM_COMBINATION_MODE; |
| 317 | |
| 318 | if (IS_GEN2(dev)) |
| 319 | return I915_READ(BLC_PWM_CTL) & BLM_LEGACY_MODE; |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 324 | /* XXX: query mode clock or hardware clock and program max PWM appropriately |
| 325 | * when it's 0. |
| 326 | */ |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 327 | static u32 i915_read_blc_pwm_ctl(struct drm_device *dev) |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 328 | { |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 329 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 330 | u32 val; |
| 331 | |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 332 | WARN_ON(!spin_is_locked(&dev_priv->backlight.lock)); |
| 333 | |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 334 | /* Restore the CTL value if it lost, e.g. GPU reset */ |
| 335 | |
| 336 | if (HAS_PCH_SPLIT(dev_priv->dev)) { |
| 337 | val = I915_READ(BLC_PWM_PCH_CTL2); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 338 | if (dev_priv->regfile.saveBLC_PWM_CTL2 == 0) { |
| 339 | dev_priv->regfile.saveBLC_PWM_CTL2 = val; |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 340 | } else if (val == 0) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 341 | val = dev_priv->regfile.saveBLC_PWM_CTL2; |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 342 | I915_WRITE(BLC_PWM_PCH_CTL2, val); |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 343 | } |
| 344 | } else { |
| 345 | val = I915_READ(BLC_PWM_CTL); |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 346 | if (dev_priv->regfile.saveBLC_PWM_CTL == 0) { |
| 347 | dev_priv->regfile.saveBLC_PWM_CTL = val; |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 348 | if (INTEL_INFO(dev)->gen >= 4) |
| 349 | dev_priv->regfile.saveBLC_PWM_CTL2 = |
| 350 | I915_READ(BLC_PWM_CTL2); |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 351 | } else if (val == 0) { |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 352 | val = dev_priv->regfile.saveBLC_PWM_CTL; |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 353 | I915_WRITE(BLC_PWM_CTL, val); |
| 354 | if (INTEL_INFO(dev)->gen >= 4) |
| 355 | I915_WRITE(BLC_PWM_CTL2, |
| 356 | dev_priv->regfile.saveBLC_PWM_CTL2); |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | return val; |
| 361 | } |
| 362 | |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 363 | static u32 intel_panel_get_max_backlight(struct drm_device *dev) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 364 | { |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 365 | u32 max; |
| 366 | |
Jani Nikula | bfd7590 | 2012-12-04 16:36:28 +0200 | [diff] [blame] | 367 | max = i915_read_blc_pwm_ctl(dev); |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 368 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 369 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 370 | max >>= 16; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 371 | } else { |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 372 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 373 | max >>= 17; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 374 | else |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 375 | max >>= 16; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 376 | |
| 377 | if (is_backlight_combination_mode(dev)) |
| 378 | max *= 0xff; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 381 | DRM_DEBUG_DRIVER("max backlight PWM = %d\n", max); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 382 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 383 | return max; |
| 384 | } |
| 385 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 386 | static int i915_panel_invert_brightness; |
| 387 | MODULE_PARM_DESC(invert_brightness, "Invert backlight brightness " |
| 388 | "(-1 force normal, 0 machine defaults, 1 force inversion), please " |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 389 | "report PCI device ID, subsystem vendor and subsystem device ID " |
| 390 | "to dri-devel@lists.freedesktop.org, if your machine needs it. " |
| 391 | "It will then be included in an upcoming module version."); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 392 | module_param_named(invert_brightness, i915_panel_invert_brightness, int, 0600); |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 393 | static u32 intel_panel_compute_brightness(struct drm_device *dev, u32 val) |
| 394 | { |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 395 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 396 | |
| 397 | if (i915_panel_invert_brightness < 0) |
| 398 | return val; |
| 399 | |
| 400 | if (i915_panel_invert_brightness > 0 || |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 401 | dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) { |
| 402 | u32 max = intel_panel_get_max_backlight(dev); |
| 403 | if (max) |
| 404 | return max - val; |
| 405 | } |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 406 | |
| 407 | return val; |
| 408 | } |
| 409 | |
Stéphane Marchesin | faea35d | 2012-07-30 13:51:38 -0700 | [diff] [blame] | 410 | static u32 intel_panel_get_backlight(struct drm_device *dev) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 411 | { |
| 412 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 413 | u32 val; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 414 | unsigned long flags; |
| 415 | |
| 416 | spin_lock_irqsave(&dev_priv->backlight.lock, flags); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 417 | |
| 418 | if (HAS_PCH_SPLIT(dev)) { |
| 419 | val = I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 420 | } else { |
| 421 | val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 422 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 423 | val >>= 1; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 424 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 425 | if (is_backlight_combination_mode(dev)) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 426 | u8 lbpc; |
| 427 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 428 | pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc); |
| 429 | val *= lbpc; |
| 430 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 433 | val = intel_panel_compute_brightness(dev, val); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 434 | |
| 435 | spin_unlock_irqrestore(&dev_priv->backlight.lock, flags); |
| 436 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 437 | DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val); |
| 438 | return val; |
| 439 | } |
| 440 | |
| 441 | static void intel_pch_panel_set_backlight(struct drm_device *dev, u32 level) |
| 442 | { |
| 443 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 444 | u32 val = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 445 | I915_WRITE(BLC_PWM_CPU_CTL, val | level); |
| 446 | } |
| 447 | |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 448 | static void intel_panel_actually_set_backlight(struct drm_device *dev, u32 level) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 449 | { |
| 450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 451 | u32 tmp; |
| 452 | |
| 453 | DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level); |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 454 | level = intel_panel_compute_brightness(dev, level); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 455 | |
| 456 | if (HAS_PCH_SPLIT(dev)) |
| 457 | return intel_pch_panel_set_backlight(dev, level); |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 458 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 459 | if (is_backlight_combination_mode(dev)) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 460 | u32 max = intel_panel_get_max_backlight(dev); |
| 461 | u8 lbpc; |
| 462 | |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 463 | /* we're screwed, but keep behaviour backwards compatible */ |
| 464 | if (!max) |
| 465 | max = 1; |
| 466 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 467 | lbpc = level * 0xfe / max + 1; |
| 468 | level /= lbpc; |
| 469 | pci_write_config_byte(dev->pdev, PCI_LBPC, lbpc); |
| 470 | } |
| 471 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 472 | tmp = I915_READ(BLC_PWM_CTL); |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 473 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 474 | level <<= 1; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 475 | tmp &= ~BACKLIGHT_DUTY_CYCLE_MASK; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 476 | I915_WRITE(BLC_PWM_CTL, tmp | level); |
| 477 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 478 | |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 479 | /* set backlight brightness to level in range [0..max] */ |
| 480 | void intel_panel_set_backlight(struct drm_device *dev, u32 level, u32 max) |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 481 | { |
| 482 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 483 | u32 freq; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 484 | unsigned long flags; |
| 485 | |
| 486 | spin_lock_irqsave(&dev_priv->backlight.lock, flags); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 487 | |
| 488 | freq = intel_panel_get_max_backlight(dev); |
| 489 | if (!freq) { |
| 490 | /* we are screwed, bail out */ |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 491 | goto out; |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* scale to hardware */ |
| 495 | level = level * freq / max; |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 496 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 497 | dev_priv->backlight.level = level; |
| 498 | if (dev_priv->backlight.device) |
| 499 | dev_priv->backlight.device->props.brightness = level; |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 500 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 501 | if (dev_priv->backlight.enabled) |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 502 | intel_panel_actually_set_backlight(dev, level); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 503 | out: |
| 504 | spin_unlock_irqrestore(&dev_priv->backlight.lock, flags); |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 507 | void intel_panel_disable_backlight(struct drm_device *dev) |
| 508 | { |
| 509 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 510 | unsigned long flags; |
| 511 | |
| 512 | spin_lock_irqsave(&dev_priv->backlight.lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 513 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 514 | dev_priv->backlight.enabled = false; |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 515 | intel_panel_actually_set_backlight(dev, 0); |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 516 | |
| 517 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | a4f32fc | 2012-07-14 11:57:12 -0300 | [diff] [blame] | 518 | uint32_t reg, tmp; |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 519 | |
| 520 | reg = HAS_PCH_SPLIT(dev) ? BLC_PWM_CPU_CTL2 : BLC_PWM_CTL2; |
| 521 | |
| 522 | I915_WRITE(reg, I915_READ(reg) & ~BLM_PWM_ENABLE); |
Paulo Zanoni | a4f32fc | 2012-07-14 11:57:12 -0300 | [diff] [blame] | 523 | |
| 524 | if (HAS_PCH_SPLIT(dev)) { |
| 525 | tmp = I915_READ(BLC_PWM_PCH_CTL1); |
| 526 | tmp &= ~BLM_PCH_PWM_ENABLE; |
| 527 | I915_WRITE(BLC_PWM_PCH_CTL1, tmp); |
| 528 | } |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 529 | } |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 530 | |
| 531 | spin_unlock_irqrestore(&dev_priv->backlight.lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 534 | void intel_panel_enable_backlight(struct drm_device *dev, |
| 535 | enum pipe pipe) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 536 | { |
| 537 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 35ffda4 | 2013-04-25 16:49:25 +0300 | [diff] [blame] | 538 | enum transcoder cpu_transcoder = |
| 539 | intel_pipe_to_cpu_transcoder(dev_priv, pipe); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 540 | unsigned long flags; |
| 541 | |
| 542 | spin_lock_irqsave(&dev_priv->backlight.lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 543 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 544 | if (dev_priv->backlight.level == 0) { |
| 545 | dev_priv->backlight.level = intel_panel_get_max_backlight(dev); |
| 546 | if (dev_priv->backlight.device) |
| 547 | dev_priv->backlight.device->props.brightness = |
| 548 | dev_priv->backlight.level; |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 549 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 550 | |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 551 | if (INTEL_INFO(dev)->gen >= 4) { |
| 552 | uint32_t reg, tmp; |
| 553 | |
| 554 | reg = HAS_PCH_SPLIT(dev) ? BLC_PWM_CPU_CTL2 : BLC_PWM_CTL2; |
| 555 | |
| 556 | |
| 557 | tmp = I915_READ(reg); |
| 558 | |
| 559 | /* Note that this can also get called through dpms changes. And |
| 560 | * we don't track the backlight dpms state, hence check whether |
| 561 | * we have to do anything first. */ |
| 562 | if (tmp & BLM_PWM_ENABLE) |
Takashi Iwai | 770c123 | 2012-08-11 08:56:42 +0200 | [diff] [blame] | 563 | goto set_level; |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 564 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 565 | if (INTEL_INFO(dev)->num_pipes == 3) |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 566 | tmp &= ~BLM_PIPE_SELECT_IVB; |
| 567 | else |
| 568 | tmp &= ~BLM_PIPE_SELECT; |
| 569 | |
Jani Nikula | 35ffda4 | 2013-04-25 16:49:25 +0300 | [diff] [blame] | 570 | if (cpu_transcoder == TRANSCODER_EDP) |
| 571 | tmp |= BLM_TRANSCODER_EDP; |
| 572 | else |
| 573 | tmp |= BLM_PIPE(cpu_transcoder); |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 574 | tmp &= ~BLM_PWM_ENABLE; |
| 575 | |
| 576 | I915_WRITE(reg, tmp); |
| 577 | POSTING_READ(reg); |
| 578 | I915_WRITE(reg, tmp | BLM_PWM_ENABLE); |
Paulo Zanoni | a4f32fc | 2012-07-14 11:57:12 -0300 | [diff] [blame] | 579 | |
| 580 | if (HAS_PCH_SPLIT(dev)) { |
| 581 | tmp = I915_READ(BLC_PWM_PCH_CTL1); |
| 582 | tmp |= BLM_PCH_PWM_ENABLE; |
| 583 | tmp &= ~BLM_PCH_OVERRIDE_ENABLE; |
| 584 | I915_WRITE(BLC_PWM_PCH_CTL1, tmp); |
| 585 | } |
Daniel Vetter | 24ded20 | 2012-06-05 12:14:54 +0200 | [diff] [blame] | 586 | } |
Takashi Iwai | 770c123 | 2012-08-11 08:56:42 +0200 | [diff] [blame] | 587 | |
| 588 | set_level: |
Daniel Vetter | b128937 | 2013-03-22 15:44:46 +0100 | [diff] [blame] | 589 | /* Call below after setting BLC_PWM_CPU_CTL2 and BLC_PWM_PCH_CTL1. |
| 590 | * BLC_PWM_CPU_CTL may be cleared to zero automatically when these |
| 591 | * registers are set. |
Takashi Iwai | 770c123 | 2012-08-11 08:56:42 +0200 | [diff] [blame] | 592 | */ |
Daniel Vetter | ecb135a | 2013-04-03 11:25:32 +0200 | [diff] [blame] | 593 | dev_priv->backlight.enabled = true; |
| 594 | intel_panel_actually_set_backlight(dev, dev_priv->backlight.level); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 595 | |
| 596 | spin_unlock_irqrestore(&dev_priv->backlight.lock, flags); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 599 | static void intel_panel_init_backlight(struct drm_device *dev) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 600 | { |
| 601 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 602 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 603 | dev_priv->backlight.level = intel_panel_get_backlight(dev); |
| 604 | dev_priv->backlight.enabled = dev_priv->backlight.level != 0; |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 605 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 606 | |
| 607 | enum drm_connector_status |
| 608 | intel_panel_detect(struct drm_device *dev) |
| 609 | { |
| 610 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 611 | |
| 612 | /* Assume that the BIOS does not lie through the OpRegion... */ |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 613 | if (!i915_panel_ignore_lid && dev_priv->opregion.lid_state) { |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 614 | return ioread32(dev_priv->opregion.lid_state) & 0x1 ? |
| 615 | connector_status_connected : |
| 616 | connector_status_disconnected; |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 617 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 618 | |
Daniel Vetter | a726915 | 2012-11-20 14:50:08 +0100 | [diff] [blame] | 619 | switch (i915_panel_ignore_lid) { |
| 620 | case -2: |
| 621 | return connector_status_connected; |
| 622 | case -1: |
| 623 | return connector_status_disconnected; |
| 624 | default: |
| 625 | return connector_status_unknown; |
| 626 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 627 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 628 | |
| 629 | #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE |
| 630 | static int intel_panel_update_status(struct backlight_device *bd) |
| 631 | { |
| 632 | struct drm_device *dev = bl_get_data(bd); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 633 | intel_panel_set_backlight(dev, bd->props.brightness, |
| 634 | bd->props.max_brightness); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static int intel_panel_get_brightness(struct backlight_device *bd) |
| 639 | { |
| 640 | struct drm_device *dev = bl_get_data(bd); |
Jani Nikula | 7c23396 | 2013-03-12 11:44:16 +0200 | [diff] [blame] | 641 | return intel_panel_get_backlight(dev); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static const struct backlight_ops intel_panel_bl_ops = { |
| 645 | .update_status = intel_panel_update_status, |
| 646 | .get_brightness = intel_panel_get_brightness, |
| 647 | }; |
| 648 | |
Jani Nikula | 0657b6b | 2012-10-19 14:51:46 +0300 | [diff] [blame] | 649 | int intel_panel_setup_backlight(struct drm_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 650 | { |
Jani Nikula | 0657b6b | 2012-10-19 14:51:46 +0300 | [diff] [blame] | 651 | struct drm_device *dev = connector->dev; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 652 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 653 | struct backlight_properties props; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 654 | unsigned long flags; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 655 | |
| 656 | intel_panel_init_backlight(dev); |
| 657 | |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 658 | if (WARN_ON(dev_priv->backlight.device)) |
| 659 | return -ENODEV; |
| 660 | |
Corentin Chary | af437cf | 2012-05-22 10:29:46 +0100 | [diff] [blame] | 661 | memset(&props, 0, sizeof(props)); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 662 | props.type = BACKLIGHT_RAW; |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 663 | props.brightness = dev_priv->backlight.level; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 664 | |
| 665 | spin_lock_irqsave(&dev_priv->backlight.lock, flags); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 666 | props.max_brightness = intel_panel_get_max_backlight(dev); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 667 | spin_unlock_irqrestore(&dev_priv->backlight.lock, flags); |
| 668 | |
Jani Nikula | 28dcc2d | 2012-09-03 16:25:12 +0300 | [diff] [blame] | 669 | if (props.max_brightness == 0) { |
Jani Nikula | e86b618 | 2012-10-25 10:57:38 +0300 | [diff] [blame] | 670 | DRM_DEBUG_DRIVER("Failed to get maximum backlight value\n"); |
Jani Nikula | 28dcc2d | 2012-09-03 16:25:12 +0300 | [diff] [blame] | 671 | return -ENODEV; |
| 672 | } |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 673 | dev_priv->backlight.device = |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 674 | backlight_device_register("intel_backlight", |
| 675 | &connector->kdev, dev, |
| 676 | &intel_panel_bl_ops, &props); |
| 677 | |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 678 | if (IS_ERR(dev_priv->backlight.device)) { |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 679 | DRM_ERROR("Failed to register backlight: %ld\n", |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 680 | PTR_ERR(dev_priv->backlight.device)); |
| 681 | dev_priv->backlight.device = NULL; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 682 | return -ENODEV; |
| 683 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | void intel_panel_destroy_backlight(struct drm_device *dev) |
| 688 | { |
| 689 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 690 | if (dev_priv->backlight.device) { |
Jani Nikula | 31ad8ec | 2013-04-02 15:48:09 +0300 | [diff] [blame] | 691 | backlight_device_unregister(dev_priv->backlight.device); |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 692 | dev_priv->backlight.device = NULL; |
| 693 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 694 | } |
| 695 | #else |
Jani Nikula | 0657b6b | 2012-10-19 14:51:46 +0300 | [diff] [blame] | 696 | int intel_panel_setup_backlight(struct drm_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 697 | { |
Jani Nikula | 0657b6b | 2012-10-19 14:51:46 +0300 | [diff] [blame] | 698 | intel_panel_init_backlight(connector->dev); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | void intel_panel_destroy_backlight(struct drm_device *dev) |
| 703 | { |
| 704 | return; |
| 705 | } |
| 706 | #endif |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 707 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 708 | int intel_panel_init(struct intel_panel *panel, |
| 709 | struct drm_display_mode *fixed_mode) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 710 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 711 | panel->fixed_mode = fixed_mode; |
| 712 | |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | void intel_panel_fini(struct intel_panel *panel) |
| 717 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 718 | struct intel_connector *intel_connector = |
| 719 | container_of(panel, struct intel_connector, panel); |
| 720 | |
| 721 | if (panel->fixed_mode) |
| 722 | drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode); |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 723 | } |