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 | |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame^] | 31 | #include <linux/moduleparam.h> |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 32 | #include "intel_drv.h" |
| 33 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 34 | #define PCI_LBPC 0xf4 /* legacy/combination backlight modes */ |
| 35 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 36 | void |
| 37 | intel_fixed_panel_mode(struct drm_display_mode *fixed_mode, |
| 38 | struct drm_display_mode *adjusted_mode) |
| 39 | { |
| 40 | adjusted_mode->hdisplay = fixed_mode->hdisplay; |
| 41 | adjusted_mode->hsync_start = fixed_mode->hsync_start; |
| 42 | adjusted_mode->hsync_end = fixed_mode->hsync_end; |
| 43 | adjusted_mode->htotal = fixed_mode->htotal; |
| 44 | |
| 45 | adjusted_mode->vdisplay = fixed_mode->vdisplay; |
| 46 | adjusted_mode->vsync_start = fixed_mode->vsync_start; |
| 47 | adjusted_mode->vsync_end = fixed_mode->vsync_end; |
| 48 | adjusted_mode->vtotal = fixed_mode->vtotal; |
| 49 | |
| 50 | adjusted_mode->clock = fixed_mode->clock; |
| 51 | |
Daniel Vetter | ca9bfa7 | 2012-01-28 14:49:20 +0100 | [diff] [blame] | 52 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
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, |
| 59 | struct drm_display_mode *mode, |
| 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 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 120 | static int is_backlight_combination_mode(struct drm_device *dev) |
| 121 | { |
| 122 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 123 | |
| 124 | if (INTEL_INFO(dev)->gen >= 4) |
| 125 | return I915_READ(BLC_PWM_CTL2) & BLM_COMBINATION_MODE; |
| 126 | |
| 127 | if (IS_GEN2(dev)) |
| 128 | return I915_READ(BLC_PWM_CTL) & BLM_LEGACY_MODE; |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 133 | static u32 i915_read_blc_pwm_ctl(struct drm_i915_private *dev_priv) |
| 134 | { |
| 135 | u32 val; |
| 136 | |
| 137 | /* Restore the CTL value if it lost, e.g. GPU reset */ |
| 138 | |
| 139 | if (HAS_PCH_SPLIT(dev_priv->dev)) { |
| 140 | val = I915_READ(BLC_PWM_PCH_CTL2); |
| 141 | if (dev_priv->saveBLC_PWM_CTL2 == 0) { |
| 142 | dev_priv->saveBLC_PWM_CTL2 = val; |
| 143 | } else if (val == 0) { |
| 144 | I915_WRITE(BLC_PWM_PCH_CTL2, |
Simon Que | 2aded1b | 2011-11-10 17:50:26 -0800 | [diff] [blame] | 145 | dev_priv->saveBLC_PWM_CTL2); |
| 146 | val = dev_priv->saveBLC_PWM_CTL2; |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 147 | } |
| 148 | } else { |
| 149 | val = I915_READ(BLC_PWM_CTL); |
| 150 | if (dev_priv->saveBLC_PWM_CTL == 0) { |
| 151 | dev_priv->saveBLC_PWM_CTL = val; |
| 152 | dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2); |
| 153 | } else if (val == 0) { |
| 154 | I915_WRITE(BLC_PWM_CTL, |
| 155 | dev_priv->saveBLC_PWM_CTL); |
| 156 | I915_WRITE(BLC_PWM_CTL2, |
| 157 | dev_priv->saveBLC_PWM_CTL2); |
| 158 | val = dev_priv->saveBLC_PWM_CTL; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return val; |
| 163 | } |
| 164 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 165 | u32 intel_panel_get_max_backlight(struct drm_device *dev) |
| 166 | { |
| 167 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 168 | u32 max; |
| 169 | |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 170 | max = i915_read_blc_pwm_ctl(dev_priv); |
| 171 | if (max == 0) { |
| 172 | /* XXX add code here to query mode clock or hardware clock |
| 173 | * and program max PWM appropriately. |
| 174 | */ |
| 175 | printk_once(KERN_WARNING "fixme: max PWM is zero.\n"); |
| 176 | return 1; |
| 177 | } |
| 178 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 179 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | 0b0b053 | 2010-11-23 09:45:50 +0000 | [diff] [blame] | 180 | max >>= 16; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 181 | } else { |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 182 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 183 | max >>= 17; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 184 | else |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 185 | max >>= 16; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 186 | |
| 187 | if (is_backlight_combination_mode(dev)) |
| 188 | max *= 0xff; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 191 | DRM_DEBUG_DRIVER("max backlight PWM = %d\n", max); |
| 192 | return max; |
| 193 | } |
| 194 | |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame^] | 195 | static bool i915_panel_invert_brightness; |
| 196 | MODULE_PARM_DESC(invert_brightness, "Invert backlight brightness, please " |
| 197 | "report PCI device ID, subsystem vendor and subsystem device ID " |
| 198 | "to dri-devel@lists.freedesktop.org, if your machine needs it. " |
| 199 | "It will then be included in an upcoming module version."); |
| 200 | module_param_named(invert_brightness, i915_panel_invert_brightness, bool, 0600); |
| 201 | static u32 intel_panel_compute_brightness(struct drm_device *dev, u32 val) |
| 202 | { |
| 203 | if (i915_panel_invert_brightness) |
| 204 | return intel_panel_get_max_backlight(dev) - val; |
| 205 | |
| 206 | return val; |
| 207 | } |
| 208 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 209 | u32 intel_panel_get_backlight(struct drm_device *dev) |
| 210 | { |
| 211 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 212 | u32 val; |
| 213 | |
| 214 | if (HAS_PCH_SPLIT(dev)) { |
| 215 | val = I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 216 | } else { |
| 217 | val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 218 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 219 | val >>= 1; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 220 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 221 | if (is_backlight_combination_mode(dev)) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 222 | u8 lbpc; |
| 223 | |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 224 | pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc); |
| 225 | val *= lbpc; |
| 226 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame^] | 229 | val = intel_panel_compute_brightness(dev, val); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 230 | DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val); |
| 231 | return val; |
| 232 | } |
| 233 | |
| 234 | static void intel_pch_panel_set_backlight(struct drm_device *dev, u32 level) |
| 235 | { |
| 236 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 237 | u32 val = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 238 | I915_WRITE(BLC_PWM_CPU_CTL, val | level); |
| 239 | } |
| 240 | |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 241 | 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] | 242 | { |
| 243 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 244 | u32 tmp; |
| 245 | |
| 246 | DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level); |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame^] | 247 | level = intel_panel_compute_brightness(dev, level); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 248 | |
| 249 | if (HAS_PCH_SPLIT(dev)) |
| 250 | return intel_pch_panel_set_backlight(dev, level); |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 251 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | if (is_backlight_combination_mode(dev)) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 253 | u32 max = intel_panel_get_max_backlight(dev); |
| 254 | u8 lbpc; |
| 255 | |
| 256 | lbpc = level * 0xfe / max + 1; |
| 257 | level /= lbpc; |
| 258 | pci_write_config_byte(dev->pdev, PCI_LBPC, lbpc); |
| 259 | } |
| 260 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 261 | tmp = I915_READ(BLC_PWM_CTL); |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 262 | if (INTEL_INFO(dev)->gen < 4) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 263 | level <<= 1; |
Keith Packard | ca88479 | 2011-11-18 11:09:24 -0800 | [diff] [blame] | 264 | tmp &= ~BACKLIGHT_DUTY_CYCLE_MASK; |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 265 | I915_WRITE(BLC_PWM_CTL, tmp | level); |
| 266 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 267 | |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 268 | void intel_panel_set_backlight(struct drm_device *dev, u32 level) |
| 269 | { |
| 270 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 271 | |
| 272 | dev_priv->backlight_level = level; |
| 273 | if (dev_priv->backlight_enabled) |
| 274 | intel_panel_actually_set_backlight(dev, level); |
| 275 | } |
| 276 | |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 277 | void intel_panel_disable_backlight(struct drm_device *dev) |
| 278 | { |
| 279 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 280 | |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 281 | dev_priv->backlight_enabled = false; |
| 282 | intel_panel_actually_set_backlight(dev, 0); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void intel_panel_enable_backlight(struct drm_device *dev) |
| 286 | { |
| 287 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 288 | |
| 289 | if (dev_priv->backlight_level == 0) |
| 290 | dev_priv->backlight_level = intel_panel_get_max_backlight(dev); |
| 291 | |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 292 | dev_priv->backlight_enabled = true; |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 293 | intel_panel_actually_set_backlight(dev, dev_priv->backlight_level); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 296 | static void intel_panel_init_backlight(struct drm_device *dev) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 297 | { |
| 298 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 299 | |
Indan Zupancic | c8303e7 | 2011-01-12 11:59:19 +0000 | [diff] [blame] | 300 | dev_priv->backlight_level = intel_panel_get_backlight(dev); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 301 | dev_priv->backlight_enabled = dev_priv->backlight_level != 0; |
| 302 | } |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 303 | |
| 304 | enum drm_connector_status |
| 305 | intel_panel_detect(struct drm_device *dev) |
| 306 | { |
Dave Airlie | bcd5023 | 2011-03-14 14:17:55 +1000 | [diff] [blame] | 307 | #if 0 |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 308 | struct drm_i915_private *dev_priv = dev->dev_private; |
Dave Airlie | bcd5023 | 2011-03-14 14:17:55 +1000 | [diff] [blame] | 309 | #endif |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 310 | |
Chris Wilson | fca8740 | 2011-02-17 13:44:48 +0000 | [diff] [blame] | 311 | if (i915_panel_ignore_lid) |
| 312 | return i915_panel_ignore_lid > 0 ? |
| 313 | connector_status_connected : |
| 314 | connector_status_disconnected; |
| 315 | |
Dave Airlie | bcd5023 | 2011-03-14 14:17:55 +1000 | [diff] [blame] | 316 | /* opregion lid state on HP 2540p is wrong at boot up, |
| 317 | * appears to be either the BIOS or Linux ACPI fault */ |
| 318 | #if 0 |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 319 | /* Assume that the BIOS does not lie through the OpRegion... */ |
| 320 | if (dev_priv->opregion.lid_state) |
| 321 | return ioread32(dev_priv->opregion.lid_state) & 0x1 ? |
| 322 | connector_status_connected : |
| 323 | connector_status_disconnected; |
Dave Airlie | bcd5023 | 2011-03-14 14:17:55 +1000 | [diff] [blame] | 324 | #endif |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 325 | |
| 326 | return connector_status_unknown; |
| 327 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 328 | |
| 329 | #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE |
| 330 | static int intel_panel_update_status(struct backlight_device *bd) |
| 331 | { |
| 332 | struct drm_device *dev = bl_get_data(bd); |
| 333 | intel_panel_set_backlight(dev, bd->props.brightness); |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int intel_panel_get_brightness(struct backlight_device *bd) |
| 338 | { |
| 339 | struct drm_device *dev = bl_get_data(bd); |
Takashi Iwai | 04b3867 | 2011-11-16 10:58:03 +0100 | [diff] [blame] | 340 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 341 | return dev_priv->backlight_level; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static const struct backlight_ops intel_panel_bl_ops = { |
| 345 | .update_status = intel_panel_update_status, |
| 346 | .get_brightness = intel_panel_get_brightness, |
| 347 | }; |
| 348 | |
| 349 | int intel_panel_setup_backlight(struct drm_device *dev) |
| 350 | { |
| 351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 352 | struct backlight_properties props; |
| 353 | struct drm_connector *connector; |
| 354 | |
| 355 | intel_panel_init_backlight(dev); |
| 356 | |
| 357 | if (dev_priv->int_lvds_connector) |
| 358 | connector = dev_priv->int_lvds_connector; |
| 359 | else if (dev_priv->int_edp_connector) |
| 360 | connector = dev_priv->int_edp_connector; |
| 361 | else |
| 362 | return -ENODEV; |
| 363 | |
| 364 | props.type = BACKLIGHT_RAW; |
| 365 | props.max_brightness = intel_panel_get_max_backlight(dev); |
| 366 | dev_priv->backlight = |
| 367 | backlight_device_register("intel_backlight", |
| 368 | &connector->kdev, dev, |
| 369 | &intel_panel_bl_ops, &props); |
| 370 | |
| 371 | if (IS_ERR(dev_priv->backlight)) { |
| 372 | DRM_ERROR("Failed to register backlight: %ld\n", |
| 373 | PTR_ERR(dev_priv->backlight)); |
| 374 | dev_priv->backlight = NULL; |
| 375 | return -ENODEV; |
| 376 | } |
| 377 | dev_priv->backlight->props.brightness = intel_panel_get_backlight(dev); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | void intel_panel_destroy_backlight(struct drm_device *dev) |
| 382 | { |
| 383 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 384 | if (dev_priv->backlight) |
| 385 | backlight_device_unregister(dev_priv->backlight); |
| 386 | } |
| 387 | #else |
| 388 | int intel_panel_setup_backlight(struct drm_device *dev) |
| 389 | { |
| 390 | intel_panel_init_backlight(dev); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | void intel_panel_destroy_backlight(struct drm_device *dev) |
| 395 | { |
| 396 | return; |
| 397 | } |
| 398 | #endif |