2 * Copyright © 2006 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
26 * Minor modifications (Dithering enable):
27 * Thomas Richter <thor@math.tu-berlin.de>
34 * register definitions for the i82807aa.
36 * Documentation on this chipset can be found in datasheet #29069001 at
41 * VCH Revision & GMBus Base Addr
44 # define VR00_BASE_ADDRESS_MASK 0x007f
47 * Functionality Enable
52 * Enable the panel fitter
54 # define VR01_PANEL_FIT_ENABLE (1 << 3)
56 * Enables the LCD display.
58 * This must not be set while VR01_DVO_BYPASS_ENABLE is set.
60 # define VR01_LCD_ENABLE (1 << 2)
61 /** Enables the DVO repeater. */
62 # define VR01_DVO_BYPASS_ENABLE (1 << 1)
63 /** Enables the DVO clock */
64 # define VR01_DVO_ENABLE (1 << 0)
65 /** Enable dithering for 18bpp panels. Not documented. */
66 # define VR01_DITHER_ENABLE (1 << 4)
69 * LCD Interface Format
72 /** Enables LVDS output instead of CMOS */
73 # define VR10_LVDS_ENABLE (1 << 4)
74 /** Enables 18-bit LVDS output. */
75 # define VR10_INTERFACE_1X18 (0 << 2)
76 /** Enables 24-bit LVDS or CMOS output */
77 # define VR10_INTERFACE_1X24 (1 << 2)
78 /** Enables 2x18-bit LVDS or CMOS output. */
79 # define VR10_INTERFACE_2X18 (2 << 2)
80 /** Enables 2x24-bit LVDS output */
81 # define VR10_INTERFACE_2X24 (3 << 2)
82 /** Mask that defines the depth of the pipeline */
83 # define VR10_INTERFACE_DEPTH_MASK (3 << 2)
86 * VR20 LCD Horizontal Display Size
91 * LCD Vertical Display Size
96 * Panel power down status
99 /** Read only bit indicating that the panel is not in a safe poweroff state. */
100 # define VR30_PANEL_ON (1 << 15)
103 # define VR40_STALL_ENABLE (1 << 13)
104 # define VR40_VERTICAL_INTERP_ENABLE (1 << 12)
105 # define VR40_ENHANCED_PANEL_FITTING (1 << 11)
106 # define VR40_HORIZONTAL_INTERP_ENABLE (1 << 10)
107 # define VR40_AUTO_RATIO_ENABLE (1 << 9)
108 # define VR40_CLOCK_GATING_ENABLE (1 << 8)
111 * Panel Fitting Vertical Ratio
112 * (((image_height - 1) << 16) / ((panel_height - 1))) >> 2
117 * Panel Fitting Horizontal Ratio
118 * (((image_width - 1) << 16) / ((panel_width - 1))) >> 2
123 * Horizontal Image Size
142 /* Graphics BIOS scratch 0
145 # define VR8E_PANEL_TYPE_MASK (0xf << 0)
146 # define VR8E_PANEL_INTERFACE_CMOS (0 << 4)
147 # define VR8E_PANEL_INTERFACE_LVDS (1 << 4)
148 # define VR8E_FORCE_DEFAULT_PANEL (1 << 5)
150 /* Graphics BIOS scratch 1
153 # define VR8F_VCH_PRESENT (1 << 0)
154 # define VR8F_DISPLAY_CONN (1 << 1)
155 # define VR8F_POWER_MASK (0x3c)
156 # define VR8F_POWER_POS (2)
162 uint16_t width
, height
;
166 static void ivch_dump_regs(struct intel_dvo_device
*dvo
);
169 * Reads a register on the ivch.
171 * Each of the 256 registers are 16 bits long.
173 static bool ivch_read(struct intel_dvo_device
*dvo
, int addr
, uint16_t *data
)
175 struct ivch_priv
*priv
= dvo
->dev_priv
;
176 struct i2c_adapter
*adapter
= dvo
->i2c_bus
;
180 struct i2c_msg msgs
[] = {
182 .addr
= dvo
->slave_addr
,
188 .flags
= I2C_M_NOSTART
,
193 .addr
= dvo
->slave_addr
,
194 .flags
= I2C_M_RD
| I2C_M_NOSTART
,
202 if (i2c_transfer(adapter
, msgs
, 3) == 3) {
203 *data
= (in_buf
[1] << 8) | in_buf
[0];
208 DRM_DEBUG_KMS("Unable to read register 0x%02x from "
210 addr
, adapter
->name
, dvo
->slave_addr
);
215 /** Writes a 16-bit register on the ivch */
216 static bool ivch_write(struct intel_dvo_device
*dvo
, int addr
, uint16_t data
)
218 struct ivch_priv
*priv
= dvo
->dev_priv
;
219 struct i2c_adapter
*adapter
= dvo
->i2c_bus
;
221 struct i2c_msg msg
= {
222 .addr
= dvo
->slave_addr
,
229 out_buf
[1] = data
& 0xff;
230 out_buf
[2] = data
>> 8;
232 if (i2c_transfer(adapter
, &msg
, 1) == 1)
236 DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
237 addr
, adapter
->name
, dvo
->slave_addr
);
243 /** Probes the given bus and slave address for an ivch */
244 static bool ivch_init(struct intel_dvo_device
*dvo
,
245 struct i2c_adapter
*adapter
)
247 struct ivch_priv
*priv
;
250 priv
= kzalloc(sizeof(struct ivch_priv
), GFP_KERNEL
);
254 dvo
->i2c_bus
= adapter
;
255 dvo
->dev_priv
= priv
;
258 if (!ivch_read(dvo
, VR00
, &temp
))
262 /* Since the identification bits are probably zeroes, which doesn't seem
263 * very unique, check that the value in the base address field matches
264 * the address it's responding on.
266 if ((temp
& VR00_BASE_ADDRESS_MASK
) != dvo
->slave_addr
) {
267 DRM_DEBUG_KMS("ivch detect failed due to address mismatch "
269 (temp
& VR00_BASE_ADDRESS_MASK
), dvo
->slave_addr
);
273 ivch_read(dvo
, VR20
, &priv
->width
);
274 ivch_read(dvo
, VR21
, &priv
->height
);
283 static enum drm_connector_status
ivch_detect(struct intel_dvo_device
*dvo
)
285 return connector_status_connected
;
288 static enum drm_mode_status
ivch_mode_valid(struct intel_dvo_device
*dvo
,
289 struct drm_display_mode
*mode
)
291 if (mode
->clock
> 112000)
292 return MODE_CLOCK_HIGH
;
297 /** Sets the power state of the panel connected to the ivch */
298 static void ivch_dpms(struct intel_dvo_device
*dvo
, bool enable
)
301 uint16_t vr01
, vr30
, backlight
;
303 /* Set the new power state of the panel. */
304 if (!ivch_read(dvo
, VR01
, &vr01
))
311 ivch_write(dvo
, VR80
, backlight
);
314 vr01
|= VR01_LCD_ENABLE
| VR01_DVO_ENABLE
;
316 vr01
&= ~(VR01_LCD_ENABLE
| VR01_DVO_ENABLE
);
318 ivch_write(dvo
, VR01
, vr01
);
320 /* Wait for the panel to make its state transition */
321 for (i
= 0; i
< 100; i
++) {
322 if (!ivch_read(dvo
, VR30
, &vr30
))
325 if (((vr30
& VR30_PANEL_ON
) != 0) == enable
)
329 /* wait some more; vch may fail to resync sometimes without this */
333 static bool ivch_get_hw_state(struct intel_dvo_device
*dvo
)
337 /* Set the new power state of the panel. */
338 if (!ivch_read(dvo
, VR01
, &vr01
))
341 if (vr01
& VR01_LCD_ENABLE
)
347 static void ivch_mode_set(struct intel_dvo_device
*dvo
,
348 struct drm_display_mode
*mode
,
349 struct drm_display_mode
*adjusted_mode
)
355 ivch_read(dvo
, VR10
, &vr10
);
356 /* Enable dithering for 18 bpp pipelines */
357 vr10
&= VR10_INTERFACE_DEPTH_MASK
;
358 if (vr10
== VR10_INTERFACE_2X18
|| vr10
== VR10_INTERFACE_1X18
)
359 vr01
= VR01_DITHER_ENABLE
;
361 vr40
= (VR40_STALL_ENABLE
| VR40_VERTICAL_INTERP_ENABLE
|
362 VR40_HORIZONTAL_INTERP_ENABLE
);
364 if (mode
->hdisplay
!= adjusted_mode
->hdisplay
||
365 mode
->vdisplay
!= adjusted_mode
->vdisplay
) {
366 uint16_t x_ratio
, y_ratio
;
368 vr01
|= VR01_PANEL_FIT_ENABLE
;
369 vr40
|= VR40_CLOCK_GATING_ENABLE
| VR40_ENHANCED_PANEL_FITTING
;
370 x_ratio
= (((mode
->hdisplay
- 1) << 16) /
371 (adjusted_mode
->hdisplay
- 1)) >> 2;
372 y_ratio
= (((mode
->vdisplay
- 1) << 16) /
373 (adjusted_mode
->vdisplay
- 1)) >> 2;
374 ivch_write(dvo
, VR42
, x_ratio
);
375 ivch_write(dvo
, VR41
, y_ratio
);
377 vr01
&= ~VR01_PANEL_FIT_ENABLE
;
378 vr40
&= ~VR40_CLOCK_GATING_ENABLE
;
380 vr40
&= ~VR40_AUTO_RATIO_ENABLE
;
382 ivch_write(dvo
, VR01
, vr01
);
383 ivch_write(dvo
, VR40
, vr40
);
388 static void ivch_dump_regs(struct intel_dvo_device
*dvo
)
392 ivch_read(dvo
, VR00
, &val
);
393 DRM_DEBUG_KMS("VR00: 0x%04x\n", val
);
394 ivch_read(dvo
, VR01
, &val
);
395 DRM_DEBUG_KMS("VR01: 0x%04x\n", val
);
396 ivch_read(dvo
, VR10
, &val
);
397 DRM_DEBUG_KMS("VR10: 0x%04x\n", val
);
398 ivch_read(dvo
, VR30
, &val
);
399 DRM_DEBUG_KMS("VR30: 0x%04x\n", val
);
400 ivch_read(dvo
, VR40
, &val
);
401 DRM_DEBUG_KMS("VR40: 0x%04x\n", val
);
404 ivch_read(dvo
, VR80
, &val
);
405 DRM_DEBUG_KMS("VR80: 0x%04x\n", val
);
406 ivch_read(dvo
, VR81
, &val
);
407 DRM_DEBUG_KMS("VR81: 0x%04x\n", val
);
408 ivch_read(dvo
, VR82
, &val
);
409 DRM_DEBUG_KMS("VR82: 0x%04x\n", val
);
410 ivch_read(dvo
, VR83
, &val
);
411 DRM_DEBUG_KMS("VR83: 0x%04x\n", val
);
412 ivch_read(dvo
, VR84
, &val
);
413 DRM_DEBUG_KMS("VR84: 0x%04x\n", val
);
414 ivch_read(dvo
, VR85
, &val
);
415 DRM_DEBUG_KMS("VR85: 0x%04x\n", val
);
416 ivch_read(dvo
, VR86
, &val
);
417 DRM_DEBUG_KMS("VR86: 0x%04x\n", val
);
418 ivch_read(dvo
, VR87
, &val
);
419 DRM_DEBUG_KMS("VR87: 0x%04x\n", val
);
420 ivch_read(dvo
, VR88
, &val
);
421 DRM_DEBUG_KMS("VR88: 0x%04x\n", val
);
423 /* Scratch register 0 - AIM Panel type */
424 ivch_read(dvo
, VR8E
, &val
);
425 DRM_DEBUG_KMS("VR8E: 0x%04x\n", val
);
427 /* Scratch register 1 - Status register */
428 ivch_read(dvo
, VR8F
, &val
);
429 DRM_DEBUG_KMS("VR8F: 0x%04x\n", val
);
432 static void ivch_destroy(struct intel_dvo_device
*dvo
)
434 struct ivch_priv
*priv
= dvo
->dev_priv
;
438 dvo
->dev_priv
= NULL
;
442 struct intel_dvo_dev_ops ivch_ops
= {
445 .get_hw_state
= ivch_get_hw_state
,
446 .mode_valid
= ivch_mode_valid
,
447 .mode_set
= ivch_mode_set
,
448 .detect
= ivch_detect
,
449 .dump_regs
= ivch_dump_regs
,
450 .destroy
= ivch_destroy
,