2 * Copyright © 2006-2009 Intel Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * Eric Anholt <eric@anholt.net>
19 * Dave Airlie <airlied@linux.ie>
20 * Jesse Barnes <jesse.barnes@intel.com>
23 #include <linux/i2c.h>
27 #include "psb_intel_bios.h"
29 #include "psb_intel_drv.h"
30 #include "psb_intel_reg.h"
31 #include "psb_powermgmt.h"
32 #include <linux/pm_runtime.h>
34 /* The max/min PWM frequency in BPCR[31:17] - */
35 /* The smallest number is 1 (not 0) that can fit in the
36 * 15-bit field of the and then*/
37 /* shifts to the left by one bit to get the actual 16-bit
38 * value that the 15-bits correspond to.*/
39 #define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF
40 #define BRIGHTNESS_MAX_LEVEL 100
43 * Sets the power state for the panel.
45 static void mrst_lvds_set_power(struct drm_device
*dev
,
46 struct psb_intel_output
*output
, bool on
)
49 DRM_DRIVER_PRIVATE_T
*dev_priv
= dev
->dev_private
;
50 PSB_DEBUG_ENTRY("\n");
52 if (!gma_power_begin(dev
, true))
56 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) |
59 pp_status
= REG_READ(PP_STATUS
);
60 } while ((pp_status
& (PP_ON
| PP_READY
)) == PP_READY
);
61 dev_priv
->is_lvds_on
= true;
63 REG_WRITE(PP_CONTROL
, REG_READ(PP_CONTROL
) &
66 pp_status
= REG_READ(PP_STATUS
);
67 } while (pp_status
& PP_ON
);
68 dev_priv
->is_lvds_on
= false;
69 pm_request_idle(&dev
->pdev
->dev
);
75 static void mrst_lvds_dpms(struct drm_encoder
*encoder
, int mode
)
77 struct drm_device
*dev
= encoder
->dev
;
78 struct psb_intel_output
*output
= enc_to_psb_intel_output(encoder
);
80 PSB_DEBUG_ENTRY("\n");
82 if (mode
== DRM_MODE_DPMS_ON
)
83 mrst_lvds_set_power(dev
, output
, true);
85 mrst_lvds_set_power(dev
, output
, false);
87 /* XXX: We never power down the LVDS pairs. */
90 static void mrst_lvds_mode_set(struct drm_encoder
*encoder
,
91 struct drm_display_mode
*mode
,
92 struct drm_display_mode
*adjusted_mode
)
94 struct psb_intel_mode_device
*mode_dev
=
95 enc_to_psb_intel_output(encoder
)->mode_dev
;
96 struct drm_device
*dev
= encoder
->dev
;
98 uint64_t v
= DRM_MODE_SCALE_FULLSCREEN
;
100 PSB_DEBUG_ENTRY("\n");
102 if (!gma_power_begin(dev
, true))
106 * The LVDS pin pair will already have been turned on in the
107 * psb_intel_crtc_mode_set since it has a large impact on the DPLL
110 lvds_port
= (REG_READ(LVDS
) &
111 (~LVDS_PIPEB_SELECT
)) |
115 if (mode_dev
->panel_wants_dither
)
116 lvds_port
|= MRST_PANEL_8TO6_DITHER_ENABLE
;
118 REG_WRITE(LVDS
, lvds_port
);
120 drm_connector_property_get_value(
121 &enc_to_psb_intel_output(encoder
)->base
,
122 dev
->mode_config
.scaling_mode_property
,
125 if (v
== DRM_MODE_SCALE_NO_SCALE
)
126 REG_WRITE(PFIT_CONTROL
, 0);
127 else if (v
== DRM_MODE_SCALE_ASPECT
) {
128 if ((mode
->vdisplay
!= adjusted_mode
->crtc_vdisplay
) ||
129 (mode
->hdisplay
!= adjusted_mode
->crtc_hdisplay
)) {
130 if ((adjusted_mode
->crtc_hdisplay
* mode
->vdisplay
) ==
131 (mode
->hdisplay
* adjusted_mode
->crtc_vdisplay
))
132 REG_WRITE(PFIT_CONTROL
, PFIT_ENABLE
);
133 else if ((adjusted_mode
->crtc_hdisplay
*
134 mode
->vdisplay
) > (mode
->hdisplay
*
135 adjusted_mode
->crtc_vdisplay
))
136 REG_WRITE(PFIT_CONTROL
, PFIT_ENABLE
|
137 PFIT_SCALING_MODE_PILLARBOX
);
139 REG_WRITE(PFIT_CONTROL
, PFIT_ENABLE
|
140 PFIT_SCALING_MODE_LETTERBOX
);
142 REG_WRITE(PFIT_CONTROL
, PFIT_ENABLE
);
143 } else /*(v == DRM_MODE_SCALE_FULLSCREEN)*/
144 REG_WRITE(PFIT_CONTROL
, PFIT_ENABLE
);
150 static const struct drm_encoder_helper_funcs mrst_lvds_helper_funcs
= {
151 .dpms
= mrst_lvds_dpms
,
152 .mode_fixup
= psb_intel_lvds_mode_fixup
,
153 .prepare
= psb_intel_lvds_prepare
,
154 .mode_set
= mrst_lvds_mode_set
,
155 .commit
= psb_intel_lvds_commit
,
158 static struct drm_display_mode lvds_configuration_modes
[] = {
159 /* hard coded fixed mode for TPO LTPS LPJ040K001A */
160 { DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER
, 33264, 800, 836,
161 846, 1056, 0, 480, 489, 491, 525, 0, 0) },
162 /* hard coded fixed mode for LVDS 800x480 */
163 { DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER
, 30994, 800, 801,
164 802, 1024, 0, 480, 481, 482, 525, 0, 0) },
165 /* hard coded fixed mode for Samsung 480wsvga LVDS 1024x600@75 */
166 { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER
, 53990, 1024, 1072,
167 1104, 1184, 0, 600, 603, 604, 608, 0, 0) },
168 /* hard coded fixed mode for Samsung 480wsvga LVDS 1024x600@75 */
169 { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER
, 53990, 1024, 1104,
170 1136, 1184, 0, 600, 603, 604, 608, 0, 0) },
171 /* hard coded fixed mode for Sharp wsvga LVDS 1024x600 */
172 { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER
, 48885, 1024, 1124,
173 1204, 1312, 0, 600, 607, 610, 621, 0, 0) },
174 /* hard coded fixed mode for LVDS 1024x768 */
175 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
176 1184, 1344, 0, 768, 771, 777, 806, 0, 0) },
177 /* hard coded fixed mode for LVDS 1366x768 */
178 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER
, 77500, 1366, 1430,
179 1558, 1664, 0, 768, 769, 770, 776, 0, 0) },
182 /* Returns the panel fixed mode from configuration. */
184 static struct drm_display_mode
*
185 mrst_lvds_get_configuration_mode(struct drm_device
*dev
)
187 struct drm_display_mode
*mode
= NULL
;
188 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
189 struct mrst_timing_info
*ti
= &dev_priv
->gct_data
.DTD
;
191 if (dev_priv
->vbt_data
.size
!= 0x00) { /*if non-zero, then use vbt*/
192 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
196 mode
->hdisplay
= (ti
->hactive_hi
<< 8) | ti
->hactive_lo
;
197 mode
->vdisplay
= (ti
->vactive_hi
<< 8) | ti
->vactive_lo
;
198 mode
->hsync_start
= mode
->hdisplay
+ \
199 ((ti
->hsync_offset_hi
<< 8) | \
200 ti
->hsync_offset_lo
);
201 mode
->hsync_end
= mode
->hsync_start
+ \
202 ((ti
->hsync_pulse_width_hi
<< 8) | \
203 ti
->hsync_pulse_width_lo
);
204 mode
->htotal
= mode
->hdisplay
+ ((ti
->hblank_hi
<< 8) | \
206 mode
->vsync_start
= \
207 mode
->vdisplay
+ ((ti
->vsync_offset_hi
<< 4) | \
208 ti
->vsync_offset_lo
);
210 mode
->vsync_start
+ ((ti
->vsync_pulse_width_hi
<< 4) | \
211 ti
->vsync_pulse_width_lo
);
212 mode
->vtotal
= mode
->vdisplay
+ \
213 ((ti
->vblank_hi
<< 8) | ti
->vblank_lo
);
214 mode
->clock
= ti
->pixel_clock
* 10;
216 printk(KERN_INFO
"hdisplay is %d\n", mode
->hdisplay
);
217 printk(KERN_INFO
"vdisplay is %d\n", mode
->vdisplay
);
218 printk(KERN_INFO
"HSS is %d\n", mode
->hsync_start
);
219 printk(KERN_INFO
"HSE is %d\n", mode
->hsync_end
);
220 printk(KERN_INFO
"htotal is %d\n", mode
->htotal
);
221 printk(KERN_INFO
"VSS is %d\n", mode
->vsync_start
);
222 printk(KERN_INFO
"VSE is %d\n", mode
->vsync_end
);
223 printk(KERN_INFO
"vtotal is %d\n", mode
->vtotal
);
224 printk(KERN_INFO
"clock is %d\n", mode
->clock
);
227 mode
= drm_mode_duplicate(dev
, &lvds_configuration_modes
[2]);
229 drm_mode_set_name(mode
);
230 drm_mode_set_crtcinfo(mode
, 0);
236 * mrst_lvds_init - setup LVDS connectors on this device
239 * Create the connector, register the LVDS DDC bus, and try to figure out what
240 * modes we can display on the LVDS panel (if present).
242 void mrst_lvds_init(struct drm_device
*dev
,
243 struct psb_intel_mode_device
*mode_dev
)
245 struct psb_intel_output
*psb_intel_output
;
246 struct drm_connector
*connector
;
247 struct drm_encoder
*encoder
;
248 struct drm_psb_private
*dev_priv
=
249 (struct drm_psb_private
*) dev
->dev_private
;
252 struct i2c_adapter
*i2c_adap
;
253 struct drm_display_mode
*scan
; /* *modes, *bios_mode; */
255 PSB_DEBUG_ENTRY("\n");
257 psb_intel_output
= kzalloc(sizeof(struct psb_intel_output
), GFP_KERNEL
);
258 if (!psb_intel_output
)
261 psb_intel_output
->mode_dev
= mode_dev
;
262 connector
= &psb_intel_output
->base
;
263 encoder
= &psb_intel_output
->enc
;
264 dev_priv
->is_lvds_on
= true;
265 drm_connector_init(dev
, &psb_intel_output
->base
,
266 &psb_intel_lvds_connector_funcs
,
267 DRM_MODE_CONNECTOR_LVDS
);
269 drm_encoder_init(dev
, &psb_intel_output
->enc
, &psb_intel_lvds_enc_funcs
,
270 DRM_MODE_ENCODER_LVDS
);
272 drm_mode_connector_attach_encoder(&psb_intel_output
->base
,
273 &psb_intel_output
->enc
);
274 psb_intel_output
->type
= INTEL_OUTPUT_LVDS
;
276 drm_encoder_helper_add(encoder
, &mrst_lvds_helper_funcs
);
277 drm_connector_helper_add(connector
,
278 &psb_intel_lvds_connector_helper_funcs
);
279 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
;
280 connector
->interlace_allowed
= false;
281 connector
->doublescan_allowed
= false;
283 drm_connector_attach_property(connector
,
284 dev
->mode_config
.scaling_mode_property
,
285 DRM_MODE_SCALE_FULLSCREEN
);
286 drm_connector_attach_property(connector
,
287 dev_priv
->backlight_property
,
288 BRIGHTNESS_MAX_LEVEL
);
290 mode_dev
->panel_wants_dither
= false;
291 if (dev_priv
->vbt_data
.size
!= 0x00)
292 mode_dev
->panel_wants_dither
= (dev_priv
->gct_data
.
293 Panel_Port_Control
& MRST_PANEL_8TO6_DITHER_ENABLE
);
297 * 1) check for EDID on DDC
298 * 2) check for VBT data
299 * 3) check to see if LVDS is already on
300 * if none of the above, no panel
301 * 4) make sure lid is open
302 * if closed, act like it's not there for now
305 /* This ifdef can go once the cpu ident stuff is cleaned up in arch */
306 #if defined(CONFIG_X86_MRST)
307 if (mrst_identify_cpu())
308 i2c_adap
= i2c_get_adapter(2);
309 else /* Oaktrail uses I2C 1 */
311 i2c_adap
= i2c_get_adapter(1);
313 if (i2c_adap
== NULL
)
314 printk(KERN_ALERT
"No ddc adapter available!\n");
316 * Attempt to get the fixed panel mode from DDC. Assume that the
317 * preferred mode is the right one.
320 edid
= drm_get_edid(connector
, i2c_adap
);
322 drm_mode_connector_update_edid_property(connector
,
324 ret
= drm_add_edid_modes(connector
, edid
);
328 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
329 if (scan
->type
& DRM_MODE_TYPE_PREFERRED
) {
330 mode_dev
->panel_fixed_mode
=
331 drm_mode_duplicate(dev
, scan
);
332 goto out
; /* FIXME: check for quirks */
338 * If we didn't get EDID, try geting panel timing
339 * from configuration data
341 mode_dev
->panel_fixed_mode
= mrst_lvds_get_configuration_mode(dev
);
343 if (mode_dev
->panel_fixed_mode
) {
344 mode_dev
->panel_fixed_mode
->type
|=
345 DRM_MODE_TYPE_PREFERRED
;
346 goto out
; /* FIXME: check for quirks */
349 /* If we still don't have a mode after all that, give up. */
350 if (!mode_dev
->panel_fixed_mode
) {
352 ("Found no modes on the lvds, ignoring the LVDS\n");
357 drm_sysfs_connector_add(connector
);
361 DRM_DEBUG("No LVDS modes found, disabling.\n");
362 if (psb_intel_output
->ddc_bus
)
363 psb_intel_i2c_destroy(psb_intel_output
->ddc_bus
);
367 drm_encoder_cleanup(encoder
);
368 drm_connector_cleanup(connector
);