blob: 38a98570d10c864207d7f4ce7180a9795f30f9dc [file] [log] [blame]
Chris Wilson1d8e1c72010-08-07 11:01:28 +01001/*
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 Perchesa70491c2012-03-18 13:00:11 -070031#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
Carsten Emde7bd90902012-03-15 15:56:25 +010033#include <linux/moduleparam.h>
Chris Wilson1d8e1c72010-08-07 11:01:28 +010034#include "intel_drv.h"
35
36void
Ville Syrjälä4c6df4b2013-09-02 21:13:39 +030037intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
Chris Wilson1d8e1c72010-08-07 11:01:28 +010038 struct drm_display_mode *adjusted_mode)
39{
Ville Syrjälä4c6df4b2013-09-02 21:13:39 +030040 drm_mode_copy(adjusted_mode, fixed_mode);
Imre Deaka52690e2013-08-27 12:24:09 +030041
42 drm_mode_set_crtcinfo(adjusted_mode, 0);
Chris Wilson1d8e1c72010-08-07 11:01:28 +010043}
44
Jani Nikula525997e2014-04-29 23:30:48 +030045/**
46 * intel_find_panel_downclock - find the reduced downclock for LVDS in EDID
47 * @dev: drm device
48 * @fixed_mode : panel native mode
49 * @connector: LVDS/eDP connector
50 *
51 * Return downclock_avail
52 * Find the reduced downclock for LVDS/eDP in EDID.
53 */
54struct drm_display_mode *
55intel_find_panel_downclock(struct drm_device *dev,
56 struct drm_display_mode *fixed_mode,
57 struct drm_connector *connector)
58{
59 struct drm_display_mode *scan, *tmp_mode;
60 int temp_downclock;
61
62 temp_downclock = fixed_mode->clock;
63 tmp_mode = NULL;
64
65 list_for_each_entry(scan, &connector->probed_modes, head) {
66 /*
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.
72 */
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) {
82 /*
83 * The downclock is already found. But we
84 * expect to find the lower downclock.
85 */
86 temp_downclock = scan->clock;
87 tmp_mode = scan;
88 }
89 }
90 }
91
92 if (temp_downclock < fixed_mode->clock)
93 return drm_mode_duplicate(dev, tmp_mode);
94 else
95 return NULL;
96}
97
Chris Wilson1d8e1c72010-08-07 11:01:28 +010098/* adjusted_mode has been preset to be the panel's fixed mode */
99void
Jesse Barnesb074cec2013-04-25 12:55:02 -0700100intel_pch_panel_fitting(struct intel_crtc *intel_crtc,
101 struct intel_crtc_config *pipe_config,
102 int fitting_mode)
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100103{
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300104 struct drm_display_mode *adjusted_mode;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100105 int x, y, width, height;
106
Jesse Barnesb074cec2013-04-25 12:55:02 -0700107 adjusted_mode = &pipe_config->adjusted_mode;
108
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100109 x = y = width = height = 0;
110
111 /* Native modes don't need fitting */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300112 if (adjusted_mode->hdisplay == pipe_config->pipe_src_w &&
113 adjusted_mode->vdisplay == pipe_config->pipe_src_h)
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100114 goto done;
115
116 switch (fitting_mode) {
117 case DRM_MODE_SCALE_CENTER:
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300118 width = pipe_config->pipe_src_w;
119 height = pipe_config->pipe_src_h;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100120 x = (adjusted_mode->hdisplay - width + 1)/2;
121 y = (adjusted_mode->vdisplay - height + 1)/2;
122 break;
123
124 case DRM_MODE_SCALE_ASPECT:
125 /* Scale but preserve the aspect ratio */
126 {
Daniel Vetter9084e7d2013-09-16 23:43:45 +0200127 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;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100131 if (scaled_width > scaled_height) { /* pillar */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300132 width = scaled_height / pipe_config->pipe_src_h;
Adam Jackson302983e2011-07-13 16:32:32 -0400133 if (width & 1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400134 width++;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100135 x = (adjusted_mode->hdisplay - width + 1) / 2;
136 y = 0;
137 height = adjusted_mode->vdisplay;
138 } else if (scaled_width < scaled_height) { /* letter */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300139 height = scaled_width / pipe_config->pipe_src_w;
Adam Jackson302983e2011-07-13 16:32:32 -0400140 if (height & 1)
141 height++;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100142 y = (adjusted_mode->vdisplay - height + 1) / 2;
143 x = 0;
144 width = adjusted_mode->hdisplay;
145 } else {
146 x = y = 0;
147 width = adjusted_mode->hdisplay;
148 height = adjusted_mode->vdisplay;
149 }
150 }
151 break;
152
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100153 case DRM_MODE_SCALE_FULLSCREEN:
154 x = y = 0;
155 width = adjusted_mode->hdisplay;
156 height = adjusted_mode->vdisplay;
157 break;
Jesse Barnesab3e67f2013-04-25 12:55:03 -0700158
159 default:
160 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
161 return;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100162 }
163
164done:
Jesse Barnesb074cec2013-04-25 12:55:02 -0700165 pipe_config->pch_pfit.pos = (x << 16) | y;
166 pipe_config->pch_pfit.size = (width << 16) | height;
Chris Wilsonfd4daa92013-08-27 17:04:17 +0100167 pipe_config->pch_pfit.enabled = pipe_config->pch_pfit.size != 0;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100168}
Chris Wilsona9573552010-08-22 13:18:16 +0100169
Jesse Barnes2dd24552013-04-25 12:55:01 -0700170static void
171centre_horizontally(struct drm_display_mode *mode,
172 int width)
173{
174 u32 border, sync_pos, blank_width, sync_width;
175
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;
180
181 border = (mode->hdisplay - width + 1) / 2;
182 border += border & 1; /* make the border even */
183
184 mode->crtc_hdisplay = width;
185 mode->crtc_hblank_start = width + border;
186 mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
187
188 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
189 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
190}
191
192static void
193centre_vertically(struct drm_display_mode *mode,
194 int height)
195{
196 u32 border, sync_pos, blank_width, sync_width;
197
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;
202
203 border = (mode->vdisplay - height + 1) / 2;
204
205 mode->crtc_vdisplay = height;
206 mode->crtc_vblank_start = height + border;
207 mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
208
209 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
210 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
211}
212
213static inline u32 panel_fitter_scaling(u32 source, u32 target)
214{
215 /*
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.
219 */
220#define ACCURACY 12
221#define FACTOR (1 << ACCURACY)
222 u32 ratio = source * FACTOR / target;
223 return (FACTOR * ratio + FACTOR/2) / FACTOR;
224}
225
Daniel Vetter9084e7d2013-09-16 23:43:45 +0200226static void i965_scale_aspect(struct intel_crtc_config *pipe_config,
227 u32 *pfit_control)
228{
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;
234
235 /* 965+ is easy, it does everything in hw */
236 if (scaled_width > scaled_height)
237 *pfit_control |= PFIT_ENABLE |
238 PFIT_SCALING_PILLAR;
239 else if (scaled_width < scaled_height)
240 *pfit_control |= PFIT_ENABLE |
241 PFIT_SCALING_LETTER;
242 else if (adjusted_mode->hdisplay != pipe_config->pipe_src_w)
243 *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
244}
245
246static void i9xx_scale_aspect(struct intel_crtc_config *pipe_config,
247 u32 *pfit_control, u32 *pfit_pgm_ratios,
248 u32 *border)
249{
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;
255 u32 bits;
256
257 /*
258 * For earlier chips we have to calculate the scaling
259 * ratio by hand and program it into the
260 * PFIT_PGM_RATIO register
261 */
262 if (scaled_width > scaled_height) { /* pillar */
263 centre_horizontally(adjusted_mode,
264 scaled_height /
265 pipe_config->pipe_src_h);
266
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);
271
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);
277 }
278 } else if (scaled_width < scaled_height) { /* letter */
279 centre_vertically(adjusted_mode,
280 scaled_width /
281 pipe_config->pipe_src_w);
282
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);
287
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);
293 }
294 } else {
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);
300 }
301}
302
Jesse Barnes2dd24552013-04-25 12:55:01 -0700303void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc,
304 struct intel_crtc_config *pipe_config,
305 int fitting_mode)
306{
307 struct drm_device *dev = intel_crtc->base.dev;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700308 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300309 struct drm_display_mode *adjusted_mode;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700310
Jesse Barnes2dd24552013-04-25 12:55:01 -0700311 adjusted_mode = &pipe_config->adjusted_mode;
312
313 /* Native modes don't need fitting */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300314 if (adjusted_mode->hdisplay == pipe_config->pipe_src_w &&
315 adjusted_mode->vdisplay == pipe_config->pipe_src_h)
Jesse Barnes2dd24552013-04-25 12:55:01 -0700316 goto out;
317
318 switch (fitting_mode) {
319 case DRM_MODE_SCALE_CENTER:
320 /*
321 * For centered modes, we have to calculate border widths &
322 * heights and modify the values programmed into the CRTC.
323 */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300324 centre_horizontally(adjusted_mode, pipe_config->pipe_src_w);
325 centre_vertically(adjusted_mode, pipe_config->pipe_src_h);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700326 border = LVDS_BORDER_ENABLE;
327 break;
328 case DRM_MODE_SCALE_ASPECT:
329 /* Scale but preserve the aspect ratio */
Daniel Vetter9084e7d2013-09-16 23:43:45 +0200330 if (INTEL_INFO(dev)->gen >= 4)
331 i965_scale_aspect(pipe_config, &pfit_control);
332 else
333 i9xx_scale_aspect(pipe_config, &pfit_control,
334 &pfit_pgm_ratios, &border);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700335 break;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700336 case DRM_MODE_SCALE_FULLSCREEN:
337 /*
338 * Full scaling, even if it changes the aspect ratio.
339 * Fortunately this is all done for us in hw.
340 */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300341 if (pipe_config->pipe_src_h != adjusted_mode->vdisplay ||
342 pipe_config->pipe_src_w != adjusted_mode->hdisplay) {
Jesse Barnes2dd24552013-04-25 12:55:01 -0700343 pfit_control |= PFIT_ENABLE;
344 if (INTEL_INFO(dev)->gen >= 4)
345 pfit_control |= PFIT_SCALING_AUTO;
346 else
347 pfit_control |= (VERT_AUTO_SCALE |
348 VERT_INTERP_BILINEAR |
349 HORIZ_AUTO_SCALE |
350 HORIZ_INTERP_BILINEAR);
351 }
352 break;
Jesse Barnesab3e67f2013-04-25 12:55:03 -0700353 default:
354 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
355 return;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700356 }
357
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) |
362 PFIT_FILTER_FUZZY);
363
Daniel Vetter773875b2014-01-27 10:00:30 +0100364 /* Make sure pre-965 set dither correctly for 18bpp panels. */
365 if (INTEL_INFO(dev)->gen < 4 && pipe_config->pipe_bpp == 18)
366 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
367
Jesse Barnes2dd24552013-04-25 12:55:01 -0700368out:
369 if ((pfit_control & PFIT_ENABLE) == 0) {
370 pfit_control = 0;
371 pfit_pgm_ratios = 0;
372 }
373
Daniel Vetter2deefda2013-04-25 22:52:17 +0200374 pipe_config->gmch_pfit.control = pfit_control;
375 pipe_config->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
Daniel Vetter68fc8742013-04-25 22:52:16 +0200376 pipe_config->gmch_pfit.lvds_border_bits = border;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700377}
378
Jani Nikula525997e2014-04-29 23:30:48 +0300379enum drm_connector_status
380intel_panel_detect(struct drm_device *dev)
381{
382 struct drm_i915_private *dev_priv = dev->dev_private;
383
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;
389 }
390
391 switch (i915.panel_ignore_lid) {
392 case -2:
393 return connector_status_connected;
394 case -1:
395 return connector_status_disconnected;
396 default:
397 return connector_status_unknown;
398 }
399}
400
Jani Nikula7bd688c2013-11-08 16:48:56 +0200401static u32 intel_panel_compute_brightness(struct intel_connector *connector,
402 u32 val)
Carsten Emde7bd90902012-03-15 15:56:25 +0100403{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200404 struct drm_device *dev = connector->base.dev;
Carsten Emde4dca20e2012-03-15 15:56:26 +0100405 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200406 struct intel_panel *panel = &connector->panel;
407
408 WARN_ON(panel->backlight.max == 0);
Carsten Emde4dca20e2012-03-15 15:56:26 +0100409
Jani Nikulad330a952014-01-21 11:24:25 +0200410 if (i915.invert_brightness < 0)
Carsten Emde4dca20e2012-03-15 15:56:26 +0100411 return val;
412
Jani Nikulad330a952014-01-21 11:24:25 +0200413 if (i915.invert_brightness > 0 ||
Jani Nikulad6540632013-04-12 15:18:36 +0300414 dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) {
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200415 return panel->backlight.max - val;
Jani Nikulad6540632013-04-12 15:18:36 +0300416 }
Carsten Emde7bd90902012-03-15 15:56:25 +0100417
418 return val;
419}
420
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100421static u32 bdw_get_backlight(struct intel_connector *connector)
Chris Wilsona9573552010-08-22 13:18:16 +0100422{
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100423 struct drm_device *dev = connector->base.dev;
424 struct drm_i915_private *dev_priv = dev->dev_private;
425
426 return I915_READ(BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK;
427}
428
Jani Nikula7bd688c2013-11-08 16:48:56 +0200429static u32 pch_get_backlight(struct intel_connector *connector)
Chris Wilsona9573552010-08-22 13:18:16 +0100430{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200431 struct drm_device *dev = connector->base.dev;
432 struct drm_i915_private *dev_priv = dev->dev_private;
433
434 return I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
435}
436
437static u32 i9xx_get_backlight(struct intel_connector *connector)
438{
439 struct drm_device *dev = connector->base.dev;
440 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula636baeb2013-11-08 16:49:02 +0200441 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200442 u32 val;
443
444 val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
445 if (INTEL_INFO(dev)->gen < 4)
446 val >>= 1;
447
Jani Nikula636baeb2013-11-08 16:49:02 +0200448 if (panel->backlight.combination_mode) {
Jani Nikula7bd688c2013-11-08 16:48:56 +0200449 u8 lbpc;
450
451 pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc);
452 val *= lbpc;
453 }
454
455 return val;
456}
457
458static u32 _vlv_get_backlight(struct drm_device *dev, enum pipe pipe)
459{
460 struct drm_i915_private *dev_priv = dev->dev_private;
461
462 return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK;
463}
464
465static u32 vlv_get_backlight(struct intel_connector *connector)
466{
467 struct drm_device *dev = connector->base.dev;
468 enum pipe pipe = intel_get_pipe_from_connector(connector);
469
470 return _vlv_get_backlight(dev, pipe);
471}
472
473static u32 intel_panel_get_backlight(struct intel_connector *connector)
474{
475 struct drm_device *dev = connector->base.dev;
Chris Wilsona9573552010-08-22 13:18:16 +0100476 struct drm_i915_private *dev_priv = dev->dev_private;
477 u32 val;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300478 unsigned long flags;
479
Jani Nikula58c68772013-11-08 16:48:54 +0200480 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilsona9573552010-08-22 13:18:16 +0100481
Jani Nikula7bd688c2013-11-08 16:48:56 +0200482 val = dev_priv->display.get_backlight(connector);
483 val = intel_panel_compute_brightness(connector, val);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300484
Jani Nikula58c68772013-11-08 16:48:54 +0200485 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300486
Chris Wilsona9573552010-08-22 13:18:16 +0100487 DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val);
488 return val;
489}
490
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100491static void bdw_set_backlight(struct intel_connector *connector, u32 level)
Ben Widawskyf8e10062013-11-11 11:12:57 +0200492{
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100493 struct drm_device *dev = connector->base.dev;
Ben Widawskyf8e10062013-11-11 11:12:57 +0200494 struct drm_i915_private *dev_priv = dev->dev_private;
495 u32 val = I915_READ(BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK;
496 I915_WRITE(BLC_PWM_PCH_CTL2, val | level);
497}
498
Jani Nikula7bd688c2013-11-08 16:48:56 +0200499static void pch_set_backlight(struct intel_connector *connector, u32 level)
Chris Wilsona9573552010-08-22 13:18:16 +0100500{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200501 struct drm_device *dev = connector->base.dev;
Chris Wilsona9573552010-08-22 13:18:16 +0100502 struct drm_i915_private *dev_priv = dev->dev_private;
503 u32 tmp;
504
Jani Nikula7bd688c2013-11-08 16:48:56 +0200505 tmp = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
506 I915_WRITE(BLC_PWM_CPU_CTL, tmp | level);
507}
Chris Wilsona9573552010-08-22 13:18:16 +0100508
Jani Nikula7bd688c2013-11-08 16:48:56 +0200509static void i9xx_set_backlight(struct intel_connector *connector, u32 level)
510{
511 struct drm_device *dev = connector->base.dev;
512 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200513 struct intel_panel *panel = &connector->panel;
Jani Nikulab329b322013-11-08 16:48:57 +0200514 u32 tmp, mask;
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100515
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200516 WARN_ON(panel->backlight.max == 0);
517
Jani Nikula636baeb2013-11-08 16:49:02 +0200518 if (panel->backlight.combination_mode) {
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100519 u8 lbpc;
520
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200521 lbpc = level * 0xfe / panel->backlight.max + 1;
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100522 level /= lbpc;
523 pci_write_config_byte(dev->pdev, PCI_LBPC, lbpc);
524 }
525
Jani Nikulab329b322013-11-08 16:48:57 +0200526 if (IS_GEN4(dev)) {
527 mask = BACKLIGHT_DUTY_CYCLE_MASK;
528 } else {
Chris Wilsona9573552010-08-22 13:18:16 +0100529 level <<= 1;
Jani Nikulab329b322013-11-08 16:48:57 +0200530 mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV;
531 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200532
Jani Nikulab329b322013-11-08 16:48:57 +0200533 tmp = I915_READ(BLC_PWM_CTL) & ~mask;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200534 I915_WRITE(BLC_PWM_CTL, tmp | level);
535}
536
537static void vlv_set_backlight(struct intel_connector *connector, u32 level)
538{
539 struct drm_device *dev = connector->base.dev;
540 struct drm_i915_private *dev_priv = dev->dev_private;
541 enum pipe pipe = intel_get_pipe_from_connector(connector);
542 u32 tmp;
543
544 tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK;
545 I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
546}
547
548static void
549intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
550{
551 struct drm_device *dev = connector->base.dev;
552 struct drm_i915_private *dev_priv = dev->dev_private;
553
554 DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level);
555
556 level = intel_panel_compute_brightness(connector, level);
557 dev_priv->display.set_backlight(connector, level);
Chris Wilsona9573552010-08-22 13:18:16 +0100558}
Chris Wilson47356eb2011-01-11 17:06:04 +0000559
Jani Nikulad6540632013-04-12 15:18:36 +0300560/* set backlight brightness to level in range [0..max] */
Jesse Barnes752aa882013-10-31 18:55:49 +0200561void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
562 u32 max)
Takashi Iwaif52c6192011-10-14 11:45:40 +0200563{
Jesse Barnes752aa882013-10-31 18:55:49 +0200564 struct drm_device *dev = connector->base.dev;
Takashi Iwaif52c6192011-10-14 11:45:40 +0200565 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200566 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200567 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulad6540632013-04-12 15:18:36 +0300568 u32 freq;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300569 unsigned long flags;
Aaron Lu721e82c2014-05-12 16:55:45 +0800570 u64 n;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300571
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200572 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200573 return;
574
Jani Nikula58c68772013-11-08 16:48:54 +0200575 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Jani Nikulad6540632013-04-12 15:18:36 +0300576
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200577 WARN_ON(panel->backlight.max == 0);
Jani Nikulad6540632013-04-12 15:18:36 +0300578
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200579 /* scale to hardware max, but be careful to not overflow */
580 freq = panel->backlight.max;
Aaron Lu721e82c2014-05-12 16:55:45 +0800581 n = (u64)level * freq;
582 do_div(n, max);
583 level = n;
Takashi Iwaif52c6192011-10-14 11:45:40 +0200584
Jani Nikula58c68772013-11-08 16:48:54 +0200585 panel->backlight.level = level;
586 if (panel->backlight.device)
587 panel->backlight.device->props.brightness = level;
Jani Nikulab6b3ba52013-03-12 11:44:15 +0200588
Jani Nikula58c68772013-11-08 16:48:54 +0200589 if (panel->backlight.enabled)
Jani Nikula7bd688c2013-11-08 16:48:56 +0200590 intel_panel_actually_set_backlight(connector, level);
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200591
Jani Nikula58c68772013-11-08 16:48:54 +0200592 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Takashi Iwaif52c6192011-10-14 11:45:40 +0200593}
594
Jani Nikula7bd688c2013-11-08 16:48:56 +0200595static void pch_disable_backlight(struct intel_connector *connector)
596{
597 struct drm_device *dev = connector->base.dev;
598 struct drm_i915_private *dev_priv = dev->dev_private;
599 u32 tmp;
600
Jani Nikula3bd712e2013-11-08 16:48:59 +0200601 intel_panel_actually_set_backlight(connector, 0);
602
Jani Nikula7bd688c2013-11-08 16:48:56 +0200603 tmp = I915_READ(BLC_PWM_CPU_CTL2);
604 I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE);
605
606 tmp = I915_READ(BLC_PWM_PCH_CTL1);
607 I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE);
608}
609
Jani Nikula3bd712e2013-11-08 16:48:59 +0200610static void i9xx_disable_backlight(struct intel_connector *connector)
611{
612 intel_panel_actually_set_backlight(connector, 0);
613}
614
Jani Nikula7bd688c2013-11-08 16:48:56 +0200615static void i965_disable_backlight(struct intel_connector *connector)
616{
617 struct drm_device *dev = connector->base.dev;
618 struct drm_i915_private *dev_priv = dev->dev_private;
619 u32 tmp;
620
Jani Nikula3bd712e2013-11-08 16:48:59 +0200621 intel_panel_actually_set_backlight(connector, 0);
622
Jani Nikula7bd688c2013-11-08 16:48:56 +0200623 tmp = I915_READ(BLC_PWM_CTL2);
624 I915_WRITE(BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE);
625}
626
627static void vlv_disable_backlight(struct intel_connector *connector)
628{
629 struct drm_device *dev = connector->base.dev;
630 struct drm_i915_private *dev_priv = dev->dev_private;
631 enum pipe pipe = intel_get_pipe_from_connector(connector);
632 u32 tmp;
633
Jani Nikula3bd712e2013-11-08 16:48:59 +0200634 intel_panel_actually_set_backlight(connector, 0);
635
Jani Nikula7bd688c2013-11-08 16:48:56 +0200636 tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe));
637 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
638}
639
Jesse Barnes752aa882013-10-31 18:55:49 +0200640void intel_panel_disable_backlight(struct intel_connector *connector)
Chris Wilson47356eb2011-01-11 17:06:04 +0000641{
Jesse Barnes752aa882013-10-31 18:55:49 +0200642 struct drm_device *dev = connector->base.dev;
Chris Wilson47356eb2011-01-11 17:06:04 +0000643 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200644 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200645 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300646 unsigned long flags;
647
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200648 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200649 return;
650
Jani Nikula3f577572013-07-25 14:31:30 +0300651 /*
652 * Do not disable backlight on the vgaswitcheroo path. When switching
653 * away from i915, the other client may depend on i915 to handle the
654 * backlight. This will leave the backlight on unnecessarily when
655 * another client is not activated.
656 */
657 if (dev->switch_power_state == DRM_SWITCH_POWER_CHANGING) {
658 DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
659 return;
660 }
661
Jani Nikula58c68772013-11-08 16:48:54 +0200662 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000663
Jani Nikula58c68772013-11-08 16:48:54 +0200664 panel->backlight.enabled = false;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200665 dev_priv->display.disable_backlight(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300666
Jani Nikula58c68772013-11-08 16:48:54 +0200667 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000668}
669
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100670static void bdw_enable_backlight(struct intel_connector *connector)
671{
672 struct drm_device *dev = connector->base.dev;
673 struct drm_i915_private *dev_priv = dev->dev_private;
674 struct intel_panel *panel = &connector->panel;
675 u32 pch_ctl1, pch_ctl2;
Chris Wilson47356eb2011-01-11 17:06:04 +0000676
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100677 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
678 if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
679 DRM_DEBUG_KMS("pch backlight already enabled\n");
680 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
681 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
Chris Wilson47356eb2011-01-11 17:06:04 +0000682 }
683
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100684 pch_ctl2 = panel->backlight.max << 16;
685 I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
686
687 pch_ctl1 = 0;
688 if (panel->backlight.active_low_pwm)
689 pch_ctl1 |= BLM_PCH_POLARITY;
690
691 /* BDW always uses the pch pwm controls. */
692 pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE;
693
694 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
695 POSTING_READ(BLC_PWM_PCH_CTL1);
696 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
697
698 /* This won't stick until the above enable. */
699 intel_panel_actually_set_backlight(connector, panel->backlight.level);
700}
701
Jani Nikula7bd688c2013-11-08 16:48:56 +0200702static void pch_enable_backlight(struct intel_connector *connector)
703{
704 struct drm_device *dev = connector->base.dev;
705 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200706 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200707 enum pipe pipe = intel_get_pipe_from_connector(connector);
708 enum transcoder cpu_transcoder =
709 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
Jani Nikulab35684b2013-11-14 12:13:41 +0200710 u32 cpu_ctl2, pch_ctl1, pch_ctl2;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200711
Jani Nikulab35684b2013-11-14 12:13:41 +0200712 cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
713 if (cpu_ctl2 & BLM_PWM_ENABLE) {
714 WARN(1, "cpu backlight already enabled\n");
715 cpu_ctl2 &= ~BLM_PWM_ENABLE;
716 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200717 }
Jani Nikula3bd712e2013-11-08 16:48:59 +0200718
Jani Nikulab35684b2013-11-14 12:13:41 +0200719 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
720 if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
721 DRM_DEBUG_KMS("pch backlight already enabled\n");
722 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
723 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
724 }
725
726 if (cpu_transcoder == TRANSCODER_EDP)
727 cpu_ctl2 = BLM_TRANSCODER_EDP;
728 else
729 cpu_ctl2 = BLM_PIPE(cpu_transcoder);
730 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
731 POSTING_READ(BLC_PWM_CPU_CTL2);
732 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE);
733
734 /* This won't stick until the above enable. */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200735 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikulab35684b2013-11-14 12:13:41 +0200736
737 pch_ctl2 = panel->backlight.max << 16;
738 I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
739
Jani Nikulab35684b2013-11-14 12:13:41 +0200740 pch_ctl1 = 0;
741 if (panel->backlight.active_low_pwm)
742 pch_ctl1 |= BLM_PCH_POLARITY;
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100743
Jani Nikulab35684b2013-11-14 12:13:41 +0200744 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
745 POSTING_READ(BLC_PWM_PCH_CTL1);
746 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
Jani Nikula3bd712e2013-11-08 16:48:59 +0200747}
748
749static void i9xx_enable_backlight(struct intel_connector *connector)
750{
Jani Nikulab35684b2013-11-14 12:13:41 +0200751 struct drm_device *dev = connector->base.dev;
752 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200753 struct intel_panel *panel = &connector->panel;
Jani Nikulab35684b2013-11-14 12:13:41 +0200754 u32 ctl, freq;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200755
Jani Nikulab35684b2013-11-14 12:13:41 +0200756 ctl = I915_READ(BLC_PWM_CTL);
757 if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) {
758 WARN(1, "backlight already enabled\n");
759 I915_WRITE(BLC_PWM_CTL, 0);
760 }
761
762 freq = panel->backlight.max;
763 if (panel->backlight.combination_mode)
764 freq /= 0xff;
765
766 ctl = freq << 17;
Jani Nikulab6ab66aa2014-02-25 13:11:47 +0200767 if (panel->backlight.combination_mode)
Jani Nikulab35684b2013-11-14 12:13:41 +0200768 ctl |= BLM_LEGACY_MODE;
769 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm)
770 ctl |= BLM_POLARITY_PNV;
771
772 I915_WRITE(BLC_PWM_CTL, ctl);
773 POSTING_READ(BLC_PWM_CTL);
774
775 /* XXX: combine this into above write? */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200776 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200777}
778
779static void i965_enable_backlight(struct intel_connector *connector)
780{
781 struct drm_device *dev = connector->base.dev;
782 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200783 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200784 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulab35684b2013-11-14 12:13:41 +0200785 u32 ctl, ctl2, freq;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200786
Jani Nikulab35684b2013-11-14 12:13:41 +0200787 ctl2 = I915_READ(BLC_PWM_CTL2);
788 if (ctl2 & BLM_PWM_ENABLE) {
789 WARN(1, "backlight already enabled\n");
790 ctl2 &= ~BLM_PWM_ENABLE;
791 I915_WRITE(BLC_PWM_CTL2, ctl2);
792 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200793
Jani Nikulab35684b2013-11-14 12:13:41 +0200794 freq = panel->backlight.max;
795 if (panel->backlight.combination_mode)
796 freq /= 0xff;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200797
Jani Nikulab35684b2013-11-14 12:13:41 +0200798 ctl = freq << 16;
799 I915_WRITE(BLC_PWM_CTL, ctl);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200800
Jani Nikulab35684b2013-11-14 12:13:41 +0200801 ctl2 = BLM_PIPE(pipe);
802 if (panel->backlight.combination_mode)
803 ctl2 |= BLM_COMBINATION_MODE;
804 if (panel->backlight.active_low_pwm)
805 ctl2 |= BLM_POLARITY_I965;
806 I915_WRITE(BLC_PWM_CTL2, ctl2);
807 POSTING_READ(BLC_PWM_CTL2);
808 I915_WRITE(BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE);
Jani Nikula2e7eeeb2014-06-09 18:24:34 +0300809
810 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200811}
812
813static void vlv_enable_backlight(struct intel_connector *connector)
814{
815 struct drm_device *dev = connector->base.dev;
816 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200817 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200818 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulab35684b2013-11-14 12:13:41 +0200819 u32 ctl, ctl2;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200820
Jani Nikulab35684b2013-11-14 12:13:41 +0200821 ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
822 if (ctl2 & BLM_PWM_ENABLE) {
823 WARN(1, "backlight already enabled\n");
824 ctl2 &= ~BLM_PWM_ENABLE;
825 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
826 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200827
Jani Nikulab35684b2013-11-14 12:13:41 +0200828 ctl = panel->backlight.max << 16;
829 I915_WRITE(VLV_BLC_PWM_CTL(pipe), ctl);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200830
Jani Nikulab35684b2013-11-14 12:13:41 +0200831 /* XXX: combine this into above write? */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200832 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikulab35684b2013-11-14 12:13:41 +0200833
834 ctl2 = 0;
835 if (panel->backlight.active_low_pwm)
836 ctl2 |= BLM_POLARITY_I965;
837 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
838 POSTING_READ(VLV_BLC_PWM_CTL2(pipe));
839 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200840}
841
Jesse Barnes752aa882013-10-31 18:55:49 +0200842void intel_panel_enable_backlight(struct intel_connector *connector)
Chris Wilson47356eb2011-01-11 17:06:04 +0000843{
Jesse Barnes752aa882013-10-31 18:55:49 +0200844 struct drm_device *dev = connector->base.dev;
Chris Wilson47356eb2011-01-11 17:06:04 +0000845 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200846 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200847 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300848 unsigned long flags;
849
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200850 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200851 return;
852
Damien Lespiau6f2bcce2013-10-16 12:29:54 +0100853 DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
Chris Wilson540b5d02013-10-13 12:56:31 +0100854
Jani Nikula58c68772013-11-08 16:48:54 +0200855 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000856
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200857 WARN_ON(panel->backlight.max == 0);
858
Jani Nikula58c68772013-11-08 16:48:54 +0200859 if (panel->backlight.level == 0) {
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200860 panel->backlight.level = panel->backlight.max;
Jani Nikula58c68772013-11-08 16:48:54 +0200861 if (panel->backlight.device)
862 panel->backlight.device->props.brightness =
863 panel->backlight.level;
Jani Nikulab6b3ba52013-03-12 11:44:15 +0200864 }
Chris Wilson47356eb2011-01-11 17:06:04 +0000865
Jani Nikula3bd712e2013-11-08 16:48:59 +0200866 dev_priv->display.enable_backlight(connector);
Jani Nikula58c68772013-11-08 16:48:54 +0200867 panel->backlight.enabled = true;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300868
Jani Nikula58c68772013-11-08 16:48:54 +0200869 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000870}
871
Jani Nikula912e8b12013-09-18 17:19:45 +0300872#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200873static int intel_backlight_device_update_status(struct backlight_device *bd)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200874{
Jesse Barnes752aa882013-10-31 18:55:49 +0200875 struct intel_connector *connector = bl_get_data(bd);
876 struct drm_device *dev = connector->base.dev;
877
Rob Clark51fd3712013-11-19 12:10:12 -0500878 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
Chris Wilson540b5d02013-10-13 12:56:31 +0100879 DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n",
880 bd->props.brightness, bd->props.max_brightness);
Jesse Barnes752aa882013-10-31 18:55:49 +0200881 intel_panel_set_backlight(connector, bd->props.brightness,
Jani Nikulad6540632013-04-12 15:18:36 +0300882 bd->props.max_brightness);
Rob Clark51fd3712013-11-19 12:10:12 -0500883 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200884 return 0;
885}
886
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200887static int intel_backlight_device_get_brightness(struct backlight_device *bd)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200888{
Jesse Barnes752aa882013-10-31 18:55:49 +0200889 struct intel_connector *connector = bl_get_data(bd);
890 struct drm_device *dev = connector->base.dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200891 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200892 int ret;
Jesse Barnes752aa882013-10-31 18:55:49 +0200893
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200894 intel_runtime_pm_get(dev_priv);
Rob Clark51fd3712013-11-19 12:10:12 -0500895 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200896 ret = intel_panel_get_backlight(connector);
Rob Clark51fd3712013-11-19 12:10:12 -0500897 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200898 intel_runtime_pm_put(dev_priv);
Jesse Barnes752aa882013-10-31 18:55:49 +0200899
Jani Nikula7bd688c2013-11-08 16:48:56 +0200900 return ret;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200901}
902
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200903static const struct backlight_ops intel_backlight_device_ops = {
904 .update_status = intel_backlight_device_update_status,
905 .get_brightness = intel_backlight_device_get_brightness,
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200906};
907
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200908static int intel_backlight_device_register(struct intel_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200909{
Jani Nikula58c68772013-11-08 16:48:54 +0200910 struct intel_panel *panel = &connector->panel;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200911 struct backlight_properties props;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200912
Jani Nikula58c68772013-11-08 16:48:54 +0200913 if (WARN_ON(panel->backlight.device))
Jani Nikuladc652f92013-04-12 15:18:38 +0300914 return -ENODEV;
915
Jani Nikula7bd688c2013-11-08 16:48:56 +0200916 BUG_ON(panel->backlight.max == 0);
917
Corentin Charyaf437cf2012-05-22 10:29:46 +0100918 memset(&props, 0, sizeof(props));
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200919 props.type = BACKLIGHT_RAW;
Jani Nikula58c68772013-11-08 16:48:54 +0200920 props.brightness = panel->backlight.level;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200921 props.max_brightness = panel->backlight.max;
Jani Nikula58c68772013-11-08 16:48:54 +0200922
923 /*
924 * Note: using the same name independent of the connector prevents
925 * registration of multiple backlight devices in the driver.
926 */
927 panel->backlight.device =
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200928 backlight_device_register("intel_backlight",
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200929 connector->base.kdev,
930 connector,
931 &intel_backlight_device_ops, &props);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200932
Jani Nikula58c68772013-11-08 16:48:54 +0200933 if (IS_ERR(panel->backlight.device)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200934 DRM_ERROR("Failed to register backlight: %ld\n",
Jani Nikula58c68772013-11-08 16:48:54 +0200935 PTR_ERR(panel->backlight.device));
936 panel->backlight.device = NULL;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200937 return -ENODEV;
938 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200939 return 0;
940}
941
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200942static void intel_backlight_device_unregister(struct intel_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200943{
Jani Nikula58c68772013-11-08 16:48:54 +0200944 struct intel_panel *panel = &connector->panel;
945
946 if (panel->backlight.device) {
947 backlight_device_unregister(panel->backlight.device);
948 panel->backlight.device = NULL;
Jani Nikuladc652f92013-04-12 15:18:38 +0300949 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200950}
Jani Nikuladb31af1d2013-11-08 16:48:53 +0200951#else /* CONFIG_BACKLIGHT_CLASS_DEVICE */
952static int intel_backlight_device_register(struct intel_connector *connector)
953{
954 return 0;
955}
956static void intel_backlight_device_unregister(struct intel_connector *connector)
957{
958}
959#endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
960
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200961/*
962 * Note: The setup hooks can't assume pipe is set!
963 *
964 * XXX: Query mode clock or hardware clock and program PWM modulation frequency
965 * appropriately when it's 0. Use VBT and/or sane defaults.
966 */
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100967static int bdw_setup_backlight(struct intel_connector *connector)
968{
969 struct drm_device *dev = connector->base.dev;
970 struct drm_i915_private *dev_priv = dev->dev_private;
971 struct intel_panel *panel = &connector->panel;
972 u32 pch_ctl1, pch_ctl2, val;
973
974 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
975 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
976
977 pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
978 panel->backlight.max = pch_ctl2 >> 16;
979 if (!panel->backlight.max)
980 return -ENODEV;
981
982 val = bdw_get_backlight(connector);
983 panel->backlight.level = intel_panel_compute_brightness(connector, val);
984
985 panel->backlight.enabled = (pch_ctl1 & BLM_PCH_PWM_ENABLE) &&
986 panel->backlight.level != 0;
987
988 return 0;
989}
990
Jani Nikula7bd688c2013-11-08 16:48:56 +0200991static int pch_setup_backlight(struct intel_connector *connector)
992{
Jani Nikula636baeb2013-11-08 16:49:02 +0200993 struct drm_device *dev = connector->base.dev;
994 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200995 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +0200996 u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200997
Jani Nikula636baeb2013-11-08 16:49:02 +0200998 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
999 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
1000
1001 pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
1002 panel->backlight.max = pch_ctl2 >> 16;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001003 if (!panel->backlight.max)
1004 return -ENODEV;
1005
1006 val = pch_get_backlight(connector);
1007 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1008
Jani Nikula636baeb2013-11-08 16:49:02 +02001009 cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
1010 panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) &&
1011 (pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0;
1012
Jani Nikula7bd688c2013-11-08 16:48:56 +02001013 return 0;
1014}
1015
1016static int i9xx_setup_backlight(struct intel_connector *connector)
1017{
Jani Nikula636baeb2013-11-08 16:49:02 +02001018 struct drm_device *dev = connector->base.dev;
1019 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001020 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +02001021 u32 ctl, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001022
Jani Nikula636baeb2013-11-08 16:49:02 +02001023 ctl = I915_READ(BLC_PWM_CTL);
1024
Jani Nikulab6ab66aa2014-02-25 13:11:47 +02001025 if (IS_GEN2(dev) || IS_I915GM(dev) || IS_I945GM(dev))
Jani Nikula636baeb2013-11-08 16:49:02 +02001026 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
1027
1028 if (IS_PINEVIEW(dev))
1029 panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV;
1030
1031 panel->backlight.max = ctl >> 17;
1032 if (panel->backlight.combination_mode)
1033 panel->backlight.max *= 0xff;
1034
Jani Nikula7bd688c2013-11-08 16:48:56 +02001035 if (!panel->backlight.max)
1036 return -ENODEV;
1037
1038 val = i9xx_get_backlight(connector);
1039 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1040
Jani Nikula636baeb2013-11-08 16:49:02 +02001041 panel->backlight.enabled = panel->backlight.level != 0;
1042
Jani Nikula7bd688c2013-11-08 16:48:56 +02001043 return 0;
1044}
1045
1046static int i965_setup_backlight(struct intel_connector *connector)
1047{
Jani Nikula636baeb2013-11-08 16:49:02 +02001048 struct drm_device *dev = connector->base.dev;
1049 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001050 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +02001051 u32 ctl, ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001052
Jani Nikula636baeb2013-11-08 16:49:02 +02001053 ctl2 = I915_READ(BLC_PWM_CTL2);
1054 panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE;
1055 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1056
1057 ctl = I915_READ(BLC_PWM_CTL);
1058 panel->backlight.max = ctl >> 16;
1059 if (panel->backlight.combination_mode)
1060 panel->backlight.max *= 0xff;
1061
Jani Nikula7bd688c2013-11-08 16:48:56 +02001062 if (!panel->backlight.max)
1063 return -ENODEV;
1064
1065 val = i9xx_get_backlight(connector);
1066 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1067
Jani Nikula636baeb2013-11-08 16:49:02 +02001068 panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
1069 panel->backlight.level != 0;
1070
Jani Nikula7bd688c2013-11-08 16:48:56 +02001071 return 0;
1072}
1073
1074static int vlv_setup_backlight(struct intel_connector *connector)
1075{
1076 struct drm_device *dev = connector->base.dev;
1077 struct drm_i915_private *dev_priv = dev->dev_private;
1078 struct intel_panel *panel = &connector->panel;
1079 enum pipe pipe;
Jani Nikula636baeb2013-11-08 16:49:02 +02001080 u32 ctl, ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001081
1082 for_each_pipe(pipe) {
1083 u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(pipe));
1084
1085 /* Skip if the modulation freq is already set */
1086 if (cur_val & ~BACKLIGHT_DUTY_CYCLE_MASK)
1087 continue;
1088
1089 cur_val &= BACKLIGHT_DUTY_CYCLE_MASK;
1090 I915_WRITE(VLV_BLC_PWM_CTL(pipe), (0xf42 << 16) |
1091 cur_val);
1092 }
1093
Jani Nikula636baeb2013-11-08 16:49:02 +02001094 ctl2 = I915_READ(VLV_BLC_PWM_CTL2(PIPE_A));
1095 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1096
1097 ctl = I915_READ(VLV_BLC_PWM_CTL(PIPE_A));
1098 panel->backlight.max = ctl >> 16;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001099 if (!panel->backlight.max)
1100 return -ENODEV;
1101
1102 val = _vlv_get_backlight(dev, PIPE_A);
1103 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1104
Jani Nikula636baeb2013-11-08 16:49:02 +02001105 panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
1106 panel->backlight.level != 0;
1107
Jani Nikula7bd688c2013-11-08 16:48:56 +02001108 return 0;
1109}
1110
Jani Nikula0657b6b2012-10-19 14:51:46 +03001111int intel_panel_setup_backlight(struct drm_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001112{
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001113 struct drm_device *dev = connector->dev;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001114 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001115 struct intel_connector *intel_connector = to_intel_connector(connector);
Jani Nikula58c68772013-11-08 16:48:54 +02001116 struct intel_panel *panel = &intel_connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001117 unsigned long flags;
1118 int ret;
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001119
Jani Nikulac6759492014-04-09 11:31:37 +03001120 if (!dev_priv->vbt.backlight.present) {
1121 DRM_DEBUG_KMS("native backlight control not available per VBT\n");
1122 return 0;
1123 }
1124
Jani Nikula7bd688c2013-11-08 16:48:56 +02001125 /* set level and max in panel struct */
1126 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
1127 ret = dev_priv->display.setup_backlight(intel_connector);
1128 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001129
Jani Nikula7bd688c2013-11-08 16:48:56 +02001130 if (ret) {
1131 DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001132 connector->name);
Jani Nikula7bd688c2013-11-08 16:48:56 +02001133 return ret;
1134 }
1135
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001136 intel_backlight_device_register(intel_connector);
1137
Jani Nikulac91c9f32013-11-08 16:48:55 +02001138 panel->backlight.present = true;
1139
Jani Nikulac445b3b2013-11-08 16:49:01 +02001140 DRM_DEBUG_KMS("backlight initialized, %s, brightness %u/%u, "
1141 "sysfs interface %sregistered\n",
1142 panel->backlight.enabled ? "enabled" : "disabled",
1143 panel->backlight.level, panel->backlight.max,
1144 panel->backlight.device ? "" : "not ");
1145
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001146 return 0;
1147}
1148
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001149void intel_panel_destroy_backlight(struct drm_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001150{
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001151 struct intel_connector *intel_connector = to_intel_connector(connector);
Jani Nikulac91c9f32013-11-08 16:48:55 +02001152 struct intel_panel *panel = &intel_connector->panel;
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001153
Jani Nikulac91c9f32013-11-08 16:48:55 +02001154 panel->backlight.present = false;
Jani Nikuladb31af1d2013-11-08 16:48:53 +02001155 intel_backlight_device_unregister(intel_connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001156}
Jani Nikula1d508702012-10-19 14:51:49 +03001157
Jani Nikula7bd688c2013-11-08 16:48:56 +02001158/* Set up chip specific backlight functions */
1159void intel_panel_init_backlight_funcs(struct drm_device *dev)
1160{
1161 struct drm_i915_private *dev_priv = dev->dev_private;
1162
Daniel Vetter96ab4c72013-11-14 15:17:41 +01001163 if (IS_BROADWELL(dev)) {
1164 dev_priv->display.setup_backlight = bdw_setup_backlight;
1165 dev_priv->display.enable_backlight = bdw_enable_backlight;
1166 dev_priv->display.disable_backlight = pch_disable_backlight;
1167 dev_priv->display.set_backlight = bdw_set_backlight;
1168 dev_priv->display.get_backlight = bdw_get_backlight;
1169 } else if (HAS_PCH_SPLIT(dev)) {
Jani Nikula7bd688c2013-11-08 16:48:56 +02001170 dev_priv->display.setup_backlight = pch_setup_backlight;
1171 dev_priv->display.enable_backlight = pch_enable_backlight;
1172 dev_priv->display.disable_backlight = pch_disable_backlight;
1173 dev_priv->display.set_backlight = pch_set_backlight;
1174 dev_priv->display.get_backlight = pch_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001175 } else if (IS_VALLEYVIEW(dev)) {
1176 dev_priv->display.setup_backlight = vlv_setup_backlight;
1177 dev_priv->display.enable_backlight = vlv_enable_backlight;
1178 dev_priv->display.disable_backlight = vlv_disable_backlight;
1179 dev_priv->display.set_backlight = vlv_set_backlight;
1180 dev_priv->display.get_backlight = vlv_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001181 } else if (IS_GEN4(dev)) {
1182 dev_priv->display.setup_backlight = i965_setup_backlight;
1183 dev_priv->display.enable_backlight = i965_enable_backlight;
1184 dev_priv->display.disable_backlight = i965_disable_backlight;
1185 dev_priv->display.set_backlight = i9xx_set_backlight;
1186 dev_priv->display.get_backlight = i9xx_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001187 } else {
1188 dev_priv->display.setup_backlight = i9xx_setup_backlight;
Jani Nikula3bd712e2013-11-08 16:48:59 +02001189 dev_priv->display.enable_backlight = i9xx_enable_backlight;
1190 dev_priv->display.disable_backlight = i9xx_disable_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001191 dev_priv->display.set_backlight = i9xx_set_backlight;
1192 dev_priv->display.get_backlight = i9xx_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001193 }
1194}
1195
Jani Nikuladd06f902012-10-19 14:51:50 +03001196int intel_panel_init(struct intel_panel *panel,
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301197 struct drm_display_mode *fixed_mode,
1198 struct drm_display_mode *downclock_mode)
Jani Nikula1d508702012-10-19 14:51:49 +03001199{
Jani Nikuladd06f902012-10-19 14:51:50 +03001200 panel->fixed_mode = fixed_mode;
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301201 panel->downclock_mode = downclock_mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03001202
Jani Nikula1d508702012-10-19 14:51:49 +03001203 return 0;
1204}
1205
1206void intel_panel_fini(struct intel_panel *panel)
1207{
Jani Nikuladd06f902012-10-19 14:51:50 +03001208 struct intel_connector *intel_connector =
1209 container_of(panel, struct intel_connector, panel);
1210
1211 if (panel->fixed_mode)
1212 drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode);
Vandana Kannanec9ed192013-12-10 13:37:36 +05301213
1214 if (panel->downclock_mode)
1215 drm_mode_destroy(intel_connector->base.dev,
1216 panel->downclock_mode);
Jani Nikula1d508702012-10-19 14:51:49 +03001217}