blob: 0eead16aeda7404053de8c9885992b0904c1049c [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
45/* adjusted_mode has been preset to be the panel's fixed mode */
46void
Jesse Barnesb074cec2013-04-25 12:55:02 -070047intel_pch_panel_fitting(struct intel_crtc *intel_crtc,
48 struct intel_crtc_config *pipe_config,
49 int fitting_mode)
Chris Wilson1d8e1c72010-08-07 11:01:28 +010050{
Ville Syrjälä37327ab2013-09-04 18:25:28 +030051 struct drm_display_mode *adjusted_mode;
Chris Wilson1d8e1c72010-08-07 11:01:28 +010052 int x, y, width, height;
53
Jesse Barnesb074cec2013-04-25 12:55:02 -070054 adjusted_mode = &pipe_config->adjusted_mode;
55
Chris Wilson1d8e1c72010-08-07 11:01:28 +010056 x = y = width = height = 0;
57
58 /* Native modes don't need fitting */
Ville Syrjälä37327ab2013-09-04 18:25:28 +030059 if (adjusted_mode->hdisplay == pipe_config->pipe_src_w &&
60 adjusted_mode->vdisplay == pipe_config->pipe_src_h)
Chris Wilson1d8e1c72010-08-07 11:01:28 +010061 goto done;
62
63 switch (fitting_mode) {
64 case DRM_MODE_SCALE_CENTER:
Ville Syrjälä37327ab2013-09-04 18:25:28 +030065 width = pipe_config->pipe_src_w;
66 height = pipe_config->pipe_src_h;
Chris Wilson1d8e1c72010-08-07 11:01:28 +010067 x = (adjusted_mode->hdisplay - width + 1)/2;
68 y = (adjusted_mode->vdisplay - height + 1)/2;
69 break;
70
71 case DRM_MODE_SCALE_ASPECT:
72 /* Scale but preserve the aspect ratio */
73 {
Daniel Vetter9084e7d2013-09-16 23:43:45 +020074 u32 scaled_width = adjusted_mode->hdisplay
75 * pipe_config->pipe_src_h;
76 u32 scaled_height = pipe_config->pipe_src_w
77 * adjusted_mode->vdisplay;
Chris Wilson1d8e1c72010-08-07 11:01:28 +010078 if (scaled_width > scaled_height) { /* pillar */
Ville Syrjälä37327ab2013-09-04 18:25:28 +030079 width = scaled_height / pipe_config->pipe_src_h;
Adam Jackson302983e2011-07-13 16:32:32 -040080 if (width & 1)
Akshay Joshi0206e352011-08-16 15:34:10 -040081 width++;
Chris Wilson1d8e1c72010-08-07 11:01:28 +010082 x = (adjusted_mode->hdisplay - width + 1) / 2;
83 y = 0;
84 height = adjusted_mode->vdisplay;
85 } else if (scaled_width < scaled_height) { /* letter */
Ville Syrjälä37327ab2013-09-04 18:25:28 +030086 height = scaled_width / pipe_config->pipe_src_w;
Adam Jackson302983e2011-07-13 16:32:32 -040087 if (height & 1)
88 height++;
Chris Wilson1d8e1c72010-08-07 11:01:28 +010089 y = (adjusted_mode->vdisplay - height + 1) / 2;
90 x = 0;
91 width = adjusted_mode->hdisplay;
92 } else {
93 x = y = 0;
94 width = adjusted_mode->hdisplay;
95 height = adjusted_mode->vdisplay;
96 }
97 }
98 break;
99
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100100 case DRM_MODE_SCALE_FULLSCREEN:
101 x = y = 0;
102 width = adjusted_mode->hdisplay;
103 height = adjusted_mode->vdisplay;
104 break;
Jesse Barnesab3e67f2013-04-25 12:55:03 -0700105
106 default:
107 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
108 return;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100109 }
110
111done:
Jesse Barnesb074cec2013-04-25 12:55:02 -0700112 pipe_config->pch_pfit.pos = (x << 16) | y;
113 pipe_config->pch_pfit.size = (width << 16) | height;
Chris Wilsonfd4daa92013-08-27 17:04:17 +0100114 pipe_config->pch_pfit.enabled = pipe_config->pch_pfit.size != 0;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100115}
Chris Wilsona9573552010-08-22 13:18:16 +0100116
Jesse Barnes2dd24552013-04-25 12:55:01 -0700117static void
118centre_horizontally(struct drm_display_mode *mode,
119 int width)
120{
121 u32 border, sync_pos, blank_width, sync_width;
122
123 /* keep the hsync and hblank widths constant */
124 sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
125 blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
126 sync_pos = (blank_width - sync_width + 1) / 2;
127
128 border = (mode->hdisplay - width + 1) / 2;
129 border += border & 1; /* make the border even */
130
131 mode->crtc_hdisplay = width;
132 mode->crtc_hblank_start = width + border;
133 mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
134
135 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
136 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
137}
138
139static void
140centre_vertically(struct drm_display_mode *mode,
141 int height)
142{
143 u32 border, sync_pos, blank_width, sync_width;
144
145 /* keep the vsync and vblank widths constant */
146 sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
147 blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
148 sync_pos = (blank_width - sync_width + 1) / 2;
149
150 border = (mode->vdisplay - height + 1) / 2;
151
152 mode->crtc_vdisplay = height;
153 mode->crtc_vblank_start = height + border;
154 mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
155
156 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
157 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
158}
159
160static inline u32 panel_fitter_scaling(u32 source, u32 target)
161{
162 /*
163 * Floating point operation is not supported. So the FACTOR
164 * is defined, which can avoid the floating point computation
165 * when calculating the panel ratio.
166 */
167#define ACCURACY 12
168#define FACTOR (1 << ACCURACY)
169 u32 ratio = source * FACTOR / target;
170 return (FACTOR * ratio + FACTOR/2) / FACTOR;
171}
172
Daniel Vetter9084e7d2013-09-16 23:43:45 +0200173static void i965_scale_aspect(struct intel_crtc_config *pipe_config,
174 u32 *pfit_control)
175{
176 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
177 u32 scaled_width = adjusted_mode->hdisplay *
178 pipe_config->pipe_src_h;
179 u32 scaled_height = pipe_config->pipe_src_w *
180 adjusted_mode->vdisplay;
181
182 /* 965+ is easy, it does everything in hw */
183 if (scaled_width > scaled_height)
184 *pfit_control |= PFIT_ENABLE |
185 PFIT_SCALING_PILLAR;
186 else if (scaled_width < scaled_height)
187 *pfit_control |= PFIT_ENABLE |
188 PFIT_SCALING_LETTER;
189 else if (adjusted_mode->hdisplay != pipe_config->pipe_src_w)
190 *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
191}
192
193static void i9xx_scale_aspect(struct intel_crtc_config *pipe_config,
194 u32 *pfit_control, u32 *pfit_pgm_ratios,
195 u32 *border)
196{
197 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
198 u32 scaled_width = adjusted_mode->hdisplay *
199 pipe_config->pipe_src_h;
200 u32 scaled_height = pipe_config->pipe_src_w *
201 adjusted_mode->vdisplay;
202 u32 bits;
203
204 /*
205 * For earlier chips we have to calculate the scaling
206 * ratio by hand and program it into the
207 * PFIT_PGM_RATIO register
208 */
209 if (scaled_width > scaled_height) { /* pillar */
210 centre_horizontally(adjusted_mode,
211 scaled_height /
212 pipe_config->pipe_src_h);
213
214 *border = LVDS_BORDER_ENABLE;
215 if (pipe_config->pipe_src_h != adjusted_mode->vdisplay) {
216 bits = panel_fitter_scaling(pipe_config->pipe_src_h,
217 adjusted_mode->vdisplay);
218
219 *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
220 bits << PFIT_VERT_SCALE_SHIFT);
221 *pfit_control |= (PFIT_ENABLE |
222 VERT_INTERP_BILINEAR |
223 HORIZ_INTERP_BILINEAR);
224 }
225 } else if (scaled_width < scaled_height) { /* letter */
226 centre_vertically(adjusted_mode,
227 scaled_width /
228 pipe_config->pipe_src_w);
229
230 *border = LVDS_BORDER_ENABLE;
231 if (pipe_config->pipe_src_w != adjusted_mode->hdisplay) {
232 bits = panel_fitter_scaling(pipe_config->pipe_src_w,
233 adjusted_mode->hdisplay);
234
235 *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
236 bits << PFIT_VERT_SCALE_SHIFT);
237 *pfit_control |= (PFIT_ENABLE |
238 VERT_INTERP_BILINEAR |
239 HORIZ_INTERP_BILINEAR);
240 }
241 } else {
242 /* Aspects match, Let hw scale both directions */
243 *pfit_control |= (PFIT_ENABLE |
244 VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
245 VERT_INTERP_BILINEAR |
246 HORIZ_INTERP_BILINEAR);
247 }
248}
249
Jesse Barnes2dd24552013-04-25 12:55:01 -0700250void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc,
251 struct intel_crtc_config *pipe_config,
252 int fitting_mode)
253{
254 struct drm_device *dev = intel_crtc->base.dev;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700255 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300256 struct drm_display_mode *adjusted_mode;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700257
Jesse Barnes2dd24552013-04-25 12:55:01 -0700258 adjusted_mode = &pipe_config->adjusted_mode;
259
260 /* Native modes don't need fitting */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300261 if (adjusted_mode->hdisplay == pipe_config->pipe_src_w &&
262 adjusted_mode->vdisplay == pipe_config->pipe_src_h)
Jesse Barnes2dd24552013-04-25 12:55:01 -0700263 goto out;
264
265 switch (fitting_mode) {
266 case DRM_MODE_SCALE_CENTER:
267 /*
268 * For centered modes, we have to calculate border widths &
269 * heights and modify the values programmed into the CRTC.
270 */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300271 centre_horizontally(adjusted_mode, pipe_config->pipe_src_w);
272 centre_vertically(adjusted_mode, pipe_config->pipe_src_h);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700273 border = LVDS_BORDER_ENABLE;
274 break;
275 case DRM_MODE_SCALE_ASPECT:
276 /* Scale but preserve the aspect ratio */
Daniel Vetter9084e7d2013-09-16 23:43:45 +0200277 if (INTEL_INFO(dev)->gen >= 4)
278 i965_scale_aspect(pipe_config, &pfit_control);
279 else
280 i9xx_scale_aspect(pipe_config, &pfit_control,
281 &pfit_pgm_ratios, &border);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700282 break;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700283 case DRM_MODE_SCALE_FULLSCREEN:
284 /*
285 * Full scaling, even if it changes the aspect ratio.
286 * Fortunately this is all done for us in hw.
287 */
Ville Syrjälä37327ab2013-09-04 18:25:28 +0300288 if (pipe_config->pipe_src_h != adjusted_mode->vdisplay ||
289 pipe_config->pipe_src_w != adjusted_mode->hdisplay) {
Jesse Barnes2dd24552013-04-25 12:55:01 -0700290 pfit_control |= PFIT_ENABLE;
291 if (INTEL_INFO(dev)->gen >= 4)
292 pfit_control |= PFIT_SCALING_AUTO;
293 else
294 pfit_control |= (VERT_AUTO_SCALE |
295 VERT_INTERP_BILINEAR |
296 HORIZ_AUTO_SCALE |
297 HORIZ_INTERP_BILINEAR);
298 }
299 break;
Jesse Barnesab3e67f2013-04-25 12:55:03 -0700300 default:
301 WARN(1, "bad panel fit mode: %d\n", fitting_mode);
302 return;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700303 }
304
305 /* 965+ wants fuzzy fitting */
306 /* FIXME: handle multiple panels by failing gracefully */
307 if (INTEL_INFO(dev)->gen >= 4)
308 pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
309 PFIT_FILTER_FUZZY);
310
311out:
312 if ((pfit_control & PFIT_ENABLE) == 0) {
313 pfit_control = 0;
314 pfit_pgm_ratios = 0;
315 }
316
317 /* Make sure pre-965 set dither correctly for 18bpp panels. */
318 if (INTEL_INFO(dev)->gen < 4 && pipe_config->pipe_bpp == 18)
319 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
320
Daniel Vetter2deefda2013-04-25 22:52:17 +0200321 pipe_config->gmch_pfit.control = pfit_control;
322 pipe_config->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
Daniel Vetter68fc8742013-04-25 22:52:16 +0200323 pipe_config->gmch_pfit.lvds_border_bits = border;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700324}
325
Jani Nikula7bd688c2013-11-08 16:48:56 +0200326static u32 intel_panel_compute_brightness(struct intel_connector *connector,
327 u32 val)
Carsten Emde7bd90902012-03-15 15:56:25 +0100328{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200329 struct drm_device *dev = connector->base.dev;
Carsten Emde4dca20e2012-03-15 15:56:26 +0100330 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200331 struct intel_panel *panel = &connector->panel;
332
333 WARN_ON(panel->backlight.max == 0);
Carsten Emde4dca20e2012-03-15 15:56:26 +0100334
Jani Nikulad330a952014-01-21 11:24:25 +0200335 if (i915.invert_brightness < 0)
Carsten Emde4dca20e2012-03-15 15:56:26 +0100336 return val;
337
Jani Nikulad330a952014-01-21 11:24:25 +0200338 if (i915.invert_brightness > 0 ||
Jani Nikulad6540632013-04-12 15:18:36 +0300339 dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) {
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200340 return panel->backlight.max - val;
Jani Nikulad6540632013-04-12 15:18:36 +0300341 }
Carsten Emde7bd90902012-03-15 15:56:25 +0100342
343 return val;
344}
345
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100346static u32 bdw_get_backlight(struct intel_connector *connector)
Chris Wilsona9573552010-08-22 13:18:16 +0100347{
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100348 struct drm_device *dev = connector->base.dev;
349 struct drm_i915_private *dev_priv = dev->dev_private;
350
351 return I915_READ(BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK;
352}
353
Jani Nikula7bd688c2013-11-08 16:48:56 +0200354static u32 pch_get_backlight(struct intel_connector *connector)
Chris Wilsona9573552010-08-22 13:18:16 +0100355{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200356 struct drm_device *dev = connector->base.dev;
357 struct drm_i915_private *dev_priv = dev->dev_private;
358
359 return I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
360}
361
362static u32 i9xx_get_backlight(struct intel_connector *connector)
363{
364 struct drm_device *dev = connector->base.dev;
365 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula636baeb2013-11-08 16:49:02 +0200366 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200367 u32 val;
368
369 val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
370 if (INTEL_INFO(dev)->gen < 4)
371 val >>= 1;
372
Jani Nikula636baeb2013-11-08 16:49:02 +0200373 if (panel->backlight.combination_mode) {
Jani Nikula7bd688c2013-11-08 16:48:56 +0200374 u8 lbpc;
375
376 pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc);
377 val *= lbpc;
378 }
379
380 return val;
381}
382
383static u32 _vlv_get_backlight(struct drm_device *dev, enum pipe pipe)
384{
385 struct drm_i915_private *dev_priv = dev->dev_private;
386
387 return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK;
388}
389
390static u32 vlv_get_backlight(struct intel_connector *connector)
391{
392 struct drm_device *dev = connector->base.dev;
393 enum pipe pipe = intel_get_pipe_from_connector(connector);
394
395 return _vlv_get_backlight(dev, pipe);
396}
397
398static u32 intel_panel_get_backlight(struct intel_connector *connector)
399{
400 struct drm_device *dev = connector->base.dev;
Chris Wilsona9573552010-08-22 13:18:16 +0100401 struct drm_i915_private *dev_priv = dev->dev_private;
402 u32 val;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300403 unsigned long flags;
404
Jani Nikula58c68772013-11-08 16:48:54 +0200405 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilsona9573552010-08-22 13:18:16 +0100406
Jani Nikula7bd688c2013-11-08 16:48:56 +0200407 val = dev_priv->display.get_backlight(connector);
408 val = intel_panel_compute_brightness(connector, val);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300409
Jani Nikula58c68772013-11-08 16:48:54 +0200410 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300411
Chris Wilsona9573552010-08-22 13:18:16 +0100412 DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val);
413 return val;
414}
415
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100416static void bdw_set_backlight(struct intel_connector *connector, u32 level)
Ben Widawskyf8e10062013-11-11 11:12:57 +0200417{
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100418 struct drm_device *dev = connector->base.dev;
Ben Widawskyf8e10062013-11-11 11:12:57 +0200419 struct drm_i915_private *dev_priv = dev->dev_private;
420 u32 val = I915_READ(BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK;
421 I915_WRITE(BLC_PWM_PCH_CTL2, val | level);
422}
423
Jani Nikula7bd688c2013-11-08 16:48:56 +0200424static void pch_set_backlight(struct intel_connector *connector, u32 level)
Chris Wilsona9573552010-08-22 13:18:16 +0100425{
Jani Nikula7bd688c2013-11-08 16:48:56 +0200426 struct drm_device *dev = connector->base.dev;
Chris Wilsona9573552010-08-22 13:18:16 +0100427 struct drm_i915_private *dev_priv = dev->dev_private;
428 u32 tmp;
429
Jani Nikula7bd688c2013-11-08 16:48:56 +0200430 tmp = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
431 I915_WRITE(BLC_PWM_CPU_CTL, tmp | level);
432}
Chris Wilsona9573552010-08-22 13:18:16 +0100433
Jani Nikula7bd688c2013-11-08 16:48:56 +0200434static void i9xx_set_backlight(struct intel_connector *connector, u32 level)
435{
436 struct drm_device *dev = connector->base.dev;
437 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200438 struct intel_panel *panel = &connector->panel;
Jani Nikulab329b322013-11-08 16:48:57 +0200439 u32 tmp, mask;
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100440
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200441 WARN_ON(panel->backlight.max == 0);
442
Jani Nikula636baeb2013-11-08 16:49:02 +0200443 if (panel->backlight.combination_mode) {
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100444 u8 lbpc;
445
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200446 lbpc = level * 0xfe / panel->backlight.max + 1;
Takashi Iwaiba3820a2011-03-10 14:02:12 +0100447 level /= lbpc;
448 pci_write_config_byte(dev->pdev, PCI_LBPC, lbpc);
449 }
450
Jani Nikulab329b322013-11-08 16:48:57 +0200451 if (IS_GEN4(dev)) {
452 mask = BACKLIGHT_DUTY_CYCLE_MASK;
453 } else {
Chris Wilsona9573552010-08-22 13:18:16 +0100454 level <<= 1;
Jani Nikulab329b322013-11-08 16:48:57 +0200455 mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV;
456 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200457
Jani Nikulab329b322013-11-08 16:48:57 +0200458 tmp = I915_READ(BLC_PWM_CTL) & ~mask;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200459 I915_WRITE(BLC_PWM_CTL, tmp | level);
460}
461
462static void vlv_set_backlight(struct intel_connector *connector, u32 level)
463{
464 struct drm_device *dev = connector->base.dev;
465 struct drm_i915_private *dev_priv = dev->dev_private;
466 enum pipe pipe = intel_get_pipe_from_connector(connector);
467 u32 tmp;
468
469 tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK;
470 I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
471}
472
473static void
474intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
475{
476 struct drm_device *dev = connector->base.dev;
477 struct drm_i915_private *dev_priv = dev->dev_private;
478
479 DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level);
480
481 level = intel_panel_compute_brightness(connector, level);
482 dev_priv->display.set_backlight(connector, level);
Chris Wilsona9573552010-08-22 13:18:16 +0100483}
Chris Wilson47356eb2011-01-11 17:06:04 +0000484
Jani Nikulad6540632013-04-12 15:18:36 +0300485/* set backlight brightness to level in range [0..max] */
Jesse Barnes752aa882013-10-31 18:55:49 +0200486void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
487 u32 max)
Takashi Iwaif52c6192011-10-14 11:45:40 +0200488{
Jesse Barnes752aa882013-10-31 18:55:49 +0200489 struct drm_device *dev = connector->base.dev;
Takashi Iwaif52c6192011-10-14 11:45:40 +0200490 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200491 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200492 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulad6540632013-04-12 15:18:36 +0300493 u32 freq;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300494 unsigned long flags;
495
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200496 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200497 return;
498
Jani Nikula58c68772013-11-08 16:48:54 +0200499 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Jani Nikulad6540632013-04-12 15:18:36 +0300500
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200501 WARN_ON(panel->backlight.max == 0);
Jani Nikulad6540632013-04-12 15:18:36 +0300502
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200503 /* scale to hardware max, but be careful to not overflow */
504 freq = panel->backlight.max;
Aaron Lu22505b82013-08-02 09:16:03 +0800505 if (freq < max)
506 level = level * freq / max;
507 else
508 level = freq / max * level;
Takashi Iwaif52c6192011-10-14 11:45:40 +0200509
Jani Nikula58c68772013-11-08 16:48:54 +0200510 panel->backlight.level = level;
511 if (panel->backlight.device)
512 panel->backlight.device->props.brightness = level;
Jani Nikulab6b3ba52013-03-12 11:44:15 +0200513
Jani Nikula58c68772013-11-08 16:48:54 +0200514 if (panel->backlight.enabled)
Jani Nikula7bd688c2013-11-08 16:48:56 +0200515 intel_panel_actually_set_backlight(connector, level);
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200516
Jani Nikula58c68772013-11-08 16:48:54 +0200517 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Takashi Iwaif52c6192011-10-14 11:45:40 +0200518}
519
Jani Nikula7bd688c2013-11-08 16:48:56 +0200520static void pch_disable_backlight(struct intel_connector *connector)
521{
522 struct drm_device *dev = connector->base.dev;
523 struct drm_i915_private *dev_priv = dev->dev_private;
524 u32 tmp;
525
Jani Nikula3bd712e2013-11-08 16:48:59 +0200526 intel_panel_actually_set_backlight(connector, 0);
527
Jani Nikula7bd688c2013-11-08 16:48:56 +0200528 tmp = I915_READ(BLC_PWM_CPU_CTL2);
529 I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE);
530
531 tmp = I915_READ(BLC_PWM_PCH_CTL1);
532 I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE);
533}
534
Jani Nikula3bd712e2013-11-08 16:48:59 +0200535static void i9xx_disable_backlight(struct intel_connector *connector)
536{
537 intel_panel_actually_set_backlight(connector, 0);
538}
539
Jani Nikula7bd688c2013-11-08 16:48:56 +0200540static void i965_disable_backlight(struct intel_connector *connector)
541{
542 struct drm_device *dev = connector->base.dev;
543 struct drm_i915_private *dev_priv = dev->dev_private;
544 u32 tmp;
545
Jani Nikula3bd712e2013-11-08 16:48:59 +0200546 intel_panel_actually_set_backlight(connector, 0);
547
Jani Nikula7bd688c2013-11-08 16:48:56 +0200548 tmp = I915_READ(BLC_PWM_CTL2);
549 I915_WRITE(BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE);
550}
551
552static void vlv_disable_backlight(struct intel_connector *connector)
553{
554 struct drm_device *dev = connector->base.dev;
555 struct drm_i915_private *dev_priv = dev->dev_private;
556 enum pipe pipe = intel_get_pipe_from_connector(connector);
557 u32 tmp;
558
Jani Nikula3bd712e2013-11-08 16:48:59 +0200559 intel_panel_actually_set_backlight(connector, 0);
560
Jani Nikula7bd688c2013-11-08 16:48:56 +0200561 tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe));
562 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE);
563}
564
Jesse Barnes752aa882013-10-31 18:55:49 +0200565void intel_panel_disable_backlight(struct intel_connector *connector)
Chris Wilson47356eb2011-01-11 17:06:04 +0000566{
Jesse Barnes752aa882013-10-31 18:55:49 +0200567 struct drm_device *dev = connector->base.dev;
Chris Wilson47356eb2011-01-11 17:06:04 +0000568 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200569 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200570 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300571 unsigned long flags;
572
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200573 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200574 return;
575
Jani Nikula3f577572013-07-25 14:31:30 +0300576 /*
577 * Do not disable backlight on the vgaswitcheroo path. When switching
578 * away from i915, the other client may depend on i915 to handle the
579 * backlight. This will leave the backlight on unnecessarily when
580 * another client is not activated.
581 */
582 if (dev->switch_power_state == DRM_SWITCH_POWER_CHANGING) {
583 DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
584 return;
585 }
586
Jani Nikula58c68772013-11-08 16:48:54 +0200587 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000588
Jani Nikula58c68772013-11-08 16:48:54 +0200589 panel->backlight.enabled = false;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200590 dev_priv->display.disable_backlight(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300591
Jani Nikula58c68772013-11-08 16:48:54 +0200592 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000593}
594
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100595static void bdw_enable_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 struct intel_panel *panel = &connector->panel;
600 u32 pch_ctl1, pch_ctl2;
Chris Wilson47356eb2011-01-11 17:06:04 +0000601
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100602 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
603 if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
604 DRM_DEBUG_KMS("pch backlight already enabled\n");
605 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
606 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
Chris Wilson47356eb2011-01-11 17:06:04 +0000607 }
608
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100609 pch_ctl2 = panel->backlight.max << 16;
610 I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
611
612 pch_ctl1 = 0;
613 if (panel->backlight.active_low_pwm)
614 pch_ctl1 |= BLM_PCH_POLARITY;
615
616 /* BDW always uses the pch pwm controls. */
617 pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE;
618
619 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
620 POSTING_READ(BLC_PWM_PCH_CTL1);
621 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
622
623 /* This won't stick until the above enable. */
624 intel_panel_actually_set_backlight(connector, panel->backlight.level);
625}
626
Jani Nikula7bd688c2013-11-08 16:48:56 +0200627static void pch_enable_backlight(struct intel_connector *connector)
628{
629 struct drm_device *dev = connector->base.dev;
630 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200631 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200632 enum pipe pipe = intel_get_pipe_from_connector(connector);
633 enum transcoder cpu_transcoder =
634 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
Jani Nikulab35684b2013-11-14 12:13:41 +0200635 u32 cpu_ctl2, pch_ctl1, pch_ctl2;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200636
Jani Nikulab35684b2013-11-14 12:13:41 +0200637 cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
638 if (cpu_ctl2 & BLM_PWM_ENABLE) {
639 WARN(1, "cpu backlight already enabled\n");
640 cpu_ctl2 &= ~BLM_PWM_ENABLE;
641 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200642 }
Jani Nikula3bd712e2013-11-08 16:48:59 +0200643
Jani Nikulab35684b2013-11-14 12:13:41 +0200644 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
645 if (pch_ctl1 & BLM_PCH_PWM_ENABLE) {
646 DRM_DEBUG_KMS("pch backlight already enabled\n");
647 pch_ctl1 &= ~BLM_PCH_PWM_ENABLE;
648 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
649 }
650
651 if (cpu_transcoder == TRANSCODER_EDP)
652 cpu_ctl2 = BLM_TRANSCODER_EDP;
653 else
654 cpu_ctl2 = BLM_PIPE(cpu_transcoder);
655 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2);
656 POSTING_READ(BLC_PWM_CPU_CTL2);
657 I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE);
658
659 /* This won't stick until the above enable. */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200660 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikulab35684b2013-11-14 12:13:41 +0200661
662 pch_ctl2 = panel->backlight.max << 16;
663 I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2);
664
Jani Nikulab35684b2013-11-14 12:13:41 +0200665 pch_ctl1 = 0;
666 if (panel->backlight.active_low_pwm)
667 pch_ctl1 |= BLM_PCH_POLARITY;
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100668
Jani Nikulab35684b2013-11-14 12:13:41 +0200669 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1);
670 POSTING_READ(BLC_PWM_PCH_CTL1);
671 I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE);
Jani Nikula3bd712e2013-11-08 16:48:59 +0200672}
673
674static void i9xx_enable_backlight(struct intel_connector *connector)
675{
Jani Nikulab35684b2013-11-14 12:13:41 +0200676 struct drm_device *dev = connector->base.dev;
677 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200678 struct intel_panel *panel = &connector->panel;
Jani Nikulab35684b2013-11-14 12:13:41 +0200679 u32 ctl, freq;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200680
Jani Nikulab35684b2013-11-14 12:13:41 +0200681 ctl = I915_READ(BLC_PWM_CTL);
682 if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) {
683 WARN(1, "backlight already enabled\n");
684 I915_WRITE(BLC_PWM_CTL, 0);
685 }
686
687 freq = panel->backlight.max;
688 if (panel->backlight.combination_mode)
689 freq /= 0xff;
690
691 ctl = freq << 17;
Jani Nikulab6ab66a2014-02-25 13:11:47 +0200692 if (panel->backlight.combination_mode)
Jani Nikulab35684b2013-11-14 12:13:41 +0200693 ctl |= BLM_LEGACY_MODE;
694 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm)
695 ctl |= BLM_POLARITY_PNV;
696
697 I915_WRITE(BLC_PWM_CTL, ctl);
698 POSTING_READ(BLC_PWM_CTL);
699
700 /* XXX: combine this into above write? */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200701 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200702}
703
704static void i965_enable_backlight(struct intel_connector *connector)
705{
706 struct drm_device *dev = connector->base.dev;
707 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200708 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200709 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulab35684b2013-11-14 12:13:41 +0200710 u32 ctl, ctl2, freq;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200711
Jani Nikulab35684b2013-11-14 12:13:41 +0200712 ctl2 = I915_READ(BLC_PWM_CTL2);
713 if (ctl2 & BLM_PWM_ENABLE) {
714 WARN(1, "backlight already enabled\n");
715 ctl2 &= ~BLM_PWM_ENABLE;
716 I915_WRITE(BLC_PWM_CTL2, ctl2);
717 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200718
Jani Nikulab35684b2013-11-14 12:13:41 +0200719 freq = panel->backlight.max;
720 if (panel->backlight.combination_mode)
721 freq /= 0xff;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200722
Jani Nikulab35684b2013-11-14 12:13:41 +0200723 ctl = freq << 16;
724 I915_WRITE(BLC_PWM_CTL, ctl);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200725
Jani Nikulab35684b2013-11-14 12:13:41 +0200726 /* XXX: combine this into above write? */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200727 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikulab35684b2013-11-14 12:13:41 +0200728
729 ctl2 = BLM_PIPE(pipe);
730 if (panel->backlight.combination_mode)
731 ctl2 |= BLM_COMBINATION_MODE;
732 if (panel->backlight.active_low_pwm)
733 ctl2 |= BLM_POLARITY_I965;
734 I915_WRITE(BLC_PWM_CTL2, ctl2);
735 POSTING_READ(BLC_PWM_CTL2);
736 I915_WRITE(BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200737}
738
739static void vlv_enable_backlight(struct intel_connector *connector)
740{
741 struct drm_device *dev = connector->base.dev;
742 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3bd712e2013-11-08 16:48:59 +0200743 struct intel_panel *panel = &connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200744 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikulab35684b2013-11-14 12:13:41 +0200745 u32 ctl, ctl2;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200746
Jani Nikulab35684b2013-11-14 12:13:41 +0200747 ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
748 if (ctl2 & BLM_PWM_ENABLE) {
749 WARN(1, "backlight already enabled\n");
750 ctl2 &= ~BLM_PWM_ENABLE;
751 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
752 }
Jani Nikula7bd688c2013-11-08 16:48:56 +0200753
Jani Nikulab35684b2013-11-14 12:13:41 +0200754 ctl = panel->backlight.max << 16;
755 I915_WRITE(VLV_BLC_PWM_CTL(pipe), ctl);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200756
Jani Nikulab35684b2013-11-14 12:13:41 +0200757 /* XXX: combine this into above write? */
Jani Nikula3bd712e2013-11-08 16:48:59 +0200758 intel_panel_actually_set_backlight(connector, panel->backlight.level);
Jani Nikulab35684b2013-11-14 12:13:41 +0200759
760 ctl2 = 0;
761 if (panel->backlight.active_low_pwm)
762 ctl2 |= BLM_POLARITY_I965;
763 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2);
764 POSTING_READ(VLV_BLC_PWM_CTL2(pipe));
765 I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200766}
767
Jesse Barnes752aa882013-10-31 18:55:49 +0200768void intel_panel_enable_backlight(struct intel_connector *connector)
Chris Wilson47356eb2011-01-11 17:06:04 +0000769{
Jesse Barnes752aa882013-10-31 18:55:49 +0200770 struct drm_device *dev = connector->base.dev;
Chris Wilson47356eb2011-01-11 17:06:04 +0000771 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula58c68772013-11-08 16:48:54 +0200772 struct intel_panel *panel = &connector->panel;
Jesse Barnes752aa882013-10-31 18:55:49 +0200773 enum pipe pipe = intel_get_pipe_from_connector(connector);
Jani Nikula8ba2d182013-04-12 15:18:37 +0300774 unsigned long flags;
775
Ville Syrjälädc5a4362014-01-16 18:27:15 +0200776 if (!panel->backlight.present || pipe == INVALID_PIPE)
Jesse Barnes752aa882013-10-31 18:55:49 +0200777 return;
778
Damien Lespiau6f2bcce2013-10-16 12:29:54 +0100779 DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
Chris Wilson540b5d02013-10-13 12:56:31 +0100780
Jani Nikula58c68772013-11-08 16:48:54 +0200781 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000782
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200783 WARN_ON(panel->backlight.max == 0);
784
Jani Nikula58c68772013-11-08 16:48:54 +0200785 if (panel->backlight.level == 0) {
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200786 panel->backlight.level = panel->backlight.max;
Jani Nikula58c68772013-11-08 16:48:54 +0200787 if (panel->backlight.device)
788 panel->backlight.device->props.brightness =
789 panel->backlight.level;
Jani Nikulab6b3ba52013-03-12 11:44:15 +0200790 }
Chris Wilson47356eb2011-01-11 17:06:04 +0000791
Jani Nikula3bd712e2013-11-08 16:48:59 +0200792 dev_priv->display.enable_backlight(connector);
Jani Nikula58c68772013-11-08 16:48:54 +0200793 panel->backlight.enabled = true;
Jani Nikula8ba2d182013-04-12 15:18:37 +0300794
Jani Nikula58c68772013-11-08 16:48:54 +0200795 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Chris Wilson47356eb2011-01-11 17:06:04 +0000796}
797
Chris Wilsonfe16d942011-02-12 10:29:38 +0000798enum drm_connector_status
799intel_panel_detect(struct drm_device *dev)
800{
801 struct drm_i915_private *dev_priv = dev->dev_private;
802
803 /* Assume that the BIOS does not lie through the OpRegion... */
Jani Nikulad330a952014-01-21 11:24:25 +0200804 if (!i915.panel_ignore_lid && dev_priv->opregion.lid_state) {
Chris Wilsonfe16d942011-02-12 10:29:38 +0000805 return ioread32(dev_priv->opregion.lid_state) & 0x1 ?
806 connector_status_connected :
807 connector_status_disconnected;
Daniel Vettera7269152012-11-20 14:50:08 +0100808 }
Chris Wilsonfe16d942011-02-12 10:29:38 +0000809
Jani Nikulad330a952014-01-21 11:24:25 +0200810 switch (i915.panel_ignore_lid) {
Daniel Vettera7269152012-11-20 14:50:08 +0100811 case -2:
812 return connector_status_connected;
813 case -1:
814 return connector_status_disconnected;
815 default:
816 return connector_status_unknown;
817 }
Chris Wilsonfe16d942011-02-12 10:29:38 +0000818}
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200819
Jani Nikula912e8b12013-09-18 17:19:45 +0300820#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
Jani Nikuladb31af12013-11-08 16:48:53 +0200821static int intel_backlight_device_update_status(struct backlight_device *bd)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200822{
Jesse Barnes752aa882013-10-31 18:55:49 +0200823 struct intel_connector *connector = bl_get_data(bd);
824 struct drm_device *dev = connector->base.dev;
825
826 mutex_lock(&dev->mode_config.mutex);
Chris Wilson540b5d02013-10-13 12:56:31 +0100827 DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n",
828 bd->props.brightness, bd->props.max_brightness);
Jesse Barnes752aa882013-10-31 18:55:49 +0200829 intel_panel_set_backlight(connector, bd->props.brightness,
Jani Nikulad6540632013-04-12 15:18:36 +0300830 bd->props.max_brightness);
Jesse Barnes752aa882013-10-31 18:55:49 +0200831 mutex_unlock(&dev->mode_config.mutex);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200832 return 0;
833}
834
Jani Nikuladb31af12013-11-08 16:48:53 +0200835static int intel_backlight_device_get_brightness(struct backlight_device *bd)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200836{
Jesse Barnes752aa882013-10-31 18:55:49 +0200837 struct intel_connector *connector = bl_get_data(bd);
838 struct drm_device *dev = connector->base.dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200839 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200840 int ret;
Jesse Barnes752aa882013-10-31 18:55:49 +0200841
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200842 intel_runtime_pm_get(dev_priv);
Jesse Barnes752aa882013-10-31 18:55:49 +0200843 mutex_lock(&dev->mode_config.mutex);
Jani Nikula7bd688c2013-11-08 16:48:56 +0200844 ret = intel_panel_get_backlight(connector);
Jesse Barnes752aa882013-10-31 18:55:49 +0200845 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200846 intel_runtime_pm_put(dev_priv);
Jesse Barnes752aa882013-10-31 18:55:49 +0200847
Jani Nikula7bd688c2013-11-08 16:48:56 +0200848 return ret;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200849}
850
Jani Nikuladb31af12013-11-08 16:48:53 +0200851static const struct backlight_ops intel_backlight_device_ops = {
852 .update_status = intel_backlight_device_update_status,
853 .get_brightness = intel_backlight_device_get_brightness,
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200854};
855
Jani Nikuladb31af12013-11-08 16:48:53 +0200856static int intel_backlight_device_register(struct intel_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200857{
Jani Nikula58c68772013-11-08 16:48:54 +0200858 struct intel_panel *panel = &connector->panel;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200859 struct backlight_properties props;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200860
Jani Nikula58c68772013-11-08 16:48:54 +0200861 if (WARN_ON(panel->backlight.device))
Jani Nikuladc652f92013-04-12 15:18:38 +0300862 return -ENODEV;
863
Jani Nikula7bd688c2013-11-08 16:48:56 +0200864 BUG_ON(panel->backlight.max == 0);
865
Corentin Charyaf437cf2012-05-22 10:29:46 +0100866 memset(&props, 0, sizeof(props));
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200867 props.type = BACKLIGHT_RAW;
Jani Nikula58c68772013-11-08 16:48:54 +0200868 props.brightness = panel->backlight.level;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200869 props.max_brightness = panel->backlight.max;
Jani Nikula58c68772013-11-08 16:48:54 +0200870
871 /*
872 * Note: using the same name independent of the connector prevents
873 * registration of multiple backlight devices in the driver.
874 */
875 panel->backlight.device =
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200876 backlight_device_register("intel_backlight",
Jani Nikuladb31af12013-11-08 16:48:53 +0200877 connector->base.kdev,
878 connector,
879 &intel_backlight_device_ops, &props);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200880
Jani Nikula58c68772013-11-08 16:48:54 +0200881 if (IS_ERR(panel->backlight.device)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200882 DRM_ERROR("Failed to register backlight: %ld\n",
Jani Nikula58c68772013-11-08 16:48:54 +0200883 PTR_ERR(panel->backlight.device));
884 panel->backlight.device = NULL;
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200885 return -ENODEV;
886 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200887 return 0;
888}
889
Jani Nikuladb31af12013-11-08 16:48:53 +0200890static void intel_backlight_device_unregister(struct intel_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200891{
Jani Nikula58c68772013-11-08 16:48:54 +0200892 struct intel_panel *panel = &connector->panel;
893
894 if (panel->backlight.device) {
895 backlight_device_unregister(panel->backlight.device);
896 panel->backlight.device = NULL;
Jani Nikuladc652f92013-04-12 15:18:38 +0300897 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +0200898}
Jani Nikuladb31af12013-11-08 16:48:53 +0200899#else /* CONFIG_BACKLIGHT_CLASS_DEVICE */
900static int intel_backlight_device_register(struct intel_connector *connector)
901{
902 return 0;
903}
904static void intel_backlight_device_unregister(struct intel_connector *connector)
905{
906}
907#endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
908
Jani Nikulaf91c15e2013-11-08 16:49:00 +0200909/*
910 * Note: The setup hooks can't assume pipe is set!
911 *
912 * XXX: Query mode clock or hardware clock and program PWM modulation frequency
913 * appropriately when it's 0. Use VBT and/or sane defaults.
914 */
Daniel Vetter96ab4c72013-11-14 15:17:41 +0100915static int bdw_setup_backlight(struct intel_connector *connector)
916{
917 struct drm_device *dev = connector->base.dev;
918 struct drm_i915_private *dev_priv = dev->dev_private;
919 struct intel_panel *panel = &connector->panel;
920 u32 pch_ctl1, pch_ctl2, val;
921
922 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
923 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
924
925 pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
926 panel->backlight.max = pch_ctl2 >> 16;
927 if (!panel->backlight.max)
928 return -ENODEV;
929
930 val = bdw_get_backlight(connector);
931 panel->backlight.level = intel_panel_compute_brightness(connector, val);
932
933 panel->backlight.enabled = (pch_ctl1 & BLM_PCH_PWM_ENABLE) &&
934 panel->backlight.level != 0;
935
936 return 0;
937}
938
Jani Nikula7bd688c2013-11-08 16:48:56 +0200939static int pch_setup_backlight(struct intel_connector *connector)
940{
Jani Nikula636baeb2013-11-08 16:49:02 +0200941 struct drm_device *dev = connector->base.dev;
942 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200943 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +0200944 u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200945
Jani Nikula636baeb2013-11-08 16:49:02 +0200946 pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
947 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
948
949 pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
950 panel->backlight.max = pch_ctl2 >> 16;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200951 if (!panel->backlight.max)
952 return -ENODEV;
953
954 val = pch_get_backlight(connector);
955 panel->backlight.level = intel_panel_compute_brightness(connector, val);
956
Jani Nikula636baeb2013-11-08 16:49:02 +0200957 cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
958 panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) &&
959 (pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0;
960
Jani Nikula7bd688c2013-11-08 16:48:56 +0200961 return 0;
962}
963
964static int i9xx_setup_backlight(struct intel_connector *connector)
965{
Jani Nikula636baeb2013-11-08 16:49:02 +0200966 struct drm_device *dev = connector->base.dev;
967 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200968 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +0200969 u32 ctl, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200970
Jani Nikula636baeb2013-11-08 16:49:02 +0200971 ctl = I915_READ(BLC_PWM_CTL);
972
Jani Nikulab6ab66a2014-02-25 13:11:47 +0200973 if (IS_GEN2(dev) || IS_I915GM(dev) || IS_I945GM(dev))
Jani Nikula636baeb2013-11-08 16:49:02 +0200974 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
975
976 if (IS_PINEVIEW(dev))
977 panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV;
978
979 panel->backlight.max = ctl >> 17;
980 if (panel->backlight.combination_mode)
981 panel->backlight.max *= 0xff;
982
Jani Nikula7bd688c2013-11-08 16:48:56 +0200983 if (!panel->backlight.max)
984 return -ENODEV;
985
986 val = i9xx_get_backlight(connector);
987 panel->backlight.level = intel_panel_compute_brightness(connector, val);
988
Jani Nikula636baeb2013-11-08 16:49:02 +0200989 panel->backlight.enabled = panel->backlight.level != 0;
990
Jani Nikula7bd688c2013-11-08 16:48:56 +0200991 return 0;
992}
993
994static int i965_setup_backlight(struct intel_connector *connector)
995{
Jani Nikula636baeb2013-11-08 16:49:02 +0200996 struct drm_device *dev = connector->base.dev;
997 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7bd688c2013-11-08 16:48:56 +0200998 struct intel_panel *panel = &connector->panel;
Jani Nikula636baeb2013-11-08 16:49:02 +0200999 u32 ctl, ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001000
Jani Nikula636baeb2013-11-08 16:49:02 +02001001 ctl2 = I915_READ(BLC_PWM_CTL2);
1002 panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE;
1003 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1004
1005 ctl = I915_READ(BLC_PWM_CTL);
1006 panel->backlight.max = ctl >> 16;
1007 if (panel->backlight.combination_mode)
1008 panel->backlight.max *= 0xff;
1009
Jani Nikula7bd688c2013-11-08 16:48:56 +02001010 if (!panel->backlight.max)
1011 return -ENODEV;
1012
1013 val = i9xx_get_backlight(connector);
1014 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1015
Jani Nikula636baeb2013-11-08 16:49:02 +02001016 panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
1017 panel->backlight.level != 0;
1018
Jani Nikula7bd688c2013-11-08 16:48:56 +02001019 return 0;
1020}
1021
1022static int vlv_setup_backlight(struct intel_connector *connector)
1023{
1024 struct drm_device *dev = connector->base.dev;
1025 struct drm_i915_private *dev_priv = dev->dev_private;
1026 struct intel_panel *panel = &connector->panel;
1027 enum pipe pipe;
Jani Nikula636baeb2013-11-08 16:49:02 +02001028 u32 ctl, ctl2, val;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001029
1030 for_each_pipe(pipe) {
1031 u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(pipe));
1032
1033 /* Skip if the modulation freq is already set */
1034 if (cur_val & ~BACKLIGHT_DUTY_CYCLE_MASK)
1035 continue;
1036
1037 cur_val &= BACKLIGHT_DUTY_CYCLE_MASK;
1038 I915_WRITE(VLV_BLC_PWM_CTL(pipe), (0xf42 << 16) |
1039 cur_val);
1040 }
1041
Jani Nikula636baeb2013-11-08 16:49:02 +02001042 ctl2 = I915_READ(VLV_BLC_PWM_CTL2(PIPE_A));
1043 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1044
1045 ctl = I915_READ(VLV_BLC_PWM_CTL(PIPE_A));
1046 panel->backlight.max = ctl >> 16;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001047 if (!panel->backlight.max)
1048 return -ENODEV;
1049
1050 val = _vlv_get_backlight(dev, PIPE_A);
1051 panel->backlight.level = intel_panel_compute_brightness(connector, val);
1052
Jani Nikula636baeb2013-11-08 16:49:02 +02001053 panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
1054 panel->backlight.level != 0;
1055
Jani Nikula7bd688c2013-11-08 16:48:56 +02001056 return 0;
1057}
1058
Jani Nikula0657b6b2012-10-19 14:51:46 +03001059int intel_panel_setup_backlight(struct drm_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001060{
Jani Nikuladb31af12013-11-08 16:48:53 +02001061 struct drm_device *dev = connector->dev;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001062 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikuladb31af12013-11-08 16:48:53 +02001063 struct intel_connector *intel_connector = to_intel_connector(connector);
Jani Nikula58c68772013-11-08 16:48:54 +02001064 struct intel_panel *panel = &intel_connector->panel;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001065 unsigned long flags;
1066 int ret;
Jani Nikuladb31af12013-11-08 16:48:53 +02001067
Jani Nikulac6759492014-04-09 11:31:37 +03001068 if (!dev_priv->vbt.backlight.present) {
1069 DRM_DEBUG_KMS("native backlight control not available per VBT\n");
1070 return 0;
1071 }
1072
Jani Nikula7bd688c2013-11-08 16:48:56 +02001073 /* set level and max in panel struct */
1074 spin_lock_irqsave(&dev_priv->backlight_lock, flags);
1075 ret = dev_priv->display.setup_backlight(intel_connector);
1076 spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
Jani Nikuladb31af12013-11-08 16:48:53 +02001077
Jani Nikula7bd688c2013-11-08 16:48:56 +02001078 if (ret) {
1079 DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
1080 drm_get_connector_name(connector));
1081 return ret;
1082 }
1083
Jani Nikuladb31af12013-11-08 16:48:53 +02001084 intel_backlight_device_register(intel_connector);
1085
Jani Nikulac91c9f32013-11-08 16:48:55 +02001086 panel->backlight.present = true;
1087
Jani Nikulac445b3b2013-11-08 16:49:01 +02001088 DRM_DEBUG_KMS("backlight initialized, %s, brightness %u/%u, "
1089 "sysfs interface %sregistered\n",
1090 panel->backlight.enabled ? "enabled" : "disabled",
1091 panel->backlight.level, panel->backlight.max,
1092 panel->backlight.device ? "" : "not ");
1093
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001094 return 0;
1095}
1096
Jani Nikuladb31af12013-11-08 16:48:53 +02001097void intel_panel_destroy_backlight(struct drm_connector *connector)
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001098{
Jani Nikuladb31af12013-11-08 16:48:53 +02001099 struct intel_connector *intel_connector = to_intel_connector(connector);
Jani Nikulac91c9f32013-11-08 16:48:55 +02001100 struct intel_panel *panel = &intel_connector->panel;
Jani Nikuladb31af12013-11-08 16:48:53 +02001101
Jani Nikulac91c9f32013-11-08 16:48:55 +02001102 panel->backlight.present = false;
Jani Nikuladb31af12013-11-08 16:48:53 +02001103 intel_backlight_device_unregister(intel_connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02001104}
Jani Nikula1d508702012-10-19 14:51:49 +03001105
Vandana Kannanec9ed192013-12-10 13:37:36 +05301106/**
1107 * intel_find_panel_downclock - find the reduced downclock for LVDS in EDID
1108 * @dev: drm device
1109 * @fixed_mode : panel native mode
1110 * @connector: LVDS/eDP connector
1111 *
1112 * Return downclock_avail
1113 * Find the reduced downclock for LVDS/eDP in EDID.
1114 */
1115struct drm_display_mode *
1116intel_find_panel_downclock(struct drm_device *dev,
1117 struct drm_display_mode *fixed_mode,
1118 struct drm_connector *connector)
1119{
1120 struct drm_display_mode *scan, *tmp_mode;
1121 int temp_downclock;
1122
1123 temp_downclock = fixed_mode->clock;
1124 tmp_mode = NULL;
1125
1126 list_for_each_entry(scan, &connector->probed_modes, head) {
1127 /*
1128 * If one mode has the same resolution with the fixed_panel
1129 * mode while they have the different refresh rate, it means
1130 * that the reduced downclock is found. In such
1131 * case we can set the different FPx0/1 to dynamically select
1132 * between low and high frequency.
1133 */
1134 if (scan->hdisplay == fixed_mode->hdisplay &&
1135 scan->hsync_start == fixed_mode->hsync_start &&
1136 scan->hsync_end == fixed_mode->hsync_end &&
1137 scan->htotal == fixed_mode->htotal &&
1138 scan->vdisplay == fixed_mode->vdisplay &&
1139 scan->vsync_start == fixed_mode->vsync_start &&
1140 scan->vsync_end == fixed_mode->vsync_end &&
1141 scan->vtotal == fixed_mode->vtotal) {
1142 if (scan->clock < temp_downclock) {
1143 /*
1144 * The downclock is already found. But we
1145 * expect to find the lower downclock.
1146 */
1147 temp_downclock = scan->clock;
1148 tmp_mode = scan;
1149 }
1150 }
1151 }
1152
1153 if (temp_downclock < fixed_mode->clock)
1154 return drm_mode_duplicate(dev, tmp_mode);
1155 else
1156 return NULL;
1157}
1158
Jani Nikula7bd688c2013-11-08 16:48:56 +02001159/* Set up chip specific backlight functions */
1160void intel_panel_init_backlight_funcs(struct drm_device *dev)
1161{
1162 struct drm_i915_private *dev_priv = dev->dev_private;
1163
Daniel Vetter96ab4c72013-11-14 15:17:41 +01001164 if (IS_BROADWELL(dev)) {
1165 dev_priv->display.setup_backlight = bdw_setup_backlight;
1166 dev_priv->display.enable_backlight = bdw_enable_backlight;
1167 dev_priv->display.disable_backlight = pch_disable_backlight;
1168 dev_priv->display.set_backlight = bdw_set_backlight;
1169 dev_priv->display.get_backlight = bdw_get_backlight;
1170 } else if (HAS_PCH_SPLIT(dev)) {
Jani Nikula7bd688c2013-11-08 16:48:56 +02001171 dev_priv->display.setup_backlight = pch_setup_backlight;
1172 dev_priv->display.enable_backlight = pch_enable_backlight;
1173 dev_priv->display.disable_backlight = pch_disable_backlight;
1174 dev_priv->display.set_backlight = pch_set_backlight;
1175 dev_priv->display.get_backlight = pch_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001176 } else if (IS_VALLEYVIEW(dev)) {
1177 dev_priv->display.setup_backlight = vlv_setup_backlight;
1178 dev_priv->display.enable_backlight = vlv_enable_backlight;
1179 dev_priv->display.disable_backlight = vlv_disable_backlight;
1180 dev_priv->display.set_backlight = vlv_set_backlight;
1181 dev_priv->display.get_backlight = vlv_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001182 } else if (IS_GEN4(dev)) {
1183 dev_priv->display.setup_backlight = i965_setup_backlight;
1184 dev_priv->display.enable_backlight = i965_enable_backlight;
1185 dev_priv->display.disable_backlight = i965_disable_backlight;
1186 dev_priv->display.set_backlight = i9xx_set_backlight;
1187 dev_priv->display.get_backlight = i9xx_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001188 } else {
1189 dev_priv->display.setup_backlight = i9xx_setup_backlight;
Jani Nikula3bd712e2013-11-08 16:48:59 +02001190 dev_priv->display.enable_backlight = i9xx_enable_backlight;
1191 dev_priv->display.disable_backlight = i9xx_disable_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001192 dev_priv->display.set_backlight = i9xx_set_backlight;
1193 dev_priv->display.get_backlight = i9xx_get_backlight;
Jani Nikula7bd688c2013-11-08 16:48:56 +02001194 }
1195}
1196
Jani Nikuladd06f902012-10-19 14:51:50 +03001197int intel_panel_init(struct intel_panel *panel,
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301198 struct drm_display_mode *fixed_mode,
1199 struct drm_display_mode *downclock_mode)
Jani Nikula1d508702012-10-19 14:51:49 +03001200{
Jani Nikuladd06f902012-10-19 14:51:50 +03001201 panel->fixed_mode = fixed_mode;
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301202 panel->downclock_mode = downclock_mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03001203
Jani Nikula1d508702012-10-19 14:51:49 +03001204 return 0;
1205}
1206
1207void intel_panel_fini(struct intel_panel *panel)
1208{
Jani Nikuladd06f902012-10-19 14:51:50 +03001209 struct intel_connector *intel_connector =
1210 container_of(panel, struct intel_connector, panel);
1211
1212 if (panel->fixed_mode)
1213 drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode);
Vandana Kannanec9ed192013-12-10 13:37:36 +05301214
1215 if (panel->downclock_mode)
1216 drm_mode_destroy(intel_connector->base.dev,
1217 panel->downclock_mode);
Jani Nikula1d508702012-10-19 14:51:49 +03001218}