2 * Copyright © 2006-2010 Intel Corporation
3 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
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:
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
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.
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>
31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/moduleparam.h>
34 #include "intel_drv.h"
37 intel_fixed_panel_mode(const struct drm_display_mode
*fixed_mode
,
38 struct drm_display_mode
*adjusted_mode
)
40 drm_mode_copy(adjusted_mode
, fixed_mode
);
42 drm_mode_set_crtcinfo(adjusted_mode
, 0);
46 * intel_find_panel_downclock - find the reduced downclock for LVDS in EDID
48 * @fixed_mode : panel native mode
49 * @connector: LVDS/eDP connector
51 * Return downclock_avail
52 * Find the reduced downclock for LVDS/eDP in EDID.
54 struct drm_display_mode
*
55 intel_find_panel_downclock(struct drm_device
*dev
,
56 struct drm_display_mode
*fixed_mode
,
57 struct drm_connector
*connector
)
59 struct drm_display_mode
*scan
, *tmp_mode
;
62 temp_downclock
= fixed_mode
->clock
;
65 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
67 * If one mode has the same resolution with the fixed_panel
68 * mode while they have the different refresh rate, it means
69 * that the reduced downclock is found. In such
70 * case we can set the different FPx0/1 to dynamically select
71 * between low and high frequency.
73 if (scan
->hdisplay
== fixed_mode
->hdisplay
&&
74 scan
->hsync_start
== fixed_mode
->hsync_start
&&
75 scan
->hsync_end
== fixed_mode
->hsync_end
&&
76 scan
->htotal
== fixed_mode
->htotal
&&
77 scan
->vdisplay
== fixed_mode
->vdisplay
&&
78 scan
->vsync_start
== fixed_mode
->vsync_start
&&
79 scan
->vsync_end
== fixed_mode
->vsync_end
&&
80 scan
->vtotal
== fixed_mode
->vtotal
) {
81 if (scan
->clock
< temp_downclock
) {
83 * The downclock is already found. But we
84 * expect to find the lower downclock.
86 temp_downclock
= scan
->clock
;
92 if (temp_downclock
< fixed_mode
->clock
)
93 return drm_mode_duplicate(dev
, tmp_mode
);
98 /* adjusted_mode has been preset to be the panel's fixed mode */
100 intel_pch_panel_fitting(struct intel_crtc
*intel_crtc
,
101 struct intel_crtc_config
*pipe_config
,
104 struct drm_display_mode
*adjusted_mode
;
105 int x
, y
, width
, height
;
107 adjusted_mode
= &pipe_config
->adjusted_mode
;
109 x
= y
= width
= height
= 0;
111 /* Native modes don't need fitting */
112 if (adjusted_mode
->hdisplay
== pipe_config
->pipe_src_w
&&
113 adjusted_mode
->vdisplay
== pipe_config
->pipe_src_h
)
116 switch (fitting_mode
) {
117 case DRM_MODE_SCALE_CENTER
:
118 width
= pipe_config
->pipe_src_w
;
119 height
= pipe_config
->pipe_src_h
;
120 x
= (adjusted_mode
->hdisplay
- width
+ 1)/2;
121 y
= (adjusted_mode
->vdisplay
- height
+ 1)/2;
124 case DRM_MODE_SCALE_ASPECT
:
125 /* Scale but preserve the aspect ratio */
127 u32 scaled_width
= adjusted_mode
->hdisplay
128 * pipe_config
->pipe_src_h
;
129 u32 scaled_height
= pipe_config
->pipe_src_w
130 * adjusted_mode
->vdisplay
;
131 if (scaled_width
> scaled_height
) { /* pillar */
132 width
= scaled_height
/ pipe_config
->pipe_src_h
;
135 x
= (adjusted_mode
->hdisplay
- width
+ 1) / 2;
137 height
= adjusted_mode
->vdisplay
;
138 } else if (scaled_width
< scaled_height
) { /* letter */
139 height
= scaled_width
/ pipe_config
->pipe_src_w
;
142 y
= (adjusted_mode
->vdisplay
- height
+ 1) / 2;
144 width
= adjusted_mode
->hdisplay
;
147 width
= adjusted_mode
->hdisplay
;
148 height
= adjusted_mode
->vdisplay
;
153 case DRM_MODE_SCALE_FULLSCREEN
:
155 width
= adjusted_mode
->hdisplay
;
156 height
= adjusted_mode
->vdisplay
;
160 WARN(1, "bad panel fit mode: %d\n", fitting_mode
);
165 pipe_config
->pch_pfit
.pos
= (x
<< 16) | y
;
166 pipe_config
->pch_pfit
.size
= (width
<< 16) | height
;
167 pipe_config
->pch_pfit
.enabled
= pipe_config
->pch_pfit
.size
!= 0;
171 centre_horizontally(struct drm_display_mode
*mode
,
174 u32 border
, sync_pos
, blank_width
, sync_width
;
176 /* keep the hsync and hblank widths constant */
177 sync_width
= mode
->crtc_hsync_end
- mode
->crtc_hsync_start
;
178 blank_width
= mode
->crtc_hblank_end
- mode
->crtc_hblank_start
;
179 sync_pos
= (blank_width
- sync_width
+ 1) / 2;
181 border
= (mode
->hdisplay
- width
+ 1) / 2;
182 border
+= border
& 1; /* make the border even */
184 mode
->crtc_hdisplay
= width
;
185 mode
->crtc_hblank_start
= width
+ border
;
186 mode
->crtc_hblank_end
= mode
->crtc_hblank_start
+ blank_width
;
188 mode
->crtc_hsync_start
= mode
->crtc_hblank_start
+ sync_pos
;
189 mode
->crtc_hsync_end
= mode
->crtc_hsync_start
+ sync_width
;
193 centre_vertically(struct drm_display_mode
*mode
,
196 u32 border
, sync_pos
, blank_width
, sync_width
;
198 /* keep the vsync and vblank widths constant */
199 sync_width
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
200 blank_width
= mode
->crtc_vblank_end
- mode
->crtc_vblank_start
;
201 sync_pos
= (blank_width
- sync_width
+ 1) / 2;
203 border
= (mode
->vdisplay
- height
+ 1) / 2;
205 mode
->crtc_vdisplay
= height
;
206 mode
->crtc_vblank_start
= height
+ border
;
207 mode
->crtc_vblank_end
= mode
->crtc_vblank_start
+ blank_width
;
209 mode
->crtc_vsync_start
= mode
->crtc_vblank_start
+ sync_pos
;
210 mode
->crtc_vsync_end
= mode
->crtc_vsync_start
+ sync_width
;
213 static inline u32
panel_fitter_scaling(u32 source
, u32 target
)
216 * Floating point operation is not supported. So the FACTOR
217 * is defined, which can avoid the floating point computation
218 * when calculating the panel ratio.
221 #define FACTOR (1 << ACCURACY)
222 u32 ratio
= source
* FACTOR
/ target
;
223 return (FACTOR
* ratio
+ FACTOR
/2) / FACTOR
;
226 static void i965_scale_aspect(struct intel_crtc_config
*pipe_config
,
229 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
230 u32 scaled_width
= adjusted_mode
->hdisplay
*
231 pipe_config
->pipe_src_h
;
232 u32 scaled_height
= pipe_config
->pipe_src_w
*
233 adjusted_mode
->vdisplay
;
235 /* 965+ is easy, it does everything in hw */
236 if (scaled_width
> scaled_height
)
237 *pfit_control
|= PFIT_ENABLE
|
239 else if (scaled_width
< scaled_height
)
240 *pfit_control
|= PFIT_ENABLE
|
242 else if (adjusted_mode
->hdisplay
!= pipe_config
->pipe_src_w
)
243 *pfit_control
|= PFIT_ENABLE
| PFIT_SCALING_AUTO
;
246 static void i9xx_scale_aspect(struct intel_crtc_config
*pipe_config
,
247 u32
*pfit_control
, u32
*pfit_pgm_ratios
,
250 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
251 u32 scaled_width
= adjusted_mode
->hdisplay
*
252 pipe_config
->pipe_src_h
;
253 u32 scaled_height
= pipe_config
->pipe_src_w
*
254 adjusted_mode
->vdisplay
;
258 * For earlier chips we have to calculate the scaling
259 * ratio by hand and program it into the
260 * PFIT_PGM_RATIO register
262 if (scaled_width
> scaled_height
) { /* pillar */
263 centre_horizontally(adjusted_mode
,
265 pipe_config
->pipe_src_h
);
267 *border
= LVDS_BORDER_ENABLE
;
268 if (pipe_config
->pipe_src_h
!= adjusted_mode
->vdisplay
) {
269 bits
= panel_fitter_scaling(pipe_config
->pipe_src_h
,
270 adjusted_mode
->vdisplay
);
272 *pfit_pgm_ratios
|= (bits
<< PFIT_HORIZ_SCALE_SHIFT
|
273 bits
<< PFIT_VERT_SCALE_SHIFT
);
274 *pfit_control
|= (PFIT_ENABLE
|
275 VERT_INTERP_BILINEAR
|
276 HORIZ_INTERP_BILINEAR
);
278 } else if (scaled_width
< scaled_height
) { /* letter */
279 centre_vertically(adjusted_mode
,
281 pipe_config
->pipe_src_w
);
283 *border
= LVDS_BORDER_ENABLE
;
284 if (pipe_config
->pipe_src_w
!= adjusted_mode
->hdisplay
) {
285 bits
= panel_fitter_scaling(pipe_config
->pipe_src_w
,
286 adjusted_mode
->hdisplay
);
288 *pfit_pgm_ratios
|= (bits
<< PFIT_HORIZ_SCALE_SHIFT
|
289 bits
<< PFIT_VERT_SCALE_SHIFT
);
290 *pfit_control
|= (PFIT_ENABLE
|
291 VERT_INTERP_BILINEAR
|
292 HORIZ_INTERP_BILINEAR
);
295 /* Aspects match, Let hw scale both directions */
296 *pfit_control
|= (PFIT_ENABLE
|
297 VERT_AUTO_SCALE
| HORIZ_AUTO_SCALE
|
298 VERT_INTERP_BILINEAR
|
299 HORIZ_INTERP_BILINEAR
);
303 void intel_gmch_panel_fitting(struct intel_crtc
*intel_crtc
,
304 struct intel_crtc_config
*pipe_config
,
307 struct drm_device
*dev
= intel_crtc
->base
.dev
;
308 u32 pfit_control
= 0, pfit_pgm_ratios
= 0, border
= 0;
309 struct drm_display_mode
*adjusted_mode
;
311 adjusted_mode
= &pipe_config
->adjusted_mode
;
313 /* Native modes don't need fitting */
314 if (adjusted_mode
->hdisplay
== pipe_config
->pipe_src_w
&&
315 adjusted_mode
->vdisplay
== pipe_config
->pipe_src_h
)
318 switch (fitting_mode
) {
319 case DRM_MODE_SCALE_CENTER
:
321 * For centered modes, we have to calculate border widths &
322 * heights and modify the values programmed into the CRTC.
324 centre_horizontally(adjusted_mode
, pipe_config
->pipe_src_w
);
325 centre_vertically(adjusted_mode
, pipe_config
->pipe_src_h
);
326 border
= LVDS_BORDER_ENABLE
;
328 case DRM_MODE_SCALE_ASPECT
:
329 /* Scale but preserve the aspect ratio */
330 if (INTEL_INFO(dev
)->gen
>= 4)
331 i965_scale_aspect(pipe_config
, &pfit_control
);
333 i9xx_scale_aspect(pipe_config
, &pfit_control
,
334 &pfit_pgm_ratios
, &border
);
336 case DRM_MODE_SCALE_FULLSCREEN
:
338 * Full scaling, even if it changes the aspect ratio.
339 * Fortunately this is all done for us in hw.
341 if (pipe_config
->pipe_src_h
!= adjusted_mode
->vdisplay
||
342 pipe_config
->pipe_src_w
!= adjusted_mode
->hdisplay
) {
343 pfit_control
|= PFIT_ENABLE
;
344 if (INTEL_INFO(dev
)->gen
>= 4)
345 pfit_control
|= PFIT_SCALING_AUTO
;
347 pfit_control
|= (VERT_AUTO_SCALE
|
348 VERT_INTERP_BILINEAR
|
350 HORIZ_INTERP_BILINEAR
);
354 WARN(1, "bad panel fit mode: %d\n", fitting_mode
);
358 /* 965+ wants fuzzy fitting */
359 /* FIXME: handle multiple panels by failing gracefully */
360 if (INTEL_INFO(dev
)->gen
>= 4)
361 pfit_control
|= ((intel_crtc
->pipe
<< PFIT_PIPE_SHIFT
) |
365 if ((pfit_control
& PFIT_ENABLE
) == 0) {
370 /* Make sure pre-965 set dither correctly for 18bpp panels. */
371 if (INTEL_INFO(dev
)->gen
< 4 && pipe_config
->pipe_bpp
== 18)
372 pfit_control
|= PANEL_8TO6_DITHER_ENABLE
;
374 pipe_config
->gmch_pfit
.control
= pfit_control
;
375 pipe_config
->gmch_pfit
.pgm_ratios
= pfit_pgm_ratios
;
376 pipe_config
->gmch_pfit
.lvds_border_bits
= border
;
379 enum drm_connector_status
380 intel_panel_detect(struct drm_device
*dev
)
382 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
384 /* Assume that the BIOS does not lie through the OpRegion... */
385 if (!i915
.panel_ignore_lid
&& dev_priv
->opregion
.lid_state
) {
386 return ioread32(dev_priv
->opregion
.lid_state
) & 0x1 ?
387 connector_status_connected
:
388 connector_status_disconnected
;
391 switch (i915
.panel_ignore_lid
) {
393 return connector_status_connected
;
395 return connector_status_disconnected
;
397 return connector_status_unknown
;
402 * scale - scale values from one range to another
404 * @source_val: value in range [@source_min..@source_max]
406 * Return @source_val in range [@source_min..@source_max] scaled to range
407 * [@target_min..@target_max].
409 static uint32_t scale(uint32_t source_val
,
410 uint32_t source_min
, uint32_t source_max
,
411 uint32_t target_min
, uint32_t target_max
)
415 WARN_ON(source_min
> source_max
);
416 WARN_ON(target_min
> target_max
);
419 source_val
= clamp(source_val
, source_min
, source_max
);
421 /* avoid overflows */
422 target_val
= (uint64_t)(source_val
- source_min
) *
423 (target_max
- target_min
);
424 do_div(target_val
, source_max
- source_min
);
425 target_val
+= target_min
;
430 /* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */
431 static inline u32
scale_user_to_hw(struct intel_connector
*connector
,
432 u32 user_level
, u32 user_max
)
434 struct intel_panel
*panel
= &connector
->panel
;
436 return scale(user_level
, 0, user_max
,
437 panel
->backlight
.min
, panel
->backlight
.max
);
440 /* Scale user_level in range [0..user_max] to [0..hw_max], clamping the result
441 * to [hw_min..hw_max]. */
442 static inline u32
clamp_user_to_hw(struct intel_connector
*connector
,
443 u32 user_level
, u32 user_max
)
445 struct intel_panel
*panel
= &connector
->panel
;
448 hw_level
= scale(user_level
, 0, user_max
, 0, panel
->backlight
.max
);
449 hw_level
= clamp(hw_level
, panel
->backlight
.min
, panel
->backlight
.max
);
454 /* Scale hw_level in range [hw_min..hw_max] to [0..user_max]. */
455 static inline u32
scale_hw_to_user(struct intel_connector
*connector
,
456 u32 hw_level
, u32 user_max
)
458 struct intel_panel
*panel
= &connector
->panel
;
460 return scale(hw_level
, panel
->backlight
.min
, panel
->backlight
.max
,
464 static u32
intel_panel_compute_brightness(struct intel_connector
*connector
,
467 struct drm_device
*dev
= connector
->base
.dev
;
468 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
469 struct intel_panel
*panel
= &connector
->panel
;
471 WARN_ON(panel
->backlight
.max
== 0);
473 if (i915
.invert_brightness
< 0)
476 if (i915
.invert_brightness
> 0 ||
477 dev_priv
->quirks
& QUIRK_INVERT_BRIGHTNESS
) {
478 return panel
->backlight
.max
- val
;
484 static u32
bdw_get_backlight(struct intel_connector
*connector
)
486 struct drm_device
*dev
= connector
->base
.dev
;
487 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
489 return I915_READ(BLC_PWM_PCH_CTL2
) & BACKLIGHT_DUTY_CYCLE_MASK
;
492 static u32
pch_get_backlight(struct intel_connector
*connector
)
494 struct drm_device
*dev
= connector
->base
.dev
;
495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
497 return I915_READ(BLC_PWM_CPU_CTL
) & BACKLIGHT_DUTY_CYCLE_MASK
;
500 static u32
i9xx_get_backlight(struct intel_connector
*connector
)
502 struct drm_device
*dev
= connector
->base
.dev
;
503 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
504 struct intel_panel
*panel
= &connector
->panel
;
507 val
= I915_READ(BLC_PWM_CTL
) & BACKLIGHT_DUTY_CYCLE_MASK
;
508 if (INTEL_INFO(dev
)->gen
< 4)
511 if (panel
->backlight
.combination_mode
) {
514 pci_read_config_byte(dev
->pdev
, PCI_LBPC
, &lbpc
);
521 static u32
_vlv_get_backlight(struct drm_device
*dev
, enum pipe pipe
)
523 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
525 return I915_READ(VLV_BLC_PWM_CTL(pipe
)) & BACKLIGHT_DUTY_CYCLE_MASK
;
528 static u32
vlv_get_backlight(struct intel_connector
*connector
)
530 struct drm_device
*dev
= connector
->base
.dev
;
531 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
533 return _vlv_get_backlight(dev
, pipe
);
536 static u32
intel_panel_get_backlight(struct intel_connector
*connector
)
538 struct drm_device
*dev
= connector
->base
.dev
;
539 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
543 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
545 val
= dev_priv
->display
.get_backlight(connector
);
546 val
= intel_panel_compute_brightness(connector
, val
);
548 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
550 DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val
);
554 static void bdw_set_backlight(struct intel_connector
*connector
, u32 level
)
556 struct drm_device
*dev
= connector
->base
.dev
;
557 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
558 u32 val
= I915_READ(BLC_PWM_PCH_CTL2
) & ~BACKLIGHT_DUTY_CYCLE_MASK
;
559 I915_WRITE(BLC_PWM_PCH_CTL2
, val
| level
);
562 static void pch_set_backlight(struct intel_connector
*connector
, u32 level
)
564 struct drm_device
*dev
= connector
->base
.dev
;
565 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
568 tmp
= I915_READ(BLC_PWM_CPU_CTL
) & ~BACKLIGHT_DUTY_CYCLE_MASK
;
569 I915_WRITE(BLC_PWM_CPU_CTL
, tmp
| level
);
572 static void i9xx_set_backlight(struct intel_connector
*connector
, u32 level
)
574 struct drm_device
*dev
= connector
->base
.dev
;
575 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
576 struct intel_panel
*panel
= &connector
->panel
;
579 WARN_ON(panel
->backlight
.max
== 0);
581 if (panel
->backlight
.combination_mode
) {
584 lbpc
= level
* 0xfe / panel
->backlight
.max
+ 1;
586 pci_write_config_byte(dev
->pdev
, PCI_LBPC
, lbpc
);
590 mask
= BACKLIGHT_DUTY_CYCLE_MASK
;
593 mask
= BACKLIGHT_DUTY_CYCLE_MASK_PNV
;
596 tmp
= I915_READ(BLC_PWM_CTL
) & ~mask
;
597 I915_WRITE(BLC_PWM_CTL
, tmp
| level
);
600 static void vlv_set_backlight(struct intel_connector
*connector
, u32 level
)
602 struct drm_device
*dev
= connector
->base
.dev
;
603 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
604 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
607 tmp
= I915_READ(VLV_BLC_PWM_CTL(pipe
)) & ~BACKLIGHT_DUTY_CYCLE_MASK
;
608 I915_WRITE(VLV_BLC_PWM_CTL(pipe
), tmp
| level
);
612 intel_panel_actually_set_backlight(struct intel_connector
*connector
, u32 level
)
614 struct drm_device
*dev
= connector
->base
.dev
;
615 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
617 DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level
);
619 level
= intel_panel_compute_brightness(connector
, level
);
620 dev_priv
->display
.set_backlight(connector
, level
);
623 /* set backlight brightness to level in range [0..max], scaling wrt hw min */
624 static void intel_panel_set_backlight(struct intel_connector
*connector
,
625 u32 user_level
, u32 user_max
)
627 struct drm_device
*dev
= connector
->base
.dev
;
628 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
629 struct intel_panel
*panel
= &connector
->panel
;
630 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
634 if (!panel
->backlight
.present
|| pipe
== INVALID_PIPE
)
637 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
639 WARN_ON(panel
->backlight
.max
== 0);
641 hw_level
= scale_user_to_hw(connector
, user_level
, user_max
);
642 panel
->backlight
.level
= hw_level
;
644 if (panel
->backlight
.enabled
)
645 intel_panel_actually_set_backlight(connector
, hw_level
);
647 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
650 /* set backlight brightness to level in range [0..max], assuming hw min is
653 void intel_panel_set_backlight_acpi(struct intel_connector
*connector
,
654 u32 user_level
, u32 user_max
)
656 struct drm_device
*dev
= connector
->base
.dev
;
657 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
658 struct intel_panel
*panel
= &connector
->panel
;
659 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
663 if (!panel
->backlight
.present
|| pipe
== INVALID_PIPE
)
666 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
668 WARN_ON(panel
->backlight
.max
== 0);
670 hw_level
= clamp_user_to_hw(connector
, user_level
, user_max
);
671 panel
->backlight
.level
= hw_level
;
673 if (panel
->backlight
.device
)
674 panel
->backlight
.device
->props
.brightness
=
675 scale_hw_to_user(connector
,
676 panel
->backlight
.level
,
677 panel
->backlight
.device
->props
.max_brightness
);
679 if (panel
->backlight
.enabled
)
680 intel_panel_actually_set_backlight(connector
, hw_level
);
682 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
685 static void pch_disable_backlight(struct intel_connector
*connector
)
687 struct drm_device
*dev
= connector
->base
.dev
;
688 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
691 intel_panel_actually_set_backlight(connector
, 0);
693 tmp
= I915_READ(BLC_PWM_CPU_CTL2
);
694 I915_WRITE(BLC_PWM_CPU_CTL2
, tmp
& ~BLM_PWM_ENABLE
);
696 tmp
= I915_READ(BLC_PWM_PCH_CTL1
);
697 I915_WRITE(BLC_PWM_PCH_CTL1
, tmp
& ~BLM_PCH_PWM_ENABLE
);
700 static void i9xx_disable_backlight(struct intel_connector
*connector
)
702 intel_panel_actually_set_backlight(connector
, 0);
705 static void i965_disable_backlight(struct intel_connector
*connector
)
707 struct drm_device
*dev
= connector
->base
.dev
;
708 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
711 intel_panel_actually_set_backlight(connector
, 0);
713 tmp
= I915_READ(BLC_PWM_CTL2
);
714 I915_WRITE(BLC_PWM_CTL2
, tmp
& ~BLM_PWM_ENABLE
);
717 static void vlv_disable_backlight(struct intel_connector
*connector
)
719 struct drm_device
*dev
= connector
->base
.dev
;
720 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
721 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
724 intel_panel_actually_set_backlight(connector
, 0);
726 tmp
= I915_READ(VLV_BLC_PWM_CTL2(pipe
));
727 I915_WRITE(VLV_BLC_PWM_CTL2(pipe
), tmp
& ~BLM_PWM_ENABLE
);
730 void intel_panel_disable_backlight(struct intel_connector
*connector
)
732 struct drm_device
*dev
= connector
->base
.dev
;
733 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
734 struct intel_panel
*panel
= &connector
->panel
;
735 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
738 if (!panel
->backlight
.present
|| pipe
== INVALID_PIPE
)
742 * Do not disable backlight on the vgaswitcheroo path. When switching
743 * away from i915, the other client may depend on i915 to handle the
744 * backlight. This will leave the backlight on unnecessarily when
745 * another client is not activated.
747 if (dev
->switch_power_state
== DRM_SWITCH_POWER_CHANGING
) {
748 DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
752 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
754 if (panel
->backlight
.device
)
755 panel
->backlight
.device
->props
.power
= FB_BLANK_POWERDOWN
;
756 panel
->backlight
.enabled
= false;
757 dev_priv
->display
.disable_backlight(connector
);
759 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
762 static void bdw_enable_backlight(struct intel_connector
*connector
)
764 struct drm_device
*dev
= connector
->base
.dev
;
765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
766 struct intel_panel
*panel
= &connector
->panel
;
767 u32 pch_ctl1
, pch_ctl2
;
769 pch_ctl1
= I915_READ(BLC_PWM_PCH_CTL1
);
770 if (pch_ctl1
& BLM_PCH_PWM_ENABLE
) {
771 DRM_DEBUG_KMS("pch backlight already enabled\n");
772 pch_ctl1
&= ~BLM_PCH_PWM_ENABLE
;
773 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
);
776 pch_ctl2
= panel
->backlight
.max
<< 16;
777 I915_WRITE(BLC_PWM_PCH_CTL2
, pch_ctl2
);
780 if (panel
->backlight
.active_low_pwm
)
781 pch_ctl1
|= BLM_PCH_POLARITY
;
783 /* BDW always uses the pch pwm controls. */
784 pch_ctl1
|= BLM_PCH_OVERRIDE_ENABLE
;
786 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
);
787 POSTING_READ(BLC_PWM_PCH_CTL1
);
788 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
| BLM_PCH_PWM_ENABLE
);
790 /* This won't stick until the above enable. */
791 intel_panel_actually_set_backlight(connector
, panel
->backlight
.level
);
794 static void pch_enable_backlight(struct intel_connector
*connector
)
796 struct drm_device
*dev
= connector
->base
.dev
;
797 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
798 struct intel_panel
*panel
= &connector
->panel
;
799 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
800 enum transcoder cpu_transcoder
=
801 intel_pipe_to_cpu_transcoder(dev_priv
, pipe
);
802 u32 cpu_ctl2
, pch_ctl1
, pch_ctl2
;
804 cpu_ctl2
= I915_READ(BLC_PWM_CPU_CTL2
);
805 if (cpu_ctl2
& BLM_PWM_ENABLE
) {
806 DRM_DEBUG_KMS("cpu backlight already enabled\n");
807 cpu_ctl2
&= ~BLM_PWM_ENABLE
;
808 I915_WRITE(BLC_PWM_CPU_CTL2
, cpu_ctl2
);
811 pch_ctl1
= I915_READ(BLC_PWM_PCH_CTL1
);
812 if (pch_ctl1
& BLM_PCH_PWM_ENABLE
) {
813 DRM_DEBUG_KMS("pch backlight already enabled\n");
814 pch_ctl1
&= ~BLM_PCH_PWM_ENABLE
;
815 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
);
818 if (cpu_transcoder
== TRANSCODER_EDP
)
819 cpu_ctl2
= BLM_TRANSCODER_EDP
;
821 cpu_ctl2
= BLM_PIPE(cpu_transcoder
);
822 I915_WRITE(BLC_PWM_CPU_CTL2
, cpu_ctl2
);
823 POSTING_READ(BLC_PWM_CPU_CTL2
);
824 I915_WRITE(BLC_PWM_CPU_CTL2
, cpu_ctl2
| BLM_PWM_ENABLE
);
826 /* This won't stick until the above enable. */
827 intel_panel_actually_set_backlight(connector
, panel
->backlight
.level
);
829 pch_ctl2
= panel
->backlight
.max
<< 16;
830 I915_WRITE(BLC_PWM_PCH_CTL2
, pch_ctl2
);
833 if (panel
->backlight
.active_low_pwm
)
834 pch_ctl1
|= BLM_PCH_POLARITY
;
836 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
);
837 POSTING_READ(BLC_PWM_PCH_CTL1
);
838 I915_WRITE(BLC_PWM_PCH_CTL1
, pch_ctl1
| BLM_PCH_PWM_ENABLE
);
841 static void i9xx_enable_backlight(struct intel_connector
*connector
)
843 struct drm_device
*dev
= connector
->base
.dev
;
844 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
845 struct intel_panel
*panel
= &connector
->panel
;
848 ctl
= I915_READ(BLC_PWM_CTL
);
849 if (ctl
& BACKLIGHT_DUTY_CYCLE_MASK_PNV
) {
850 DRM_DEBUG_KMS("backlight already enabled\n");
851 I915_WRITE(BLC_PWM_CTL
, 0);
854 freq
= panel
->backlight
.max
;
855 if (panel
->backlight
.combination_mode
)
859 if (panel
->backlight
.combination_mode
)
860 ctl
|= BLM_LEGACY_MODE
;
861 if (IS_PINEVIEW(dev
) && panel
->backlight
.active_low_pwm
)
862 ctl
|= BLM_POLARITY_PNV
;
864 I915_WRITE(BLC_PWM_CTL
, ctl
);
865 POSTING_READ(BLC_PWM_CTL
);
867 /* XXX: combine this into above write? */
868 intel_panel_actually_set_backlight(connector
, panel
->backlight
.level
);
871 static void i965_enable_backlight(struct intel_connector
*connector
)
873 struct drm_device
*dev
= connector
->base
.dev
;
874 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
875 struct intel_panel
*panel
= &connector
->panel
;
876 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
879 ctl2
= I915_READ(BLC_PWM_CTL2
);
880 if (ctl2
& BLM_PWM_ENABLE
) {
881 DRM_DEBUG_KMS("backlight already enabled\n");
882 ctl2
&= ~BLM_PWM_ENABLE
;
883 I915_WRITE(BLC_PWM_CTL2
, ctl2
);
886 freq
= panel
->backlight
.max
;
887 if (panel
->backlight
.combination_mode
)
891 I915_WRITE(BLC_PWM_CTL
, ctl
);
893 ctl2
= BLM_PIPE(pipe
);
894 if (panel
->backlight
.combination_mode
)
895 ctl2
|= BLM_COMBINATION_MODE
;
896 if (panel
->backlight
.active_low_pwm
)
897 ctl2
|= BLM_POLARITY_I965
;
898 I915_WRITE(BLC_PWM_CTL2
, ctl2
);
899 POSTING_READ(BLC_PWM_CTL2
);
900 I915_WRITE(BLC_PWM_CTL2
, ctl2
| BLM_PWM_ENABLE
);
902 intel_panel_actually_set_backlight(connector
, panel
->backlight
.level
);
905 static void vlv_enable_backlight(struct intel_connector
*connector
)
907 struct drm_device
*dev
= connector
->base
.dev
;
908 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
909 struct intel_panel
*panel
= &connector
->panel
;
910 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
913 ctl2
= I915_READ(VLV_BLC_PWM_CTL2(pipe
));
914 if (ctl2
& BLM_PWM_ENABLE
) {
915 DRM_DEBUG_KMS("backlight already enabled\n");
916 ctl2
&= ~BLM_PWM_ENABLE
;
917 I915_WRITE(VLV_BLC_PWM_CTL2(pipe
), ctl2
);
920 ctl
= panel
->backlight
.max
<< 16;
921 I915_WRITE(VLV_BLC_PWM_CTL(pipe
), ctl
);
923 /* XXX: combine this into above write? */
924 intel_panel_actually_set_backlight(connector
, panel
->backlight
.level
);
927 if (panel
->backlight
.active_low_pwm
)
928 ctl2
|= BLM_POLARITY_I965
;
929 I915_WRITE(VLV_BLC_PWM_CTL2(pipe
), ctl2
);
930 POSTING_READ(VLV_BLC_PWM_CTL2(pipe
));
931 I915_WRITE(VLV_BLC_PWM_CTL2(pipe
), ctl2
| BLM_PWM_ENABLE
);
934 void intel_panel_enable_backlight(struct intel_connector
*connector
)
936 struct drm_device
*dev
= connector
->base
.dev
;
937 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
938 struct intel_panel
*panel
= &connector
->panel
;
939 enum pipe pipe
= intel_get_pipe_from_connector(connector
);
942 if (!panel
->backlight
.present
|| pipe
== INVALID_PIPE
)
945 DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe
));
947 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
949 WARN_ON(panel
->backlight
.max
== 0);
951 if (panel
->backlight
.level
== 0) {
952 panel
->backlight
.level
= panel
->backlight
.max
;
953 if (panel
->backlight
.device
)
954 panel
->backlight
.device
->props
.brightness
=
955 scale_hw_to_user(connector
,
956 panel
->backlight
.level
,
957 panel
->backlight
.device
->props
.max_brightness
);
960 dev_priv
->display
.enable_backlight(connector
);
961 panel
->backlight
.enabled
= true;
962 if (panel
->backlight
.device
)
963 panel
->backlight
.device
->props
.power
= FB_BLANK_UNBLANK
;
965 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
968 #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
969 static int intel_backlight_device_update_status(struct backlight_device
*bd
)
971 struct intel_connector
*connector
= bl_get_data(bd
);
972 struct intel_panel
*panel
= &connector
->panel
;
973 struct drm_device
*dev
= connector
->base
.dev
;
975 drm_modeset_lock(&dev
->mode_config
.connection_mutex
, NULL
);
976 DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n",
977 bd
->props
.brightness
, bd
->props
.max_brightness
);
978 intel_panel_set_backlight(connector
, bd
->props
.brightness
,
979 bd
->props
.max_brightness
);
982 * Allow flipping bl_power as a sub-state of enabled. Sadly the
983 * backlight class device does not make it easy to to differentiate
984 * between callbacks for brightness and bl_power, so our backlight_power
985 * callback needs to take this into account.
987 if (panel
->backlight
.enabled
) {
988 if (panel
->backlight_power
) {
989 bool enable
= bd
->props
.power
== FB_BLANK_UNBLANK
&&
990 bd
->props
.brightness
!= 0;
991 panel
->backlight_power(connector
, enable
);
994 bd
->props
.power
= FB_BLANK_POWERDOWN
;
997 drm_modeset_unlock(&dev
->mode_config
.connection_mutex
);
1001 static int intel_backlight_device_get_brightness(struct backlight_device
*bd
)
1003 struct intel_connector
*connector
= bl_get_data(bd
);
1004 struct drm_device
*dev
= connector
->base
.dev
;
1005 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1009 intel_runtime_pm_get(dev_priv
);
1010 drm_modeset_lock(&dev
->mode_config
.connection_mutex
, NULL
);
1012 hw_level
= intel_panel_get_backlight(connector
);
1013 ret
= scale_hw_to_user(connector
, hw_level
, bd
->props
.max_brightness
);
1015 drm_modeset_unlock(&dev
->mode_config
.connection_mutex
);
1016 intel_runtime_pm_put(dev_priv
);
1021 static const struct backlight_ops intel_backlight_device_ops
= {
1022 .update_status
= intel_backlight_device_update_status
,
1023 .get_brightness
= intel_backlight_device_get_brightness
,
1026 static int intel_backlight_device_register(struct intel_connector
*connector
)
1028 struct intel_panel
*panel
= &connector
->panel
;
1029 struct backlight_properties props
;
1031 if (WARN_ON(panel
->backlight
.device
))
1034 WARN_ON(panel
->backlight
.max
== 0);
1036 memset(&props
, 0, sizeof(props
));
1037 props
.type
= BACKLIGHT_RAW
;
1040 * Note: Everything should work even if the backlight device max
1041 * presented to the userspace is arbitrarily chosen.
1043 props
.max_brightness
= panel
->backlight
.max
;
1044 props
.brightness
= scale_hw_to_user(connector
,
1045 panel
->backlight
.level
,
1046 props
.max_brightness
);
1048 if (panel
->backlight
.enabled
)
1049 props
.power
= FB_BLANK_UNBLANK
;
1051 props
.power
= FB_BLANK_POWERDOWN
;
1054 * Note: using the same name independent of the connector prevents
1055 * registration of multiple backlight devices in the driver.
1057 panel
->backlight
.device
=
1058 backlight_device_register("intel_backlight",
1059 connector
->base
.kdev
,
1061 &intel_backlight_device_ops
, &props
);
1063 if (IS_ERR(panel
->backlight
.device
)) {
1064 DRM_ERROR("Failed to register backlight: %ld\n",
1065 PTR_ERR(panel
->backlight
.device
));
1066 panel
->backlight
.device
= NULL
;
1072 static void intel_backlight_device_unregister(struct intel_connector
*connector
)
1074 struct intel_panel
*panel
= &connector
->panel
;
1076 if (panel
->backlight
.device
) {
1077 backlight_device_unregister(panel
->backlight
.device
);
1078 panel
->backlight
.device
= NULL
;
1081 #else /* CONFIG_BACKLIGHT_CLASS_DEVICE */
1082 static int intel_backlight_device_register(struct intel_connector
*connector
)
1086 static void intel_backlight_device_unregister(struct intel_connector
*connector
)
1089 #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
1092 * Note: The setup hooks can't assume pipe is set!
1094 * XXX: Query mode clock or hardware clock and program PWM modulation frequency
1095 * appropriately when it's 0. Use VBT and/or sane defaults.
1097 static u32
get_backlight_min_vbt(struct intel_connector
*connector
)
1099 struct drm_device
*dev
= connector
->base
.dev
;
1100 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1101 struct intel_panel
*panel
= &connector
->panel
;
1103 WARN_ON(panel
->backlight
.max
== 0);
1105 /* vbt value is a coefficient in range [0..255] */
1106 return scale(dev_priv
->vbt
.backlight
.min_brightness
, 0, 255,
1107 0, panel
->backlight
.max
);
1110 static int bdw_setup_backlight(struct intel_connector
*connector
)
1112 struct drm_device
*dev
= connector
->base
.dev
;
1113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1114 struct intel_panel
*panel
= &connector
->panel
;
1115 u32 pch_ctl1
, pch_ctl2
, val
;
1117 pch_ctl1
= I915_READ(BLC_PWM_PCH_CTL1
);
1118 panel
->backlight
.active_low_pwm
= pch_ctl1
& BLM_PCH_POLARITY
;
1120 pch_ctl2
= I915_READ(BLC_PWM_PCH_CTL2
);
1121 panel
->backlight
.max
= pch_ctl2
>> 16;
1122 if (!panel
->backlight
.max
)
1125 panel
->backlight
.min
= get_backlight_min_vbt(connector
);
1127 val
= bdw_get_backlight(connector
);
1128 panel
->backlight
.level
= intel_panel_compute_brightness(connector
, val
);
1130 panel
->backlight
.enabled
= (pch_ctl1
& BLM_PCH_PWM_ENABLE
) &&
1131 panel
->backlight
.level
!= 0;
1136 static int pch_setup_backlight(struct intel_connector
*connector
)
1138 struct drm_device
*dev
= connector
->base
.dev
;
1139 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1140 struct intel_panel
*panel
= &connector
->panel
;
1141 u32 cpu_ctl2
, pch_ctl1
, pch_ctl2
, val
;
1143 pch_ctl1
= I915_READ(BLC_PWM_PCH_CTL1
);
1144 panel
->backlight
.active_low_pwm
= pch_ctl1
& BLM_PCH_POLARITY
;
1146 pch_ctl2
= I915_READ(BLC_PWM_PCH_CTL2
);
1147 panel
->backlight
.max
= pch_ctl2
>> 16;
1148 if (!panel
->backlight
.max
)
1151 panel
->backlight
.min
= get_backlight_min_vbt(connector
);
1153 val
= pch_get_backlight(connector
);
1154 panel
->backlight
.level
= intel_panel_compute_brightness(connector
, val
);
1156 cpu_ctl2
= I915_READ(BLC_PWM_CPU_CTL2
);
1157 panel
->backlight
.enabled
= (cpu_ctl2
& BLM_PWM_ENABLE
) &&
1158 (pch_ctl1
& BLM_PCH_PWM_ENABLE
) && panel
->backlight
.level
!= 0;
1163 static int i9xx_setup_backlight(struct intel_connector
*connector
)
1165 struct drm_device
*dev
= connector
->base
.dev
;
1166 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1167 struct intel_panel
*panel
= &connector
->panel
;
1170 ctl
= I915_READ(BLC_PWM_CTL
);
1172 if (IS_GEN2(dev
) || IS_I915GM(dev
) || IS_I945GM(dev
))
1173 panel
->backlight
.combination_mode
= ctl
& BLM_LEGACY_MODE
;
1175 if (IS_PINEVIEW(dev
))
1176 panel
->backlight
.active_low_pwm
= ctl
& BLM_POLARITY_PNV
;
1178 panel
->backlight
.max
= ctl
>> 17;
1179 if (panel
->backlight
.combination_mode
)
1180 panel
->backlight
.max
*= 0xff;
1182 if (!panel
->backlight
.max
)
1185 panel
->backlight
.min
= get_backlight_min_vbt(connector
);
1187 val
= i9xx_get_backlight(connector
);
1188 panel
->backlight
.level
= intel_panel_compute_brightness(connector
, val
);
1190 panel
->backlight
.enabled
= panel
->backlight
.level
!= 0;
1195 static int i965_setup_backlight(struct intel_connector
*connector
)
1197 struct drm_device
*dev
= connector
->base
.dev
;
1198 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1199 struct intel_panel
*panel
= &connector
->panel
;
1202 ctl2
= I915_READ(BLC_PWM_CTL2
);
1203 panel
->backlight
.combination_mode
= ctl2
& BLM_COMBINATION_MODE
;
1204 panel
->backlight
.active_low_pwm
= ctl2
& BLM_POLARITY_I965
;
1206 ctl
= I915_READ(BLC_PWM_CTL
);
1207 panel
->backlight
.max
= ctl
>> 16;
1208 if (panel
->backlight
.combination_mode
)
1209 panel
->backlight
.max
*= 0xff;
1211 if (!panel
->backlight
.max
)
1214 panel
->backlight
.min
= get_backlight_min_vbt(connector
);
1216 val
= i9xx_get_backlight(connector
);
1217 panel
->backlight
.level
= intel_panel_compute_brightness(connector
, val
);
1219 panel
->backlight
.enabled
= (ctl2
& BLM_PWM_ENABLE
) &&
1220 panel
->backlight
.level
!= 0;
1225 static int vlv_setup_backlight(struct intel_connector
*connector
)
1227 struct drm_device
*dev
= connector
->base
.dev
;
1228 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1229 struct intel_panel
*panel
= &connector
->panel
;
1233 for_each_pipe(dev_priv
, pipe
) {
1234 u32 cur_val
= I915_READ(VLV_BLC_PWM_CTL(pipe
));
1236 /* Skip if the modulation freq is already set */
1237 if (cur_val
& ~BACKLIGHT_DUTY_CYCLE_MASK
)
1240 cur_val
&= BACKLIGHT_DUTY_CYCLE_MASK
;
1241 I915_WRITE(VLV_BLC_PWM_CTL(pipe
), (0xf42 << 16) |
1245 ctl2
= I915_READ(VLV_BLC_PWM_CTL2(PIPE_A
));
1246 panel
->backlight
.active_low_pwm
= ctl2
& BLM_POLARITY_I965
;
1248 ctl
= I915_READ(VLV_BLC_PWM_CTL(PIPE_A
));
1249 panel
->backlight
.max
= ctl
>> 16;
1250 if (!panel
->backlight
.max
)
1253 panel
->backlight
.min
= get_backlight_min_vbt(connector
);
1255 val
= _vlv_get_backlight(dev
, PIPE_A
);
1256 panel
->backlight
.level
= intel_panel_compute_brightness(connector
, val
);
1258 panel
->backlight
.enabled
= (ctl2
& BLM_PWM_ENABLE
) &&
1259 panel
->backlight
.level
!= 0;
1264 int intel_panel_setup_backlight(struct drm_connector
*connector
)
1266 struct drm_device
*dev
= connector
->dev
;
1267 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1268 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
1269 struct intel_panel
*panel
= &intel_connector
->panel
;
1270 unsigned long flags
;
1273 if (!dev_priv
->vbt
.backlight
.present
) {
1274 if (dev_priv
->quirks
& QUIRK_BACKLIGHT_PRESENT
) {
1275 DRM_DEBUG_KMS("no backlight present per VBT, but present per quirk\n");
1277 DRM_DEBUG_KMS("no backlight present per VBT\n");
1282 /* set level and max in panel struct */
1283 spin_lock_irqsave(&dev_priv
->backlight_lock
, flags
);
1284 ret
= dev_priv
->display
.setup_backlight(intel_connector
);
1285 spin_unlock_irqrestore(&dev_priv
->backlight_lock
, flags
);
1288 DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
1293 intel_backlight_device_register(intel_connector
);
1295 panel
->backlight
.present
= true;
1297 DRM_DEBUG_KMS("backlight initialized, %s, brightness %u/%u, "
1298 "sysfs interface %sregistered\n",
1299 panel
->backlight
.enabled
? "enabled" : "disabled",
1300 panel
->backlight
.level
, panel
->backlight
.max
,
1301 panel
->backlight
.device
? "" : "not ");
1306 void intel_panel_destroy_backlight(struct drm_connector
*connector
)
1308 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
1309 struct intel_panel
*panel
= &intel_connector
->panel
;
1311 panel
->backlight
.present
= false;
1312 intel_backlight_device_unregister(intel_connector
);
1315 /* Set up chip specific backlight functions */
1316 void intel_panel_init_backlight_funcs(struct drm_device
*dev
)
1318 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1320 if (IS_BROADWELL(dev
)) {
1321 dev_priv
->display
.setup_backlight
= bdw_setup_backlight
;
1322 dev_priv
->display
.enable_backlight
= bdw_enable_backlight
;
1323 dev_priv
->display
.disable_backlight
= pch_disable_backlight
;
1324 dev_priv
->display
.set_backlight
= bdw_set_backlight
;
1325 dev_priv
->display
.get_backlight
= bdw_get_backlight
;
1326 } else if (HAS_PCH_SPLIT(dev
)) {
1327 dev_priv
->display
.setup_backlight
= pch_setup_backlight
;
1328 dev_priv
->display
.enable_backlight
= pch_enable_backlight
;
1329 dev_priv
->display
.disable_backlight
= pch_disable_backlight
;
1330 dev_priv
->display
.set_backlight
= pch_set_backlight
;
1331 dev_priv
->display
.get_backlight
= pch_get_backlight
;
1332 } else if (IS_VALLEYVIEW(dev
)) {
1333 dev_priv
->display
.setup_backlight
= vlv_setup_backlight
;
1334 dev_priv
->display
.enable_backlight
= vlv_enable_backlight
;
1335 dev_priv
->display
.disable_backlight
= vlv_disable_backlight
;
1336 dev_priv
->display
.set_backlight
= vlv_set_backlight
;
1337 dev_priv
->display
.get_backlight
= vlv_get_backlight
;
1338 } else if (IS_GEN4(dev
)) {
1339 dev_priv
->display
.setup_backlight
= i965_setup_backlight
;
1340 dev_priv
->display
.enable_backlight
= i965_enable_backlight
;
1341 dev_priv
->display
.disable_backlight
= i965_disable_backlight
;
1342 dev_priv
->display
.set_backlight
= i9xx_set_backlight
;
1343 dev_priv
->display
.get_backlight
= i9xx_get_backlight
;
1345 dev_priv
->display
.setup_backlight
= i9xx_setup_backlight
;
1346 dev_priv
->display
.enable_backlight
= i9xx_enable_backlight
;
1347 dev_priv
->display
.disable_backlight
= i9xx_disable_backlight
;
1348 dev_priv
->display
.set_backlight
= i9xx_set_backlight
;
1349 dev_priv
->display
.get_backlight
= i9xx_get_backlight
;
1353 int intel_panel_init(struct intel_panel
*panel
,
1354 struct drm_display_mode
*fixed_mode
,
1355 struct drm_display_mode
*downclock_mode
)
1357 panel
->fixed_mode
= fixed_mode
;
1358 panel
->downclock_mode
= downclock_mode
;
1363 void intel_panel_fini(struct intel_panel
*panel
)
1365 struct intel_connector
*intel_connector
=
1366 container_of(panel
, struct intel_connector
, panel
);
1368 if (panel
->fixed_mode
)
1369 drm_mode_destroy(intel_connector
->base
.dev
, panel
->fixed_mode
);
1371 if (panel
->downclock_mode
)
1372 drm_mode_destroy(intel_connector
->base
.dev
,
1373 panel
->downclock_mode
);