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