aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/Kconfig1
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c2
-rw-r--r--drivers/gpu/drm/drm_edid.c12
-rw-r--r--drivers/gpu/drm/i915/Makefile2
-rw-r--r--drivers/gpu/drm/i915/dvo.h4
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7017.c20
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7xxx.c25
-rw-r--r--drivers/gpu/drm/i915/dvo_ivch.c21
-rw-r--r--drivers/gpu/drm/i915/dvo_sil164.c25
-rw-r--r--drivers/gpu/drm/i915/dvo_tfp410.c25
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c72
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c13
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h39
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c55
-rw-r--r--drivers/gpu/drm/i915/i915_gem_debug.c6
-rw-r--r--drivers/gpu/drm/i915/i915_gem_debugfs.c44
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c8
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c155
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h81
-rw-r--r--drivers/gpu/drm/i915/i915_suspend.c251
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c32
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c30
-rw-r--r--drivers/gpu/drm/i915/intel_display.c623
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c1156
-rw-r--r--drivers/gpu/drm/i915/intel_dp.h144
-rw-r--r--drivers/gpu/drm/i915/intel_dp_i2c.c273
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h17
-rw-r--r--drivers/gpu/drm/i915/intel_dvo.c16
-rw-r--r--drivers/gpu/drm/i915/intel_fb.c18
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c35
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c16
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c418
-rw-r--r--drivers/gpu/drm/i915/intel_modes.c14
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c186
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo_regs.h1
-rw-r--r--drivers/gpu/drm/i915/intel_tv.c53
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c22
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_fb.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c30
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_util.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c1
44 files changed, 3508 insertions, 477 deletions
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index c961fe415aef..39b393d38bb3 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -81,6 +81,7 @@ config DRM_I830
81 81
82config DRM_I915 82config DRM_I915
83 tristate "i915 driver" 83 tristate "i915 driver"
84 depends on AGP_INTEL
84 select FB_CFB_FILLRECT 85 select FB_CFB_FILLRECT
85 select FB_CFB_COPYAREA 86 select FB_CFB_COPYAREA
86 select FB_CFB_IMAGEBLIT 87 select FB_CFB_IMAGEBLIT
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 4e89ab08b7b8..fe23f29f7cba 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -16,6 +16,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
16drm-$(CONFIG_COMPAT) += drm_ioc32.o 16drm-$(CONFIG_COMPAT) += drm_ioc32.o
17 17
18obj-$(CONFIG_DRM) += drm.o 18obj-$(CONFIG_DRM) += drm.o
19obj-$(CONFIG_DRM_TTM) += ttm/
19obj-$(CONFIG_DRM_TDFX) += tdfx/ 20obj-$(CONFIG_DRM_TDFX) += tdfx/
20obj-$(CONFIG_DRM_R128) += r128/ 21obj-$(CONFIG_DRM_R128) += r128/
21obj-$(CONFIG_DRM_RADEON)+= radeon/ 22obj-$(CONFIG_DRM_RADEON)+= radeon/
@@ -26,4 +27,3 @@ obj-$(CONFIG_DRM_I915) += i915/
26obj-$(CONFIG_DRM_SIS) += sis/ 27obj-$(CONFIG_DRM_SIS) += sis/
27obj-$(CONFIG_DRM_SAVAGE)+= savage/ 28obj-$(CONFIG_DRM_SAVAGE)+= savage/
28obj-$(CONFIG_DRM_VIA) +=via/ 29obj-$(CONFIG_DRM_VIA) +=via/
29obj-$(CONFIG_DRM_TTM) += ttm/
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index a6f73f1e99d9..3da9cfa31848 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -1090,6 +1090,8 @@ int drm_helper_resume_force_mode(struct drm_device *dev)
1090 if (ret == false) 1090 if (ret == false)
1091 DRM_ERROR("failed to set mode on crtc %p\n", crtc); 1091 DRM_ERROR("failed to set mode on crtc %p\n", crtc);
1092 } 1092 }
1093 /* disable the unused connectors while restoring the modesetting */
1094 drm_helper_disable_unused_functions(dev);
1093 return 0; 1095 return 0;
1094} 1096}
1095EXPORT_SYMBOL(drm_helper_resume_force_mode); 1097EXPORT_SYMBOL(drm_helper_resume_force_mode);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7d0835226f6e..80cc6d06d61b 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -294,10 +294,10 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
294 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo; 294 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
295 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo; 295 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
296 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo; 296 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
297 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 8 | pt->hsync_offset_lo; 297 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
298 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 6 | pt->hsync_pulse_width_lo; 298 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
299 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) | (pt->vsync_offset_pulse_width_lo & 0xf); 299 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) >> 2 | pt->vsync_offset_pulse_width_lo >> 4;
300 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) >> 2 | pt->vsync_offset_pulse_width_lo >> 4; 300 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
301 301
302 /* ignore tiny modes */ 302 /* ignore tiny modes */
303 if (hactive < 64 || vactive < 64) 303 if (hactive < 64 || vactive < 64)
@@ -347,8 +347,8 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
347 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ? 347 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
348 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; 348 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
349 349
350 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf) << 8; 350 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
351 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4; 351 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
352 352
353 if (quirks & EDID_QUIRK_DETAILED_IN_CM) { 353 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
354 mode->width_mm *= 10; 354 mode->width_mm *= 10;
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 51c5a050aa73..30d6b99fb302 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -13,6 +13,8 @@ i915-y := i915_drv.o i915_dma.o i915_irq.o i915_mem.o \
13 intel_crt.o \ 13 intel_crt.o \
14 intel_lvds.o \ 14 intel_lvds.o \
15 intel_bios.o \ 15 intel_bios.o \
16 intel_dp.o \
17 intel_dp_i2c.o \
16 intel_hdmi.o \ 18 intel_hdmi.o \
17 intel_sdvo.o \ 19 intel_sdvo.o \
18 intel_modes.o \ 20 intel_modes.o \
diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
index e747ac42fe3a..288fc50627e2 100644
--- a/drivers/gpu/drm/i915/dvo.h
+++ b/drivers/gpu/drm/i915/dvo.h
@@ -37,7 +37,7 @@ struct intel_dvo_device {
37 /* GPIO register used for i2c bus to control this device */ 37 /* GPIO register used for i2c bus to control this device */
38 u32 gpio; 38 u32 gpio;
39 int slave_addr; 39 int slave_addr;
40 struct intel_i2c_chan *i2c_bus; 40 struct i2c_adapter *i2c_bus;
41 41
42 const struct intel_dvo_dev_ops *dev_ops; 42 const struct intel_dvo_dev_ops *dev_ops;
43 void *dev_priv; 43 void *dev_priv;
@@ -52,7 +52,7 @@ struct intel_dvo_dev_ops {
52 * Returns NULL if the device does not exist. 52 * Returns NULL if the device does not exist.
53 */ 53 */
54 bool (*init)(struct intel_dvo_device *dvo, 54 bool (*init)(struct intel_dvo_device *dvo,
55 struct intel_i2c_chan *i2cbus); 55 struct i2c_adapter *i2cbus);
56 56
57 /* 57 /*
58 * Called to allow the output a chance to create properties after the 58 * Called to allow the output a chance to create properties after the
diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
index 03d4b4973b02..621815b531db 100644
--- a/drivers/gpu/drm/i915/dvo_ch7017.c
+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
@@ -176,19 +176,20 @@ static void ch7017_dpms(struct intel_dvo_device *dvo, int mode);
176 176
177static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val) 177static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val)
178{ 178{
179 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 179 struct i2c_adapter *adapter = dvo->i2c_bus;
180 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
180 u8 out_buf[2]; 181 u8 out_buf[2];
181 u8 in_buf[2]; 182 u8 in_buf[2];
182 183
183 struct i2c_msg msgs[] = { 184 struct i2c_msg msgs[] = {
184 { 185 {
185 .addr = i2cbus->slave_addr, 186 .addr = dvo->slave_addr,
186 .flags = 0, 187 .flags = 0,
187 .len = 1, 188 .len = 1,
188 .buf = out_buf, 189 .buf = out_buf,
189 }, 190 },
190 { 191 {
191 .addr = i2cbus->slave_addr, 192 .addr = dvo->slave_addr,
192 .flags = I2C_M_RD, 193 .flags = I2C_M_RD,
193 .len = 1, 194 .len = 1,
194 .buf = in_buf, 195 .buf = in_buf,
@@ -208,10 +209,11 @@ static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val)
208 209
209static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val) 210static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val)
210{ 211{
211 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 212 struct i2c_adapter *adapter = dvo->i2c_bus;
213 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
212 uint8_t out_buf[2]; 214 uint8_t out_buf[2];
213 struct i2c_msg msg = { 215 struct i2c_msg msg = {
214 .addr = i2cbus->slave_addr, 216 .addr = dvo->slave_addr,
215 .flags = 0, 217 .flags = 0,
216 .len = 2, 218 .len = 2,
217 .buf = out_buf, 219 .buf = out_buf,
@@ -228,8 +230,9 @@ static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val)
228 230
229/** Probes for a CH7017 on the given bus and slave address. */ 231/** Probes for a CH7017 on the given bus and slave address. */
230static bool ch7017_init(struct intel_dvo_device *dvo, 232static bool ch7017_init(struct intel_dvo_device *dvo,
231 struct intel_i2c_chan *i2cbus) 233 struct i2c_adapter *adapter)
232{ 234{
235 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
233 struct ch7017_priv *priv; 236 struct ch7017_priv *priv;
234 uint8_t val; 237 uint8_t val;
235 238
@@ -237,8 +240,7 @@ static bool ch7017_init(struct intel_dvo_device *dvo,
237 if (priv == NULL) 240 if (priv == NULL)
238 return false; 241 return false;
239 242
240 dvo->i2c_bus = i2cbus; 243 dvo->i2c_bus = adapter;
241 dvo->i2c_bus->slave_addr = dvo->slave_addr;
242 dvo->dev_priv = priv; 244 dvo->dev_priv = priv;
243 245
244 if (!ch7017_read(dvo, CH7017_DEVICE_ID, &val)) 246 if (!ch7017_read(dvo, CH7017_DEVICE_ID, &val))
@@ -248,7 +250,7 @@ static bool ch7017_init(struct intel_dvo_device *dvo,
248 val != CH7018_DEVICE_ID_VALUE && 250 val != CH7018_DEVICE_ID_VALUE &&
249 val != CH7019_DEVICE_ID_VALUE) { 251 val != CH7019_DEVICE_ID_VALUE) {
250 DRM_DEBUG("ch701x not detected, got %d: from %s Slave %d.\n", 252 DRM_DEBUG("ch701x not detected, got %d: from %s Slave %d.\n",
251 val, i2cbus->adapter.name,i2cbus->slave_addr); 253 val, i2cbus->adapter.name,dvo->slave_addr);
252 goto fail; 254 goto fail;
253 } 255 }
254 256
diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
index d2fd95dbd034..a9b896289680 100644
--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
@@ -123,19 +123,20 @@ static char *ch7xxx_get_id(uint8_t vid)
123static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 123static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
124{ 124{
125 struct ch7xxx_priv *ch7xxx= dvo->dev_priv; 125 struct ch7xxx_priv *ch7xxx= dvo->dev_priv;
126 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 126 struct i2c_adapter *adapter = dvo->i2c_bus;
127 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
127 u8 out_buf[2]; 128 u8 out_buf[2];
128 u8 in_buf[2]; 129 u8 in_buf[2];
129 130
130 struct i2c_msg msgs[] = { 131 struct i2c_msg msgs[] = {
131 { 132 {
132 .addr = i2cbus->slave_addr, 133 .addr = dvo->slave_addr,
133 .flags = 0, 134 .flags = 0,
134 .len = 1, 135 .len = 1,
135 .buf = out_buf, 136 .buf = out_buf,
136 }, 137 },
137 { 138 {
138 .addr = i2cbus->slave_addr, 139 .addr = dvo->slave_addr,
139 .flags = I2C_M_RD, 140 .flags = I2C_M_RD,
140 .len = 1, 141 .len = 1,
141 .buf = in_buf, 142 .buf = in_buf,
@@ -152,7 +153,7 @@ static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
152 153
153 if (!ch7xxx->quiet) { 154 if (!ch7xxx->quiet) {
154 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 155 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
155 addr, i2cbus->adapter.name, i2cbus->slave_addr); 156 addr, i2cbus->adapter.name, dvo->slave_addr);
156 } 157 }
157 return false; 158 return false;
158} 159}
@@ -161,10 +162,11 @@ static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
161static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 162static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
162{ 163{
163 struct ch7xxx_priv *ch7xxx = dvo->dev_priv; 164 struct ch7xxx_priv *ch7xxx = dvo->dev_priv;
164 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 165 struct i2c_adapter *adapter = dvo->i2c_bus;
166 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
165 uint8_t out_buf[2]; 167 uint8_t out_buf[2];
166 struct i2c_msg msg = { 168 struct i2c_msg msg = {
167 .addr = i2cbus->slave_addr, 169 .addr = dvo->slave_addr,
168 .flags = 0, 170 .flags = 0,
169 .len = 2, 171 .len = 2,
170 .buf = out_buf, 172 .buf = out_buf,
@@ -178,14 +180,14 @@ static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
178 180
179 if (!ch7xxx->quiet) { 181 if (!ch7xxx->quiet) {
180 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 182 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
181 addr, i2cbus->adapter.name, i2cbus->slave_addr); 183 addr, i2cbus->adapter.name, dvo->slave_addr);
182 } 184 }
183 185
184 return false; 186 return false;
185} 187}
186 188
187static bool ch7xxx_init(struct intel_dvo_device *dvo, 189static bool ch7xxx_init(struct intel_dvo_device *dvo,
188 struct intel_i2c_chan *i2cbus) 190 struct i2c_adapter *adapter)
189{ 191{
190 /* this will detect the CH7xxx chip on the specified i2c bus */ 192 /* this will detect the CH7xxx chip on the specified i2c bus */
191 struct ch7xxx_priv *ch7xxx; 193 struct ch7xxx_priv *ch7xxx;
@@ -196,8 +198,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
196 if (ch7xxx == NULL) 198 if (ch7xxx == NULL)
197 return false; 199 return false;
198 200
199 dvo->i2c_bus = i2cbus; 201 dvo->i2c_bus = adapter;
200 dvo->i2c_bus->slave_addr = dvo->slave_addr;
201 dvo->dev_priv = ch7xxx; 202 dvo->dev_priv = ch7xxx;
202 ch7xxx->quiet = true; 203 ch7xxx->quiet = true;
203 204
@@ -207,7 +208,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
207 name = ch7xxx_get_id(vendor); 208 name = ch7xxx_get_id(vendor);
208 if (!name) { 209 if (!name) {
209 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", 210 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n",
210 vendor, i2cbus->adapter.name, i2cbus->slave_addr); 211 vendor, adapter->name, dvo->slave_addr);
211 goto out; 212 goto out;
212 } 213 }
213 214
@@ -217,7 +218,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
217 218
218 if (device != CH7xxx_DID) { 219 if (device != CH7xxx_DID) {
219 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", 220 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n",
220 vendor, i2cbus->adapter.name, i2cbus->slave_addr); 221 vendor, adapter->name, dvo->slave_addr);
221 goto out; 222 goto out;
222 } 223 }
223 224
diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
index 0c8d375e8e37..aa176f9921fe 100644
--- a/drivers/gpu/drm/i915/dvo_ivch.c
+++ b/drivers/gpu/drm/i915/dvo_ivch.c
@@ -169,13 +169,14 @@ static void ivch_dump_regs(struct intel_dvo_device *dvo);
169static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data) 169static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
170{ 170{
171 struct ivch_priv *priv = dvo->dev_priv; 171 struct ivch_priv *priv = dvo->dev_priv;
172 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 172 struct i2c_adapter *adapter = dvo->i2c_bus;
173 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
173 u8 out_buf[1]; 174 u8 out_buf[1];
174 u8 in_buf[2]; 175 u8 in_buf[2];
175 176
176 struct i2c_msg msgs[] = { 177 struct i2c_msg msgs[] = {
177 { 178 {
178 .addr = i2cbus->slave_addr, 179 .addr = dvo->slave_addr,
179 .flags = I2C_M_RD, 180 .flags = I2C_M_RD,
180 .len = 0, 181 .len = 0,
181 }, 182 },
@@ -186,7 +187,7 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
186 .buf = out_buf, 187 .buf = out_buf,
187 }, 188 },
188 { 189 {
189 .addr = i2cbus->slave_addr, 190 .addr = dvo->slave_addr,
190 .flags = I2C_M_RD | I2C_M_NOSTART, 191 .flags = I2C_M_RD | I2C_M_NOSTART,
191 .len = 2, 192 .len = 2,
192 .buf = in_buf, 193 .buf = in_buf,
@@ -202,7 +203,7 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
202 203
203 if (!priv->quiet) { 204 if (!priv->quiet) {
204 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 205 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
205 addr, i2cbus->adapter.name, i2cbus->slave_addr); 206 addr, i2cbus->adapter.name, dvo->slave_addr);
206 } 207 }
207 return false; 208 return false;
208} 209}
@@ -211,10 +212,11 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
211static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data) 212static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
212{ 213{
213 struct ivch_priv *priv = dvo->dev_priv; 214 struct ivch_priv *priv = dvo->dev_priv;
214 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 215 struct i2c_adapter *adapter = dvo->i2c_bus;
216 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
215 u8 out_buf[3]; 217 u8 out_buf[3];
216 struct i2c_msg msg = { 218 struct i2c_msg msg = {
217 .addr = i2cbus->slave_addr, 219 .addr = dvo->slave_addr,
218 .flags = 0, 220 .flags = 0,
219 .len = 3, 221 .len = 3,
220 .buf = out_buf, 222 .buf = out_buf,
@@ -229,7 +231,7 @@ static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
229 231
230 if (!priv->quiet) { 232 if (!priv->quiet) {
231 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 233 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
232 addr, i2cbus->adapter.name, i2cbus->slave_addr); 234 addr, i2cbus->adapter.name, dvo->slave_addr);
233 } 235 }
234 236
235 return false; 237 return false;
@@ -237,7 +239,7 @@ static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
237 239
238/** Probes the given bus and slave address for an ivch */ 240/** Probes the given bus and slave address for an ivch */
239static bool ivch_init(struct intel_dvo_device *dvo, 241static bool ivch_init(struct intel_dvo_device *dvo,
240 struct intel_i2c_chan *i2cbus) 242 struct i2c_adapter *adapter)
241{ 243{
242 struct ivch_priv *priv; 244 struct ivch_priv *priv;
243 uint16_t temp; 245 uint16_t temp;
@@ -246,8 +248,7 @@ static bool ivch_init(struct intel_dvo_device *dvo,
246 if (priv == NULL) 248 if (priv == NULL)
247 return false; 249 return false;
248 250
249 dvo->i2c_bus = i2cbus; 251 dvo->i2c_bus = adapter;
250 dvo->i2c_bus->slave_addr = dvo->slave_addr;
251 dvo->dev_priv = priv; 252 dvo->dev_priv = priv;
252 priv->quiet = true; 253 priv->quiet = true;
253 254
diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
index 033a4bb070b2..e1c1f7341e5c 100644
--- a/drivers/gpu/drm/i915/dvo_sil164.c
+++ b/drivers/gpu/drm/i915/dvo_sil164.c
@@ -76,19 +76,20 @@ struct sil164_priv {
76static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 76static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
77{ 77{
78 struct sil164_priv *sil = dvo->dev_priv; 78 struct sil164_priv *sil = dvo->dev_priv;
79 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 79 struct i2c_adapter *adapter = dvo->i2c_bus;
80 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
80 u8 out_buf[2]; 81 u8 out_buf[2];
81 u8 in_buf[2]; 82 u8 in_buf[2];
82 83
83 struct i2c_msg msgs[] = { 84 struct i2c_msg msgs[] = {
84 { 85 {
85 .addr = i2cbus->slave_addr, 86 .addr = dvo->slave_addr,
86 .flags = 0, 87 .flags = 0,
87 .len = 1, 88 .len = 1,
88 .buf = out_buf, 89 .buf = out_buf,
89 }, 90 },
90 { 91 {
91 .addr = i2cbus->slave_addr, 92 .addr = dvo->slave_addr,
92 .flags = I2C_M_RD, 93 .flags = I2C_M_RD,
93 .len = 1, 94 .len = 1,
94 .buf = in_buf, 95 .buf = in_buf,
@@ -105,7 +106,7 @@ static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
105 106
106 if (!sil->quiet) { 107 if (!sil->quiet) {
107 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 108 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
108 addr, i2cbus->adapter.name, i2cbus->slave_addr); 109 addr, i2cbus->adapter.name, dvo->slave_addr);
109 } 110 }
110 return false; 111 return false;
111} 112}
@@ -113,10 +114,11 @@ static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
113static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 114static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
114{ 115{
115 struct sil164_priv *sil= dvo->dev_priv; 116 struct sil164_priv *sil= dvo->dev_priv;
116 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 117 struct i2c_adapter *adapter = dvo->i2c_bus;
118 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
117 uint8_t out_buf[2]; 119 uint8_t out_buf[2];
118 struct i2c_msg msg = { 120 struct i2c_msg msg = {
119 .addr = i2cbus->slave_addr, 121 .addr = dvo->slave_addr,
120 .flags = 0, 122 .flags = 0,
121 .len = 2, 123 .len = 2,
122 .buf = out_buf, 124 .buf = out_buf,
@@ -130,7 +132,7 @@ static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
130 132
131 if (!sil->quiet) { 133 if (!sil->quiet) {
132 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 134 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
133 addr, i2cbus->adapter.name, i2cbus->slave_addr); 135 addr, i2cbus->adapter.name, dvo->slave_addr);
134 } 136 }
135 137
136 return false; 138 return false;
@@ -138,7 +140,7 @@ static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
138 140
139/* Silicon Image 164 driver for chip on i2c bus */ 141/* Silicon Image 164 driver for chip on i2c bus */
140static bool sil164_init(struct intel_dvo_device *dvo, 142static bool sil164_init(struct intel_dvo_device *dvo,
141 struct intel_i2c_chan *i2cbus) 143 struct i2c_adapter *adapter)
142{ 144{
143 /* this will detect the SIL164 chip on the specified i2c bus */ 145 /* this will detect the SIL164 chip on the specified i2c bus */
144 struct sil164_priv *sil; 146 struct sil164_priv *sil;
@@ -148,8 +150,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
148 if (sil == NULL) 150 if (sil == NULL)
149 return false; 151 return false;
150 152
151 dvo->i2c_bus = i2cbus; 153 dvo->i2c_bus = adapter;
152 dvo->i2c_bus->slave_addr = dvo->slave_addr;
153 dvo->dev_priv = sil; 154 dvo->dev_priv = sil;
154 sil->quiet = true; 155 sil->quiet = true;
155 156
@@ -158,7 +159,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
158 159
159 if (ch != (SIL164_VID & 0xff)) { 160 if (ch != (SIL164_VID & 0xff)) {
160 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n", 161 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n",
161 ch, i2cbus->adapter.name, i2cbus->slave_addr); 162 ch, adapter->name, dvo->slave_addr);
162 goto out; 163 goto out;
163 } 164 }
164 165
@@ -167,7 +168,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
167 168
168 if (ch != (SIL164_DID & 0xff)) { 169 if (ch != (SIL164_DID & 0xff)) {
169 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n", 170 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n",
170 ch, i2cbus->adapter.name, i2cbus->slave_addr); 171 ch, adapter->name, dvo->slave_addr);
171 goto out; 172 goto out;
172 } 173 }
173 sil->quiet = false; 174 sil->quiet = false;
diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
index 207fda806ebf..9ecc907384ec 100644
--- a/drivers/gpu/drm/i915/dvo_tfp410.c
+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
@@ -101,19 +101,20 @@ struct tfp410_priv {
101static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 101static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
102{ 102{
103 struct tfp410_priv *tfp = dvo->dev_priv; 103 struct tfp410_priv *tfp = dvo->dev_priv;
104 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 104 struct i2c_adapter *adapter = dvo->i2c_bus;
105 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
105 u8 out_buf[2]; 106 u8 out_buf[2];
106 u8 in_buf[2]; 107 u8 in_buf[2];
107 108
108 struct i2c_msg msgs[] = { 109 struct i2c_msg msgs[] = {
109 { 110 {
110 .addr = i2cbus->slave_addr, 111 .addr = dvo->slave_addr,
111 .flags = 0, 112 .flags = 0,
112 .len = 1, 113 .len = 1,
113 .buf = out_buf, 114 .buf = out_buf,
114 }, 115 },
115 { 116 {
116 .addr = i2cbus->slave_addr, 117 .addr = dvo->slave_addr,
117 .flags = I2C_M_RD, 118 .flags = I2C_M_RD,
118 .len = 1, 119 .len = 1,
119 .buf = in_buf, 120 .buf = in_buf,
@@ -130,7 +131,7 @@ static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
130 131
131 if (!tfp->quiet) { 132 if (!tfp->quiet) {
132 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 133 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
133 addr, i2cbus->adapter.name, i2cbus->slave_addr); 134 addr, i2cbus->adapter.name, dvo->slave_addr);
134 } 135 }
135 return false; 136 return false;
136} 137}
@@ -138,10 +139,11 @@ static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
138static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 139static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
139{ 140{
140 struct tfp410_priv *tfp = dvo->dev_priv; 141 struct tfp410_priv *tfp = dvo->dev_priv;
141 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 142 struct i2c_adapter *adapter = dvo->i2c_bus;
143 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
142 uint8_t out_buf[2]; 144 uint8_t out_buf[2];
143 struct i2c_msg msg = { 145 struct i2c_msg msg = {
144 .addr = i2cbus->slave_addr, 146 .addr = dvo->slave_addr,
145 .flags = 0, 147 .flags = 0,
146 .len = 2, 148 .len = 2,
147 .buf = out_buf, 149 .buf = out_buf,
@@ -155,7 +157,7 @@ static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
155 157
156 if (!tfp->quiet) { 158 if (!tfp->quiet) {
157 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 159 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
158 addr, i2cbus->adapter.name, i2cbus->slave_addr); 160 addr, i2cbus->adapter.name, dvo->slave_addr);
159 } 161 }
160 162
161 return false; 163 return false;
@@ -174,7 +176,7 @@ static int tfp410_getid(struct intel_dvo_device *dvo, int addr)
174 176
175/* Ti TFP410 driver for chip on i2c bus */ 177/* Ti TFP410 driver for chip on i2c bus */
176static bool tfp410_init(struct intel_dvo_device *dvo, 178static bool tfp410_init(struct intel_dvo_device *dvo,
177 struct intel_i2c_chan *i2cbus) 179 struct i2c_adapter *adapter)
178{ 180{
179 /* this will detect the tfp410 chip on the specified i2c bus */ 181 /* this will detect the tfp410 chip on the specified i2c bus */
180 struct tfp410_priv *tfp; 182 struct tfp410_priv *tfp;
@@ -184,20 +186,19 @@ static bool tfp410_init(struct intel_dvo_device *dvo,
184 if (tfp == NULL) 186 if (tfp == NULL)
185 return false; 187 return false;
186 188
187 dvo->i2c_bus = i2cbus; 189 dvo->i2c_bus = adapter;
188 dvo->i2c_bus->slave_addr = dvo->slave_addr;
189 dvo->dev_priv = tfp; 190 dvo->dev_priv = tfp;
190 tfp->quiet = true; 191 tfp->quiet = true;
191 192
192 if ((id = tfp410_getid(dvo, TFP410_VID_LO)) != TFP410_VID) { 193 if ((id = tfp410_getid(dvo, TFP410_VID_LO)) != TFP410_VID) {
193 DRM_DEBUG("tfp410 not detected got VID %X: from %s Slave %d.\n", 194 DRM_DEBUG("tfp410 not detected got VID %X: from %s Slave %d.\n",
194 id, i2cbus->adapter.name, i2cbus->slave_addr); 195 id, adapter->name, dvo->slave_addr);
195 goto out; 196 goto out;
196 } 197 }
197 198
198 if ((id = tfp410_getid(dvo, TFP410_DID_LO)) != TFP410_DID) { 199 if ((id = tfp410_getid(dvo, TFP410_DID_LO)) != TFP410_DID) {
199 DRM_DEBUG("tfp410 not detected got DID %X: from %s Slave %d.\n", 200 DRM_DEBUG("tfp410 not detected got DID %X: from %s Slave %d.\n",
200 id, i2cbus->adapter.name, i2cbus->slave_addr); 201 id, adapter->name, dvo->slave_addr);
201 goto out; 202 goto out;
202 } 203 }
203 tfp->quiet = false; 204 tfp->quiet = false;
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index f112c769d533..8c4783180bf6 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -846,7 +846,7 @@ static int i915_set_status_page(struct drm_device *dev, void *data,
846 return 0; 846 return 0;
847 } 847 }
848 848
849 printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr); 849 DRM_DEBUG("set status page addr 0x%08x\n", (u32)hws->addr);
850 850
851 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12); 851 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
852 852
@@ -885,8 +885,8 @@ static int i915_set_status_page(struct drm_device *dev, void *data,
885 * some RAM for the framebuffer at early boot. This code figures out 885 * some RAM for the framebuffer at early boot. This code figures out
886 * how much was set aside so we can use it for our own purposes. 886 * how much was set aside so we can use it for our own purposes.
887 */ 887 */
888static int i915_probe_agp(struct drm_device *dev, unsigned long *aperture_size, 888static int i915_probe_agp(struct drm_device *dev, uint32_t *aperture_size,
889 unsigned long *preallocated_size) 889 uint32_t *preallocated_size)
890{ 890{
891 struct pci_dev *bridge_dev; 891 struct pci_dev *bridge_dev;
892 u16 tmp = 0; 892 u16 tmp = 0;
@@ -984,10 +984,11 @@ static int i915_probe_agp(struct drm_device *dev, unsigned long *aperture_size,
984 return 0; 984 return 0;
985} 985}
986 986
987static int i915_load_modeset_init(struct drm_device *dev) 987static int i915_load_modeset_init(struct drm_device *dev,
988 unsigned long prealloc_size,
989 unsigned long agp_size)
988{ 990{
989 struct drm_i915_private *dev_priv = dev->dev_private; 991 struct drm_i915_private *dev_priv = dev->dev_private;
990 unsigned long agp_size, prealloc_size;
991 int fb_bar = IS_I9XX(dev) ? 2 : 0; 992 int fb_bar = IS_I9XX(dev) ? 2 : 0;
992 int ret = 0; 993 int ret = 0;
993 994
@@ -1002,10 +1003,6 @@ static int i915_load_modeset_init(struct drm_device *dev)
1002 if (IS_I965G(dev) || IS_G33(dev)) 1003 if (IS_I965G(dev) || IS_G33(dev))
1003 dev_priv->cursor_needs_physical = false; 1004 dev_priv->cursor_needs_physical = false;
1004 1005
1005 ret = i915_probe_agp(dev, &agp_size, &prealloc_size);
1006 if (ret)
1007 goto out;
1008
1009 /* Basic memrange allocator for stolen space (aka vram) */ 1006 /* Basic memrange allocator for stolen space (aka vram) */
1010 drm_mm_init(&dev_priv->vram, 0, prealloc_size); 1007 drm_mm_init(&dev_priv->vram, 0, prealloc_size);
1011 1008
@@ -1082,6 +1079,44 @@ void i915_master_destroy(struct drm_device *dev, struct drm_master *master)
1082 master->driver_priv = NULL; 1079 master->driver_priv = NULL;
1083} 1080}
1084 1081
1082static void i915_get_mem_freq(struct drm_device *dev)
1083{
1084 drm_i915_private_t *dev_priv = dev->dev_private;
1085 u32 tmp;
1086
1087 if (!IS_IGD(dev))
1088 return;
1089
1090 tmp = I915_READ(CLKCFG);
1091
1092 switch (tmp & CLKCFG_FSB_MASK) {
1093 case CLKCFG_FSB_533:
1094 dev_priv->fsb_freq = 533; /* 133*4 */
1095 break;
1096 case CLKCFG_FSB_800:
1097 dev_priv->fsb_freq = 800; /* 200*4 */
1098 break;
1099 case CLKCFG_FSB_667:
1100 dev_priv->fsb_freq = 667; /* 167*4 */
1101 break;
1102 case CLKCFG_FSB_400:
1103 dev_priv->fsb_freq = 400; /* 100*4 */
1104 break;
1105 }
1106
1107 switch (tmp & CLKCFG_MEM_MASK) {
1108 case CLKCFG_MEM_533:
1109 dev_priv->mem_freq = 533;
1110 break;
1111 case CLKCFG_MEM_667:
1112 dev_priv->mem_freq = 667;
1113 break;
1114 case CLKCFG_MEM_800:
1115 dev_priv->mem_freq = 800;
1116 break;
1117 }
1118}
1119
1085/** 1120/**
1086 * i915_driver_load - setup chip and create an initial config 1121 * i915_driver_load - setup chip and create an initial config
1087 * @dev: DRM device 1122 * @dev: DRM device
@@ -1098,6 +1133,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1098 struct drm_i915_private *dev_priv = dev->dev_private; 1133 struct drm_i915_private *dev_priv = dev->dev_private;
1099 resource_size_t base, size; 1134 resource_size_t base, size;
1100 int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1; 1135 int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
1136 uint32_t agp_size, prealloc_size;
1101 1137
1102 /* i915 has 4 more counters */ 1138 /* i915 has 4 more counters */
1103 dev->counters += 4; 1139 dev->counters += 4;
@@ -1146,9 +1182,22 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1146 "performance may suffer.\n"); 1182 "performance may suffer.\n");
1147 } 1183 }
1148 1184
1185 ret = i915_probe_agp(dev, &agp_size, &prealloc_size);
1186 if (ret)
1187 goto out_iomapfree;
1188
1149 /* enable GEM by default */ 1189 /* enable GEM by default */
1150 dev_priv->has_gem = 1; 1190 dev_priv->has_gem = 1;
1151 1191
1192 if (prealloc_size > agp_size * 3 / 4) {
1193 DRM_ERROR("Detected broken video BIOS with %d/%dkB of video "
1194 "memory stolen.\n",
1195 prealloc_size / 1024, agp_size / 1024);
1196 DRM_ERROR("Disabling GEM. (try reducing stolen memory or "
1197 "updating the BIOS to fix).\n");
1198 dev_priv->has_gem = 0;
1199 }
1200
1152 dev->driver->get_vblank_counter = i915_get_vblank_counter; 1201 dev->driver->get_vblank_counter = i915_get_vblank_counter;
1153 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 1202 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
1154 if (IS_G4X(dev) || IS_IGDNG(dev)) { 1203 if (IS_G4X(dev) || IS_IGDNG(dev)) {
@@ -1165,6 +1214,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1165 goto out_iomapfree; 1214 goto out_iomapfree;
1166 } 1215 }
1167 1216
1217 i915_get_mem_freq(dev);
1218
1168 /* On the 945G/GM, the chipset reports the MSI capability on the 1219 /* On the 945G/GM, the chipset reports the MSI capability on the
1169 * integrated graphics even though the support isn't actually there 1220 * integrated graphics even though the support isn't actually there
1170 * according to the published specs. It doesn't appear to function 1221 * according to the published specs. It doesn't appear to function
@@ -1180,6 +1231,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1180 pci_enable_msi(dev->pdev); 1231 pci_enable_msi(dev->pdev);
1181 1232
1182 spin_lock_init(&dev_priv->user_irq_lock); 1233 spin_lock_init(&dev_priv->user_irq_lock);
1234 spin_lock_init(&dev_priv->error_lock);
1183 dev_priv->user_irq_refcount = 0; 1235 dev_priv->user_irq_refcount = 0;
1184 1236
1185 ret = drm_vblank_init(dev, I915_NUM_PIPE); 1237 ret = drm_vblank_init(dev, I915_NUM_PIPE);
@@ -1190,7 +1242,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1190 } 1242 }
1191 1243
1192 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 1244 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
1193 ret = i915_load_modeset_init(dev); 1245 ret = i915_load_modeset_init(dev, prealloc_size, agp_size);
1194 if (ret < 0) { 1246 if (ret < 0) {
1195 DRM_ERROR("failed to init modeset\n"); 1247 DRM_ERROR("failed to init modeset\n");
1196 goto out_rmmap; 1248 goto out_rmmap;
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 98560e1e899a..fc4b68aa2d05 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -35,6 +35,7 @@
35 35
36#include "drm_pciids.h" 36#include "drm_pciids.h"
37#include <linux/console.h> 37#include <linux/console.h>
38#include "drm_crtc_helper.h"
38 39
39static unsigned int i915_modeset = -1; 40static unsigned int i915_modeset = -1;
40module_param_named(modeset, i915_modeset, int, 0400); 41module_param_named(modeset, i915_modeset, int, 0400);
@@ -57,8 +58,8 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
57 struct drm_i915_private *dev_priv = dev->dev_private; 58 struct drm_i915_private *dev_priv = dev->dev_private;
58 59
59 if (!dev || !dev_priv) { 60 if (!dev || !dev_priv) {
60 printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv); 61 DRM_ERROR("dev: %p, dev_priv: %p\n", dev, dev_priv);
61 printk(KERN_ERR "DRM not initialized, aborting suspend.\n"); 62 DRM_ERROR("DRM not initialized, aborting suspend.\n");
62 return -ENODEV; 63 return -ENODEV;
63 } 64 }
64 65
@@ -67,8 +68,6 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
67 68
68 pci_save_state(dev->pdev); 69 pci_save_state(dev->pdev);
69 70
70 i915_save_state(dev);
71
72 /* If KMS is active, we do the leavevt stuff here */ 71 /* If KMS is active, we do the leavevt stuff here */
73 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 72 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
74 if (i915_gem_idle(dev)) 73 if (i915_gem_idle(dev))
@@ -77,6 +76,8 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
77 drm_irq_uninstall(dev); 76 drm_irq_uninstall(dev);
78 } 77 }
79 78
79 i915_save_state(dev);
80
80 intel_opregion_free(dev, 1); 81 intel_opregion_free(dev, 1);
81 82
82 if (state.event == PM_EVENT_SUSPEND) { 83 if (state.event == PM_EVENT_SUSPEND) {
@@ -115,6 +116,10 @@ static int i915_resume(struct drm_device *dev)
115 116
116 drm_irq_install(dev); 117 drm_irq_install(dev);
117 } 118 }
119 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
120 /* Resume the modeset for every activated CRTC */
121 drm_helper_resume_force_mode(dev);
122 }
118 123
119 return ret; 124 return ret;
120} 125}
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 7a84f04e8439..d08752875885 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -133,6 +133,22 @@ struct sdvo_device_mapping {
133 u8 initialized; 133 u8 initialized;
134}; 134};
135 135
136struct drm_i915_error_state {
137 u32 eir;
138 u32 pgtbl_er;
139 u32 pipeastat;
140 u32 pipebstat;
141 u32 ipeir;
142 u32 ipehr;
143 u32 instdone;
144 u32 acthd;
145 u32 instpm;
146 u32 instps;
147 u32 instdone1;
148 u32 seqno;
149 struct timeval time;
150};
151
136typedef struct drm_i915_private { 152typedef struct drm_i915_private {
137 struct drm_device *dev; 153 struct drm_device *dev;
138 154
@@ -209,6 +225,11 @@ typedef struct drm_i915_private {
209 int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */ 225 int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
210 int num_fence_regs; /* 8 on pre-965, 16 otherwise */ 226 int num_fence_regs; /* 8 on pre-965, 16 otherwise */
211 227
228 unsigned int fsb_freq, mem_freq;
229
230 spinlock_t error_lock;
231 struct drm_i915_error_state *first_error;
232
212 /* Register state */ 233 /* Register state */
213 u8 saveLBB; 234 u8 saveLBB;
214 u32 saveDSPACNTR; 235 u32 saveDSPACNTR;
@@ -306,6 +327,17 @@ typedef struct drm_i915_private {
306 u32 saveCURBPOS; 327 u32 saveCURBPOS;
307 u32 saveCURBBASE; 328 u32 saveCURBBASE;
308 u32 saveCURSIZE; 329 u32 saveCURSIZE;
330 u32 saveDP_B;
331 u32 saveDP_C;
332 u32 saveDP_D;
333 u32 savePIPEA_GMCH_DATA_M;
334 u32 savePIPEB_GMCH_DATA_M;
335 u32 savePIPEA_GMCH_DATA_N;
336 u32 savePIPEB_GMCH_DATA_N;
337 u32 savePIPEA_DP_LINK_M;
338 u32 savePIPEB_DP_LINK_M;
339 u32 savePIPEA_DP_LINK_N;
340 u32 savePIPEB_DP_LINK_N;
309 341
310 struct { 342 struct {
311 struct drm_mm gtt_space; 343 struct drm_mm gtt_space;
@@ -457,9 +489,6 @@ struct drm_i915_gem_object {
457 */ 489 */
458 int fence_reg; 490 int fence_reg;
459 491
460 /** Boolean whether this object has a valid gtt offset. */
461 int gtt_bound;
462
463 /** How many users have pinned this object in GTT space */ 492 /** How many users have pinned this object in GTT space */
464 int pin_count; 493 int pin_count;
465 494
@@ -644,6 +673,7 @@ void i915_gem_free_object(struct drm_gem_object *obj);
644int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment); 673int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
645void i915_gem_object_unpin(struct drm_gem_object *obj); 674void i915_gem_object_unpin(struct drm_gem_object *obj);
646int i915_gem_object_unbind(struct drm_gem_object *obj); 675int i915_gem_object_unbind(struct drm_gem_object *obj);
676void i915_gem_release_mmap(struct drm_gem_object *obj);
647void i915_gem_lastclose(struct drm_device *dev); 677void i915_gem_lastclose(struct drm_device *dev);
648uint32_t i915_get_gem_seqno(struct drm_device *dev); 678uint32_t i915_get_gem_seqno(struct drm_device *dev);
649int i915_gem_object_get_fence_reg(struct drm_gem_object *obj); 679int i915_gem_object_get_fence_reg(struct drm_gem_object *obj);
@@ -857,7 +887,10 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
857#define HAS_128_BYTE_Y_TILING(dev) (IS_I9XX(dev) && !(IS_I915G(dev) || \ 887#define HAS_128_BYTE_Y_TILING(dev) (IS_I9XX(dev) && !(IS_I915G(dev) || \
858 IS_I915GM(dev))) 888 IS_I915GM(dev)))
859#define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IGDNG(dev)) 889#define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IGDNG(dev))
890#define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_IGDNG(dev))
860#define I915_HAS_HOTPLUG(dev) (IS_I945G(dev) || IS_I945GM(dev) || IS_I965G(dev)) 891#define I915_HAS_HOTPLUG(dev) (IS_I945G(dev) || IS_I945GM(dev) || IS_I965G(dev))
892/* dsparb controlled by hw only */
893#define DSPARB_HWCONTROL(dev) (IS_G4X(dev) || IS_IGDNG(dev))
861 894
862#define PRIMARY_RINGBUFFER_SIZE (128*1024) 895#define PRIMARY_RINGBUFFER_SIZE (128*1024)
863 896
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index fd2b8bdffe3f..5bf420378b6d 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1006,7 +1006,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1006 1006
1007 mutex_lock(&dev->struct_mutex); 1007 mutex_lock(&dev->struct_mutex);
1008#if WATCH_BUF 1008#if WATCH_BUF
1009 DRM_INFO("set_domain_ioctl %p(%d), %08x %08x\n", 1009 DRM_INFO("set_domain_ioctl %p(%zd), %08x %08x\n",
1010 obj, obj->size, read_domains, write_domain); 1010 obj, obj->size, read_domains, write_domain);
1011#endif 1011#endif
1012 if (read_domains & I915_GEM_DOMAIN_GTT) { 1012 if (read_domains & I915_GEM_DOMAIN_GTT) {
@@ -1050,7 +1050,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
1050 } 1050 }
1051 1051
1052#if WATCH_BUF 1052#if WATCH_BUF
1053 DRM_INFO("%s: sw_finish %d (%p %d)\n", 1053 DRM_INFO("%s: sw_finish %d (%p %zd)\n",
1054 __func__, args->handle, obj, obj->size); 1054 __func__, args->handle, obj, obj->size);
1055#endif 1055#endif
1056 obj_priv = obj->driver_private; 1056 obj_priv = obj->driver_private;
@@ -1252,6 +1252,31 @@ out_free_list:
1252 return ret; 1252 return ret;
1253} 1253}
1254 1254
1255/**
1256 * i915_gem_release_mmap - remove physical page mappings
1257 * @obj: obj in question
1258 *
1259 * Preserve the reservation of the mmaping with the DRM core code, but
1260 * relinquish ownership of the pages back to the system.
1261 *
1262 * It is vital that we remove the page mapping if we have mapped a tiled
1263 * object through the GTT and then lose the fence register due to
1264 * resource pressure. Similarly if the object has been moved out of the
1265 * aperture, than pages mapped into userspace must be revoked. Removing the
1266 * mapping will then trigger a page fault on the next user access, allowing
1267 * fixup by i915_gem_fault().
1268 */
1269void
1270i915_gem_release_mmap(struct drm_gem_object *obj)
1271{
1272 struct drm_device *dev = obj->dev;
1273 struct drm_i915_gem_object *obj_priv = obj->driver_private;
1274
1275 if (dev->dev_mapping)
1276 unmap_mapping_range(dev->dev_mapping,
1277 obj_priv->mmap_offset, obj->size, 1);
1278}
1279
1255static void 1280static void
1256i915_gem_free_mmap_offset(struct drm_gem_object *obj) 1281i915_gem_free_mmap_offset(struct drm_gem_object *obj)
1257{ 1282{
@@ -1861,7 +1886,6 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
1861{ 1886{
1862 struct drm_device *dev = obj->dev; 1887 struct drm_device *dev = obj->dev;
1863 struct drm_i915_gem_object *obj_priv = obj->driver_private; 1888 struct drm_i915_gem_object *obj_priv = obj->driver_private;
1864 loff_t offset;
1865 int ret = 0; 1889 int ret = 0;
1866 1890
1867#if WATCH_BUF 1891#if WATCH_BUF
@@ -1898,9 +1922,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
1898 BUG_ON(obj_priv->active); 1922 BUG_ON(obj_priv->active);
1899 1923
1900 /* blow away mappings if mapped through GTT */ 1924 /* blow away mappings if mapped through GTT */
1901 offset = ((loff_t) obj->map_list.hash.key) << PAGE_SHIFT; 1925 i915_gem_release_mmap(obj);
1902 if (dev->dev_mapping)
1903 unmap_mapping_range(dev->dev_mapping, offset, obj->size, 1);
1904 1926
1905 if (obj_priv->fence_reg != I915_FENCE_REG_NONE) 1927 if (obj_priv->fence_reg != I915_FENCE_REG_NONE)
1906 i915_gem_clear_fence_reg(obj); 1928 i915_gem_clear_fence_reg(obj);
@@ -2222,7 +2244,6 @@ try_again:
2222 /* None available, try to steal one or wait for a user to finish */ 2244 /* None available, try to steal one or wait for a user to finish */
2223 if (i == dev_priv->num_fence_regs) { 2245 if (i == dev_priv->num_fence_regs) {
2224 uint32_t seqno = dev_priv->mm.next_gem_seqno; 2246 uint32_t seqno = dev_priv->mm.next_gem_seqno;
2225 loff_t offset;
2226 2247
2227 if (avail == 0) 2248 if (avail == 0)
2228 return -ENOSPC; 2249 return -ENOSPC;
@@ -2274,10 +2295,7 @@ try_again:
2274 * Zap this virtual mapping so we can set up a fence again 2295 * Zap this virtual mapping so we can set up a fence again
2275 * for this object next time we need it. 2296 * for this object next time we need it.
2276 */ 2297 */
2277 offset = ((loff_t) reg->obj->map_list.hash.key) << PAGE_SHIFT; 2298 i915_gem_release_mmap(reg->obj);
2278 if (dev->dev_mapping)
2279 unmap_mapping_range(dev->dev_mapping, offset,
2280 reg->obj->size, 1);
2281 old_obj_priv->fence_reg = I915_FENCE_REG_NONE; 2299 old_obj_priv->fence_reg = I915_FENCE_REG_NONE;
2282 } 2300 }
2283 2301
@@ -2423,7 +2441,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
2423 } 2441 }
2424 2442
2425#if WATCH_BUF 2443#if WATCH_BUF
2426 DRM_INFO("Binding object of size %d at 0x%08x\n", 2444 DRM_INFO("Binding object of size %zd at 0x%08x\n",
2427 obj->size, obj_priv->gtt_offset); 2445 obj->size, obj_priv->gtt_offset);
2428#endif 2446#endif
2429 ret = i915_gem_object_get_pages(obj); 2447 ret = i915_gem_object_get_pages(obj);
@@ -4227,6 +4245,7 @@ i915_gem_lastclose(struct drm_device *dev)
4227void 4245void
4228i915_gem_load(struct drm_device *dev) 4246i915_gem_load(struct drm_device *dev)
4229{ 4247{
4248 int i;
4230 drm_i915_private_t *dev_priv = dev->dev_private; 4249 drm_i915_private_t *dev_priv = dev->dev_private;
4231 4250
4232 spin_lock_init(&dev_priv->mm.active_list_lock); 4251 spin_lock_init(&dev_priv->mm.active_list_lock);
@@ -4246,6 +4265,18 @@ i915_gem_load(struct drm_device *dev)
4246 else 4265 else
4247 dev_priv->num_fence_regs = 8; 4266 dev_priv->num_fence_regs = 8;
4248 4267
4268 /* Initialize fence registers to zero */
4269 if (IS_I965G(dev)) {
4270 for (i = 0; i < 16; i++)
4271 I915_WRITE64(FENCE_REG_965_0 + (i * 8), 0);
4272 } else {
4273 for (i = 0; i < 8; i++)
4274 I915_WRITE(FENCE_REG_830_0 + (i * 4), 0);
4275 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4276 for (i = 0; i < 8; i++)
4277 I915_WRITE(FENCE_REG_945_8 + (i * 4), 0);
4278 }
4279
4249 i915_gem_detect_bit_6_swizzle(dev); 4280 i915_gem_detect_bit_6_swizzle(dev);
4250} 4281}
4251 4282
diff --git a/drivers/gpu/drm/i915/i915_gem_debug.c b/drivers/gpu/drm/i915/i915_gem_debug.c
index 8d0b943e2c5a..e602614bd3f8 100644
--- a/drivers/gpu/drm/i915/i915_gem_debug.c
+++ b/drivers/gpu/drm/i915/i915_gem_debug.c
@@ -87,7 +87,7 @@ i915_gem_dump_object(struct drm_gem_object *obj, int len,
87 chunk_len = page_len - chunk; 87 chunk_len = page_len - chunk;
88 if (chunk_len > 128) 88 if (chunk_len > 128)
89 chunk_len = 128; 89 chunk_len = 128;
90 i915_gem_dump_page(obj_priv->page_list[page], 90 i915_gem_dump_page(obj_priv->pages[page],
91 chunk, chunk + chunk_len, 91 chunk, chunk + chunk_len,
92 obj_priv->gtt_offset + 92 obj_priv->gtt_offset +
93 page * PAGE_SIZE, 93 page * PAGE_SIZE,
@@ -143,7 +143,7 @@ i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle)
143 uint32_t *backing_map = NULL; 143 uint32_t *backing_map = NULL;
144 int bad_count = 0; 144 int bad_count = 0;
145 145
146 DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %dkb):\n", 146 DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %zdkb):\n",
147 __func__, obj, obj_priv->gtt_offset, handle, 147 __func__, obj, obj_priv->gtt_offset, handle,
148 obj->size / 1024); 148 obj->size / 1024);
149 149
@@ -157,7 +157,7 @@ i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle)
157 for (page = 0; page < obj->size / PAGE_SIZE; page++) { 157 for (page = 0; page < obj->size / PAGE_SIZE; page++) {
158 int i; 158 int i;
159 159
160 backing_map = kmap_atomic(obj_priv->page_list[page], KM_USER0); 160 backing_map = kmap_atomic(obj_priv->pages[page], KM_USER0);
161 161
162 if (backing_map == NULL) { 162 if (backing_map == NULL) {
163 DRM_ERROR("failed to map backing page\n"); 163 DRM_ERROR("failed to map backing page\n");
diff --git a/drivers/gpu/drm/i915/i915_gem_debugfs.c b/drivers/gpu/drm/i915/i915_gem_debugfs.c
index 28146e405e87..9a44bfcb8139 100644
--- a/drivers/gpu/drm/i915/i915_gem_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_gem_debugfs.c
@@ -75,11 +75,10 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
75 case ACTIVE_LIST: 75 case ACTIVE_LIST:
76 seq_printf(m, "Active:\n"); 76 seq_printf(m, "Active:\n");
77 lock = &dev_priv->mm.active_list_lock; 77 lock = &dev_priv->mm.active_list_lock;
78 spin_lock(lock);
79 head = &dev_priv->mm.active_list; 78 head = &dev_priv->mm.active_list;
80 break; 79 break;
81 case INACTIVE_LIST: 80 case INACTIVE_LIST:
82 seq_printf(m, "Inctive:\n"); 81 seq_printf(m, "Inactive:\n");
83 head = &dev_priv->mm.inactive_list; 82 head = &dev_priv->mm.inactive_list;
84 break; 83 break;
85 case FLUSHING_LIST: 84 case FLUSHING_LIST:
@@ -91,6 +90,8 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
91 return 0; 90 return 0;
92 } 91 }
93 92
93 if (lock)
94 spin_lock(lock);
94 list_for_each_entry(obj_priv, head, list) 95 list_for_each_entry(obj_priv, head, list)
95 { 96 {
96 struct drm_gem_object *obj = obj_priv->obj; 97 struct drm_gem_object *obj = obj_priv->obj;
@@ -104,7 +105,10 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
104 if (obj->name) 105 if (obj->name)
105 seq_printf(m, " (name: %d)", obj->name); 106 seq_printf(m, " (name: %d)", obj->name);
106 if (obj_priv->fence_reg != I915_FENCE_REG_NONE) 107 if (obj_priv->fence_reg != I915_FENCE_REG_NONE)
107 seq_printf(m, " (fence: %d)\n", obj_priv->fence_reg); 108 seq_printf(m, " (fence: %d)", obj_priv->fence_reg);
109 if (obj_priv->gtt_space != NULL)
110 seq_printf(m, " (gtt_offset: %08x)", obj_priv->gtt_offset);
111
108 seq_printf(m, "\n"); 112 seq_printf(m, "\n");
109 } 113 }
110 114
@@ -323,6 +327,39 @@ static int i915_ringbuffer_info(struct seq_file *m, void *data)
323 return 0; 327 return 0;
324} 328}
325 329
330static int i915_error_state(struct seq_file *m, void *unused)
331{
332 struct drm_info_node *node = (struct drm_info_node *) m->private;
333 struct drm_device *dev = node->minor->dev;
334 drm_i915_private_t *dev_priv = dev->dev_private;
335 struct drm_i915_error_state *error;
336 unsigned long flags;
337
338 spin_lock_irqsave(&dev_priv->error_lock, flags);
339 if (!dev_priv->first_error) {
340 seq_printf(m, "no error state collected\n");
341 goto out;
342 }
343
344 error = dev_priv->first_error;
345
346 seq_printf(m, "EIR: 0x%08x\n", error->eir);
347 seq_printf(m, " PGTBL_ER: 0x%08x\n", error->pgtbl_er);
348 seq_printf(m, " INSTPM: 0x%08x\n", error->instpm);
349 seq_printf(m, " IPEIR: 0x%08x\n", error->ipeir);
350 seq_printf(m, " IPEHR: 0x%08x\n", error->ipehr);
351 seq_printf(m, " INSTDONE: 0x%08x\n", error->instdone);
352 seq_printf(m, " ACTHD: 0x%08x\n", error->acthd);
353 if (IS_I965G(dev)) {
354 seq_printf(m, " INSTPS: 0x%08x\n", error->instps);
355 seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1);
356 }
357
358out:
359 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
360
361 return 0;
362}
326 363
327static struct drm_info_list i915_gem_debugfs_list[] = { 364static struct drm_info_list i915_gem_debugfs_list[] = {
328 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST}, 365 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
@@ -336,6 +373,7 @@ static struct drm_info_list i915_gem_debugfs_list[] = {
336 {"i915_ringbuffer_data", i915_ringbuffer_data, 0}, 373 {"i915_ringbuffer_data", i915_ringbuffer_data, 0},
337 {"i915_ringbuffer_info", i915_ringbuffer_info, 0}, 374 {"i915_ringbuffer_info", i915_ringbuffer_info, 0},
338 {"i915_batchbuffers", i915_batchbuffer_info, 0}, 375 {"i915_batchbuffers", i915_batchbuffer_info, 0},
376 {"i915_error_state", i915_error_state, 0},
339}; 377};
340#define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list) 378#define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list)
341 379
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 5c1ceec49f5b..a2d527b22ec4 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -114,11 +114,13 @@ intel_alloc_mchbar_resource(struct drm_device *dev)
114 mchbar_addr = ((u64)temp_hi << 32) | temp_lo; 114 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
115 115
116 /* If ACPI doesn't have it, assume we need to allocate it ourselves */ 116 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
117#ifdef CONFIG_PNP
117 if (mchbar_addr && 118 if (mchbar_addr &&
118 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) { 119 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) {
119 ret = 0; 120 ret = 0;
120 goto out_put; 121 goto out_put;
121 } 122 }
123#endif
122 124
123 /* Get some space for it */ 125 /* Get some space for it */
124 ret = pci_bus_alloc_resource(bridge_dev->bus, &dev_priv->mch_res, 126 ret = pci_bus_alloc_resource(bridge_dev->bus, &dev_priv->mch_res,
@@ -519,6 +521,12 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
519 goto err; 521 goto err;
520 } 522 }
521 523
524 /* If we've changed tiling, GTT-mappings of the object
525 * need to re-fault to ensure that the correct fence register
526 * setup is in place.
527 */
528 i915_gem_release_mmap(obj);
529
522 obj_priv->tiling_mode = args->tiling_mode; 530 obj_priv->tiling_mode = args->tiling_mode;
523 obj_priv->stride = args->stride; 531 obj_priv->stride = args->stride;
524 } 532 }
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index b86b7b7130c6..7ba23a69a0c0 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -26,6 +26,7 @@
26 * 26 *
27 */ 27 */
28 28
29#include <linux/sysrq.h>
29#include "drmP.h" 30#include "drmP.h"
30#include "drm.h" 31#include "drm.h"
31#include "i915_drm.h" 32#include "i915_drm.h"
@@ -41,9 +42,10 @@
41 * we leave them always unmasked in IMR and then control enabling them through 42 * we leave them always unmasked in IMR and then control enabling them through
42 * PIPESTAT alone. 43 * PIPESTAT alone.
43 */ 44 */
44#define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \ 45#define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \
45 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ 46 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
46 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT) 47 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
48 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
47 49
48/** Interrupts that we mask and unmask at runtime. */ 50/** Interrupts that we mask and unmask at runtime. */
49#define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT) 51#define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT)
@@ -232,7 +234,17 @@ static void i915_hotplug_work_func(struct work_struct *work)
232 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 234 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
233 hotplug_work); 235 hotplug_work);
234 struct drm_device *dev = dev_priv->dev; 236 struct drm_device *dev = dev_priv->dev;
235 237 struct drm_mode_config *mode_config = &dev->mode_config;
238 struct drm_connector *connector;
239
240 if (mode_config->num_connector) {
241 list_for_each_entry(connector, &mode_config->connector_list, head) {
242 struct intel_output *intel_output = to_intel_output(connector);
243
244 if (intel_output->hot_plug)
245 (*intel_output->hot_plug) (intel_output);
246 }
247 }
236 /* Just fire off a uevent and let userspace tell us what to do */ 248 /* Just fire off a uevent and let userspace tell us what to do */
237 drm_sysfs_hotplug_event(dev); 249 drm_sysfs_hotplug_event(dev);
238} 250}
@@ -278,6 +290,47 @@ irqreturn_t igdng_irq_handler(struct drm_device *dev)
278 return ret; 290 return ret;
279} 291}
280 292
293static void i915_capture_error_state(struct drm_device *dev)
294{
295 struct drm_i915_private *dev_priv = dev->dev_private;
296 struct drm_i915_error_state *error;
297 unsigned long flags;
298
299 spin_lock_irqsave(&dev_priv->error_lock, flags);
300 if (dev_priv->first_error)
301 goto out;
302
303 error = kmalloc(sizeof(*error), GFP_ATOMIC);
304 if (!error) {
305 DRM_DEBUG("out ot memory, not capturing error state\n");
306 goto out;
307 }
308
309 error->eir = I915_READ(EIR);
310 error->pgtbl_er = I915_READ(PGTBL_ER);
311 error->pipeastat = I915_READ(PIPEASTAT);
312 error->pipebstat = I915_READ(PIPEBSTAT);
313 error->instpm = I915_READ(INSTPM);
314 if (!IS_I965G(dev)) {
315 error->ipeir = I915_READ(IPEIR);
316 error->ipehr = I915_READ(IPEHR);
317 error->instdone = I915_READ(INSTDONE);
318 error->acthd = I915_READ(ACTHD);
319 } else {
320 error->ipeir = I915_READ(IPEIR_I965);
321 error->ipehr = I915_READ(IPEHR_I965);
322 error->instdone = I915_READ(INSTDONE_I965);
323 error->instps = I915_READ(INSTPS);
324 error->instdone1 = I915_READ(INSTDONE1);
325 error->acthd = I915_READ(ACTHD_I965);
326 }
327
328 dev_priv->first_error = error;
329
330out:
331 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
332}
333
281irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 334irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
282{ 335{
283 struct drm_device *dev = (struct drm_device *) arg; 336 struct drm_device *dev = (struct drm_device *) arg;
@@ -323,11 +376,15 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
323 * Clear the PIPE(A|B)STAT regs before the IIR 376 * Clear the PIPE(A|B)STAT regs before the IIR
324 */ 377 */
325 if (pipea_stats & 0x8000ffff) { 378 if (pipea_stats & 0x8000ffff) {
379 if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS)
380 DRM_DEBUG("pipe a underrun\n");
326 I915_WRITE(PIPEASTAT, pipea_stats); 381 I915_WRITE(PIPEASTAT, pipea_stats);
327 irq_received = 1; 382 irq_received = 1;
328 } 383 }
329 384
330 if (pipeb_stats & 0x8000ffff) { 385 if (pipeb_stats & 0x8000ffff) {
386 if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS)
387 DRM_DEBUG("pipe b underrun\n");
331 I915_WRITE(PIPEBSTAT, pipeb_stats); 388 I915_WRITE(PIPEBSTAT, pipeb_stats);
332 irq_received = 1; 389 irq_received = 1;
333 } 390 }
@@ -352,6 +409,80 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
352 I915_READ(PORT_HOTPLUG_STAT); 409 I915_READ(PORT_HOTPLUG_STAT);
353 } 410 }
354 411
412 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) {
413 u32 eir = I915_READ(EIR);
414
415 i915_capture_error_state(dev);
416
417 printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
418 eir);
419 if (eir & I915_ERROR_PAGE_TABLE) {
420 u32 pgtbl_err = I915_READ(PGTBL_ER);
421 printk(KERN_ERR "page table error\n");
422 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
423 pgtbl_err);
424 I915_WRITE(PGTBL_ER, pgtbl_err);
425 (void)I915_READ(PGTBL_ER);
426 }
427 if (eir & I915_ERROR_MEMORY_REFRESH) {
428 printk(KERN_ERR "memory refresh error\n");
429 printk(KERN_ERR "PIPEASTAT: 0x%08x\n",
430 pipea_stats);
431 printk(KERN_ERR "PIPEBSTAT: 0x%08x\n",
432 pipeb_stats);
433 /* pipestat has already been acked */
434 }
435 if (eir & I915_ERROR_INSTRUCTION) {
436 printk(KERN_ERR "instruction error\n");
437 printk(KERN_ERR " INSTPM: 0x%08x\n",
438 I915_READ(INSTPM));
439 if (!IS_I965G(dev)) {
440 u32 ipeir = I915_READ(IPEIR);
441
442 printk(KERN_ERR " IPEIR: 0x%08x\n",
443 I915_READ(IPEIR));
444 printk(KERN_ERR " IPEHR: 0x%08x\n",
445 I915_READ(IPEHR));
446 printk(KERN_ERR " INSTDONE: 0x%08x\n",
447 I915_READ(INSTDONE));
448 printk(KERN_ERR " ACTHD: 0x%08x\n",
449 I915_READ(ACTHD));
450 I915_WRITE(IPEIR, ipeir);
451 (void)I915_READ(IPEIR);
452 } else {
453 u32 ipeir = I915_READ(IPEIR_I965);
454
455 printk(KERN_ERR " IPEIR: 0x%08x\n",
456 I915_READ(IPEIR_I965));
457 printk(KERN_ERR " IPEHR: 0x%08x\n",
458 I915_READ(IPEHR_I965));
459 printk(KERN_ERR " INSTDONE: 0x%08x\n",
460 I915_READ(INSTDONE_I965));
461 printk(KERN_ERR " INSTPS: 0x%08x\n",
462 I915_READ(INSTPS));
463 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
464 I915_READ(INSTDONE1));
465 printk(KERN_ERR " ACTHD: 0x%08x\n",
466 I915_READ(ACTHD_I965));
467 I915_WRITE(IPEIR_I965, ipeir);
468 (void)I915_READ(IPEIR_I965);
469 }
470 }
471
472 I915_WRITE(EIR, eir);
473 (void)I915_READ(EIR);
474 eir = I915_READ(EIR);
475 if (eir) {
476 /*
477 * some errors might have become stuck,
478 * mask them.
479 */
480 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
481 I915_WRITE(EMR, I915_READ(EMR) | eir);
482 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
483 }
484 }
485
355 I915_WRITE(IIR, iir); 486 I915_WRITE(IIR, iir);
356 new_iir = I915_READ(IIR); /* Flush posted writes */ 487 new_iir = I915_READ(IIR); /* Flush posted writes */
357 488
@@ -722,6 +853,7 @@ int i915_driver_irq_postinstall(struct drm_device *dev)
722{ 853{
723 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 854 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
724 u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; 855 u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
856 u32 error_mask;
725 857
726 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); 858 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
727 859
@@ -758,6 +890,21 @@ int i915_driver_irq_postinstall(struct drm_device *dev)
758 i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT); 890 i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT);
759 } 891 }
760 892
893 /*
894 * Enable some error detection, note the instruction error mask
895 * bit is reserved, so we leave it masked.
896 */
897 if (IS_G4X(dev)) {
898 error_mask = ~(GM45_ERROR_PAGE_TABLE |
899 GM45_ERROR_MEM_PRIV |
900 GM45_ERROR_CP_PRIV |
901 I915_ERROR_MEMORY_REFRESH);
902 } else {
903 error_mask = ~(I915_ERROR_PAGE_TABLE |
904 I915_ERROR_MEMORY_REFRESH);
905 }
906 I915_WRITE(EMR, error_mask);
907
761 /* Disable pipe interrupt enables, clear pending pipe status */ 908 /* Disable pipe interrupt enables, clear pending pipe status */
762 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); 909 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
763 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); 910 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index f6237a0b1133..6c0858484094 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -206,6 +206,7 @@
206/* 206/*
207 * Instruction and interrupt control regs 207 * Instruction and interrupt control regs
208 */ 208 */
209#define PGTBL_ER 0x02024
209#define PRB0_TAIL 0x02030 210#define PRB0_TAIL 0x02030
210#define PRB0_HEAD 0x02034 211#define PRB0_HEAD 0x02034
211#define PRB0_START 0x02038 212#define PRB0_START 0x02038
@@ -226,11 +227,18 @@
226#define PRB1_HEAD 0x02044 /* 915+ only */ 227#define PRB1_HEAD 0x02044 /* 915+ only */
227#define PRB1_START 0x02048 /* 915+ only */ 228#define PRB1_START 0x02048 /* 915+ only */
228#define PRB1_CTL 0x0204c /* 915+ only */ 229#define PRB1_CTL 0x0204c /* 915+ only */
230#define IPEIR_I965 0x02064
231#define IPEHR_I965 0x02068
232#define INSTDONE_I965 0x0206c
233#define INSTPS 0x02070 /* 965+ only */
234#define INSTDONE1 0x0207c /* 965+ only */
229#define ACTHD_I965 0x02074 235#define ACTHD_I965 0x02074
230#define HWS_PGA 0x02080 236#define HWS_PGA 0x02080
231#define HWS_ADDRESS_MASK 0xfffff000 237#define HWS_ADDRESS_MASK 0xfffff000
232#define HWS_START_ADDRESS_SHIFT 4 238#define HWS_START_ADDRESS_SHIFT 4
233#define IPEIR 0x02088 239#define IPEIR 0x02088
240#define IPEHR 0x0208c
241#define INSTDONE 0x02090
234#define NOPID 0x02094 242#define NOPID 0x02094
235#define HWSTAM 0x02098 243#define HWSTAM 0x02098
236#define SCPD0 0x0209c /* 915+ only */ 244#define SCPD0 0x0209c /* 915+ only */
@@ -258,10 +266,22 @@
258#define EIR 0x020b0 266#define EIR 0x020b0
259#define EMR 0x020b4 267#define EMR 0x020b4
260#define ESR 0x020b8 268#define ESR 0x020b8
269#define GM45_ERROR_PAGE_TABLE (1<<5)
270#define GM45_ERROR_MEM_PRIV (1<<4)
271#define I915_ERROR_PAGE_TABLE (1<<4)
272#define GM45_ERROR_CP_PRIV (1<<3)
273#define I915_ERROR_MEMORY_REFRESH (1<<1)
274#define I915_ERROR_INSTRUCTION (1<<0)
261#define INSTPM 0x020c0 275#define INSTPM 0x020c0
262#define ACTHD 0x020c8 276#define ACTHD 0x020c8
263#define FW_BLC 0x020d8 277#define FW_BLC 0x020d8
278#define FW_BLC2 0x020dc
264#define FW_BLC_SELF 0x020e0 /* 915+ only */ 279#define FW_BLC_SELF 0x020e0 /* 915+ only */
280#define FW_BLC_SELF_EN (1<<15)
281#define MM_BURST_LENGTH 0x00700000
282#define MM_FIFO_WATERMARK 0x0001F000
283#define LM_BURST_LENGTH 0x00000700
284#define LM_FIFO_WATERMARK 0x0000001F
265#define MI_ARB_STATE 0x020e4 /* 915+ only */ 285#define MI_ARB_STATE 0x020e4 /* 915+ only */
266#define CACHE_MODE_0 0x02120 /* 915+ only */ 286#define CACHE_MODE_0 0x02120 /* 915+ only */
267#define CM0_MASK_SHIFT 16 287#define CM0_MASK_SHIFT 16
@@ -569,6 +589,23 @@
569#define C0DRB3 0x10206 589#define C0DRB3 0x10206
570#define C1DRB3 0x10606 590#define C1DRB3 0x10606
571 591
592/* Clocking configuration register */
593#define CLKCFG 0x10c00
594#define CLKCFG_FSB_400 (5 << 0) /* hrawclk 100 */
595#define CLKCFG_FSB_533 (1 << 0) /* hrawclk 133 */
596#define CLKCFG_FSB_667 (3 << 0) /* hrawclk 166 */
597#define CLKCFG_FSB_800 (2 << 0) /* hrawclk 200 */
598#define CLKCFG_FSB_1067 (6 << 0) /* hrawclk 266 */
599#define CLKCFG_FSB_1333 (7 << 0) /* hrawclk 333 */
600/* Note, below two are guess */
601#define CLKCFG_FSB_1600 (4 << 0) /* hrawclk 400 */
602#define CLKCFG_FSB_1600_ALT (0 << 0) /* hrawclk 400 */
603#define CLKCFG_FSB_MASK (7 << 0)
604#define CLKCFG_MEM_533 (1 << 4)
605#define CLKCFG_MEM_667 (2 << 4)
606#define CLKCFG_MEM_800 (3 << 4)
607#define CLKCFG_MEM_MASK (7 << 4)
608
572/** GM965 GM45 render standby register */ 609/** GM965 GM45 render standby register */
573#define MCHBAR_RENDER_STANDBY 0x111B8 610#define MCHBAR_RENDER_STANDBY 0x111B8
574 611
@@ -834,9 +871,25 @@
834#define HORIZ_INTERP_MASK (3 << 6) 871#define HORIZ_INTERP_MASK (3 << 6)
835#define HORIZ_AUTO_SCALE (1 << 5) 872#define HORIZ_AUTO_SCALE (1 << 5)
836#define PANEL_8TO6_DITHER_ENABLE (1 << 3) 873#define PANEL_8TO6_DITHER_ENABLE (1 << 3)
874#define PFIT_FILTER_FUZZY (0 << 24)
875#define PFIT_SCALING_AUTO (0 << 26)
876#define PFIT_SCALING_PROGRAMMED (1 << 26)
877#define PFIT_SCALING_PILLAR (2 << 26)
878#define PFIT_SCALING_LETTER (3 << 26)
837#define PFIT_PGM_RATIOS 0x61234 879#define PFIT_PGM_RATIOS 0x61234
838#define PFIT_VERT_SCALE_MASK 0xfff00000 880#define PFIT_VERT_SCALE_MASK 0xfff00000
839#define PFIT_HORIZ_SCALE_MASK 0x0000fff0 881#define PFIT_HORIZ_SCALE_MASK 0x0000fff0
882/* Pre-965 */
883#define PFIT_VERT_SCALE_SHIFT 20
884#define PFIT_VERT_SCALE_MASK 0xfff00000
885#define PFIT_HORIZ_SCALE_SHIFT 4
886#define PFIT_HORIZ_SCALE_MASK 0x0000fff0
887/* 965+ */
888#define PFIT_VERT_SCALE_SHIFT_965 16
889#define PFIT_VERT_SCALE_MASK_965 0x1fff0000
890#define PFIT_HORIZ_SCALE_SHIFT_965 0
891#define PFIT_HORIZ_SCALE_MASK_965 0x00001fff
892
840#define PFIT_AUTO_RATIOS 0x61238 893#define PFIT_AUTO_RATIOS 0x61238
841 894
842/* Backlight control */ 895/* Backlight control */
@@ -1552,6 +1605,34 @@
1552#define DSPARB_CSTART_SHIFT 7 1605#define DSPARB_CSTART_SHIFT 7
1553#define DSPARB_BSTART_MASK (0x7f) 1606#define DSPARB_BSTART_MASK (0x7f)
1554#define DSPARB_BSTART_SHIFT 0 1607#define DSPARB_BSTART_SHIFT 0
1608#define DSPARB_BEND_SHIFT 9 /* on 855 */
1609#define DSPARB_AEND_SHIFT 0
1610
1611#define DSPFW1 0x70034
1612#define DSPFW2 0x70038
1613#define DSPFW3 0x7003c
1614#define IGD_SELF_REFRESH_EN (1<<30)
1615
1616/* FIFO watermark sizes etc */
1617#define I915_FIFO_LINE_SIZE 64
1618#define I830_FIFO_LINE_SIZE 32
1619#define I945_FIFO_SIZE 127 /* 945 & 965 */
1620#define I915_FIFO_SIZE 95
1621#define I855GM_FIFO_SIZE 255
1622#define I830_FIFO_SIZE 95
1623#define I915_MAX_WM 0x3f
1624
1625#define IGD_DISPLAY_FIFO 512 /* in 64byte unit */
1626#define IGD_FIFO_LINE_SIZE 64
1627#define IGD_MAX_WM 0x1ff
1628#define IGD_DFT_WM 0x3f
1629#define IGD_DFT_HPLLOFF_WM 0
1630#define IGD_GUARD_WM 10
1631#define IGD_CURSOR_FIFO 64
1632#define IGD_CURSOR_MAX_WM 0x3f
1633#define IGD_CURSOR_DFT_WM 0
1634#define IGD_CURSOR_GUARD_WM 5
1635
1555/* 1636/*
1556 * The two pipe frame counter registers are not synchronized, so 1637 * The two pipe frame counter registers are not synchronized, so
1557 * reading a stable value is somewhat tricky. The following code 1638 * reading a stable value is somewhat tricky. The following code
diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c
index a98e2831ed31..9e1d16e5c3ea 100644
--- a/drivers/gpu/drm/i915/i915_suspend.c
+++ b/drivers/gpu/drm/i915/i915_suspend.c
@@ -222,23 +222,12 @@ static void i915_restore_vga(struct drm_device *dev)
222 I915_WRITE8(VGA_DACMASK, dev_priv->saveDACMASK); 222 I915_WRITE8(VGA_DACMASK, dev_priv->saveDACMASK);
223} 223}
224 224
225int i915_save_state(struct drm_device *dev) 225static void i915_save_modeset_reg(struct drm_device *dev)
226{ 226{
227 struct drm_i915_private *dev_priv = dev->dev_private; 227 struct drm_i915_private *dev_priv = dev->dev_private;
228 int i;
229
230 pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
231
232 /* Render Standby */
233 if (IS_I965G(dev) && IS_MOBILE(dev))
234 dev_priv->saveRENDERSTANDBY = I915_READ(MCHBAR_RENDER_STANDBY);
235
236 /* Hardware status page */
237 dev_priv->saveHWS = I915_READ(HWS_PGA);
238
239 /* Display arbitration control */
240 dev_priv->saveDSPARB = I915_READ(DSPARB);
241 228
229 if (drm_core_check_feature(dev, DRIVER_MODESET))
230 return;
242 /* Pipe & plane A info */ 231 /* Pipe & plane A info */
243 dev_priv->savePIPEACONF = I915_READ(PIPEACONF); 232 dev_priv->savePIPEACONF = I915_READ(PIPEACONF);
244 dev_priv->savePIPEASRC = I915_READ(PIPEASRC); 233 dev_priv->savePIPEASRC = I915_READ(PIPEASRC);
@@ -294,7 +283,122 @@ int i915_save_state(struct drm_device *dev)
294 } 283 }
295 i915_save_palette(dev, PIPE_B); 284 i915_save_palette(dev, PIPE_B);
296 dev_priv->savePIPEBSTAT = I915_READ(PIPEBSTAT); 285 dev_priv->savePIPEBSTAT = I915_READ(PIPEBSTAT);
286 return;
287}
288static void i915_restore_modeset_reg(struct drm_device *dev)
289{
290 struct drm_i915_private *dev_priv = dev->dev_private;
291
292 if (drm_core_check_feature(dev, DRIVER_MODESET))
293 return;
294
295 /* Pipe & plane A info */
296 /* Prime the clock */
297 if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
298 I915_WRITE(DPLL_A, dev_priv->saveDPLL_A &
299 ~DPLL_VCO_ENABLE);
300 DRM_UDELAY(150);
301 }
302 I915_WRITE(FPA0, dev_priv->saveFPA0);
303 I915_WRITE(FPA1, dev_priv->saveFPA1);
304 /* Actually enable it */
305 I915_WRITE(DPLL_A, dev_priv->saveDPLL_A);
306 DRM_UDELAY(150);
307 if (IS_I965G(dev))
308 I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
309 DRM_UDELAY(150);
310
311 /* Restore mode */
312 I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
313 I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
314 I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
315 I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
316 I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
317 I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
318 I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
319
320 /* Restore plane info */
321 I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
322 I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
323 I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
324 I915_WRITE(DSPAADDR, dev_priv->saveDSPAADDR);
325 I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
326 if (IS_I965G(dev)) {
327 I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
328 I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
329 }
330
331 I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
332
333 i915_restore_palette(dev, PIPE_A);
334 /* Enable the plane */
335 I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
336 I915_WRITE(DSPAADDR, I915_READ(DSPAADDR));
337
338 /* Pipe & plane B info */
339 if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
340 I915_WRITE(DPLL_B, dev_priv->saveDPLL_B &
341 ~DPLL_VCO_ENABLE);
342 DRM_UDELAY(150);
343 }
344 I915_WRITE(FPB0, dev_priv->saveFPB0);
345 I915_WRITE(FPB1, dev_priv->saveFPB1);
346 /* Actually enable it */
347 I915_WRITE(DPLL_B, dev_priv->saveDPLL_B);
348 DRM_UDELAY(150);
349 if (IS_I965G(dev))
350 I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
351 DRM_UDELAY(150);
352
353 /* Restore mode */
354 I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
355 I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
356 I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
357 I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
358 I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
359 I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
360 I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
361
362 /* Restore plane info */
363 I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
364 I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
365 I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
366 I915_WRITE(DSPBADDR, dev_priv->saveDSPBADDR);
367 I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
368 if (IS_I965G(dev)) {
369 I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
370 I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
371 }
372
373 I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
374
375 i915_restore_palette(dev, PIPE_B);
376 /* Enable the plane */
377 I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
378 I915_WRITE(DSPBADDR, I915_READ(DSPBADDR));
297 379
380 return;
381}
382int i915_save_state(struct drm_device *dev)
383{
384 struct drm_i915_private *dev_priv = dev->dev_private;
385 int i;
386
387 pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
388
389 /* Render Standby */
390 if (IS_I965G(dev) && IS_MOBILE(dev))
391 dev_priv->saveRENDERSTANDBY = I915_READ(MCHBAR_RENDER_STANDBY);
392
393 /* Hardware status page */
394 dev_priv->saveHWS = I915_READ(HWS_PGA);
395
396 /* Display arbitration control */
397 dev_priv->saveDSPARB = I915_READ(DSPARB);
398
399 /* This is only meaningful in non-KMS mode */
400 /* Don't save them in KMS mode */
401 i915_save_modeset_reg(dev);
298 /* Cursor state */ 402 /* Cursor state */
299 dev_priv->saveCURACNTR = I915_READ(CURACNTR); 403 dev_priv->saveCURACNTR = I915_READ(CURACNTR);
300 dev_priv->saveCURAPOS = I915_READ(CURAPOS); 404 dev_priv->saveCURAPOS = I915_READ(CURAPOS);
@@ -322,6 +426,20 @@ int i915_save_state(struct drm_device *dev)
322 dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS); 426 dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
323 dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR); 427 dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR);
324 428
429 /* Display Port state */
430 if (SUPPORTS_INTEGRATED_DP(dev)) {
431 dev_priv->saveDP_B = I915_READ(DP_B);
432 dev_priv->saveDP_C = I915_READ(DP_C);
433 dev_priv->saveDP_D = I915_READ(DP_D);
434 dev_priv->savePIPEA_GMCH_DATA_M = I915_READ(PIPEA_GMCH_DATA_M);
435 dev_priv->savePIPEB_GMCH_DATA_M = I915_READ(PIPEB_GMCH_DATA_M);
436 dev_priv->savePIPEA_GMCH_DATA_N = I915_READ(PIPEA_GMCH_DATA_N);
437 dev_priv->savePIPEB_GMCH_DATA_N = I915_READ(PIPEB_GMCH_DATA_N);
438 dev_priv->savePIPEA_DP_LINK_M = I915_READ(PIPEA_DP_LINK_M);
439 dev_priv->savePIPEB_DP_LINK_M = I915_READ(PIPEB_DP_LINK_M);
440 dev_priv->savePIPEA_DP_LINK_N = I915_READ(PIPEA_DP_LINK_N);
441 dev_priv->savePIPEB_DP_LINK_N = I915_READ(PIPEB_DP_LINK_N);
442 }
325 /* FIXME: save TV & SDVO state */ 443 /* FIXME: save TV & SDVO state */
326 444
327 /* FBC state */ 445 /* FBC state */
@@ -404,92 +522,21 @@ int i915_restore_state(struct drm_device *dev)
404 for (i = 0; i < 8; i++) 522 for (i = 0; i < 8; i++)
405 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]); 523 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]);
406 } 524 }
407 525
408 /* Pipe & plane A info */ 526 /* Display port ratios (must be done before clock is set) */
409 /* Prime the clock */ 527 if (SUPPORTS_INTEGRATED_DP(dev)) {
410 if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) { 528 I915_WRITE(PIPEA_GMCH_DATA_M, dev_priv->savePIPEA_GMCH_DATA_M);
411 I915_WRITE(DPLL_A, dev_priv->saveDPLL_A & 529 I915_WRITE(PIPEB_GMCH_DATA_M, dev_priv->savePIPEB_GMCH_DATA_M);
412 ~DPLL_VCO_ENABLE); 530 I915_WRITE(PIPEA_GMCH_DATA_N, dev_priv->savePIPEA_GMCH_DATA_N);
413 DRM_UDELAY(150); 531 I915_WRITE(PIPEB_GMCH_DATA_N, dev_priv->savePIPEB_GMCH_DATA_N);
532 I915_WRITE(PIPEA_DP_LINK_M, dev_priv->savePIPEA_DP_LINK_M);
533 I915_WRITE(PIPEB_DP_LINK_M, dev_priv->savePIPEB_DP_LINK_M);
534 I915_WRITE(PIPEA_DP_LINK_N, dev_priv->savePIPEA_DP_LINK_N);
535 I915_WRITE(PIPEB_DP_LINK_N, dev_priv->savePIPEB_DP_LINK_N);
414 } 536 }
415 I915_WRITE(FPA0, dev_priv->saveFPA0); 537 /* This is only meaningful in non-KMS mode */
416 I915_WRITE(FPA1, dev_priv->saveFPA1); 538 /* Don't restore them in KMS mode */
417 /* Actually enable it */ 539 i915_restore_modeset_reg(dev);
418 I915_WRITE(DPLL_A, dev_priv->saveDPLL_A);
419 DRM_UDELAY(150);
420 if (IS_I965G(dev))
421 I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
422 DRM_UDELAY(150);
423
424 /* Restore mode */
425 I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
426 I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
427 I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
428 I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
429 I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
430 I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
431 I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
432
433 /* Restore plane info */
434 I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
435 I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
436 I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
437 I915_WRITE(DSPAADDR, dev_priv->saveDSPAADDR);
438 I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
439 if (IS_I965G(dev)) {
440 I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
441 I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
442 }
443
444 I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
445
446 i915_restore_palette(dev, PIPE_A);
447 /* Enable the plane */
448 I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
449 I915_WRITE(DSPAADDR, I915_READ(DSPAADDR));
450
451 /* Pipe & plane B info */
452 if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
453 I915_WRITE(DPLL_B, dev_priv->saveDPLL_B &
454 ~DPLL_VCO_ENABLE);
455 DRM_UDELAY(150);
456 }
457 I915_WRITE(FPB0, dev_priv->saveFPB0);
458 I915_WRITE(FPB1, dev_priv->saveFPB1);
459 /* Actually enable it */
460 I915_WRITE(DPLL_B, dev_priv->saveDPLL_B);
461 DRM_UDELAY(150);
462 if (IS_I965G(dev))
463 I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
464 DRM_UDELAY(150);
465
466 /* Restore mode */
467 I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
468 I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
469 I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
470 I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
471 I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
472 I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
473 I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
474
475 /* Restore plane info */
476 I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
477 I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
478 I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
479 I915_WRITE(DSPBADDR, dev_priv->saveDSPBADDR);
480 I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
481 if (IS_I965G(dev)) {
482 I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
483 I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
484 }
485
486 I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
487
488 i915_restore_palette(dev, PIPE_B);
489 /* Enable the plane */
490 I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
491 I915_WRITE(DSPBADDR, I915_READ(DSPBADDR));
492
493 /* Cursor state */ 540 /* Cursor state */
494 I915_WRITE(CURAPOS, dev_priv->saveCURAPOS); 541 I915_WRITE(CURAPOS, dev_priv->saveCURAPOS);
495 I915_WRITE(CURACNTR, dev_priv->saveCURACNTR); 542 I915_WRITE(CURACNTR, dev_priv->saveCURACNTR);
@@ -518,6 +565,12 @@ int i915_restore_state(struct drm_device *dev)
518 I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR); 565 I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR);
519 I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL); 566 I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
520 567
568 /* Display Port state */
569 if (SUPPORTS_INTEGRATED_DP(dev)) {
570 I915_WRITE(DP_B, dev_priv->saveDP_B);
571 I915_WRITE(DP_C, dev_priv->saveDP_C);
572 I915_WRITE(DP_D, dev_priv->saveDP_D);
573 }
521 /* FIXME: restore TV & SDVO state */ 574 /* FIXME: restore TV & SDVO state */
522 575
523 /* FBC info */ 576 /* FBC info */
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index cdd126d068a7..7cc447191028 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -97,11 +97,14 @@ static void
97parse_lfp_panel_data(struct drm_i915_private *dev_priv, 97parse_lfp_panel_data(struct drm_i915_private *dev_priv,
98 struct bdb_header *bdb) 98 struct bdb_header *bdb)
99{ 99{
100 struct drm_device *dev = dev_priv->dev;
100 struct bdb_lvds_options *lvds_options; 101 struct bdb_lvds_options *lvds_options;
101 struct bdb_lvds_lfp_data *lvds_lfp_data; 102 struct bdb_lvds_lfp_data *lvds_lfp_data;
103 struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
102 struct bdb_lvds_lfp_data_entry *entry; 104 struct bdb_lvds_lfp_data_entry *entry;
103 struct lvds_dvo_timing *dvo_timing; 105 struct lvds_dvo_timing *dvo_timing;
104 struct drm_display_mode *panel_fixed_mode; 106 struct drm_display_mode *panel_fixed_mode;
107 int lfp_data_size;
105 108
106 /* Defaults if we can't find VBT info */ 109 /* Defaults if we can't find VBT info */
107 dev_priv->lvds_dither = 0; 110 dev_priv->lvds_dither = 0;
@@ -119,10 +122,25 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv,
119 if (!lvds_lfp_data) 122 if (!lvds_lfp_data)
120 return; 123 return;
121 124
125 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
126 if (!lvds_lfp_data_ptrs)
127 return;
128
122 dev_priv->lvds_vbt = 1; 129 dev_priv->lvds_vbt = 1;
123 130
124 entry = &lvds_lfp_data->data[lvds_options->panel_type]; 131 lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
125 dvo_timing = &entry->dvo_timing; 132 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
133 entry = (struct bdb_lvds_lfp_data_entry *)
134 ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
135 lvds_options->panel_type));
136
137 /* On IGDNG mobile, LVDS data block removes panel fitting registers.
138 So dec 2 dword from dvo_timing offset */
139 if (IS_IGDNG(dev))
140 dvo_timing = (struct lvds_dvo_timing *)
141 ((u8 *)&entry->dvo_timing - 8);
142 else
143 dvo_timing = &entry->dvo_timing;
126 144
127 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); 145 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
128 146
@@ -185,10 +203,12 @@ parse_general_features(struct drm_i915_private *dev_priv,
185 dev_priv->lvds_use_ssc = general->enable_ssc; 203 dev_priv->lvds_use_ssc = general->enable_ssc;
186 204
187 if (dev_priv->lvds_use_ssc) { 205 if (dev_priv->lvds_use_ssc) {
188 if (IS_I855(dev_priv->dev)) 206 if (IS_I85X(dev_priv->dev))
189 dev_priv->lvds_ssc_freq = general->ssc_freq ? 66 : 48; 207 dev_priv->lvds_ssc_freq =
190 else 208 general->ssc_freq ? 66 : 48;
191 dev_priv->lvds_ssc_freq = general->ssc_freq ? 100 : 96; 209 else
210 dev_priv->lvds_ssc_freq =
211 general->ssc_freq ? 100 : 96;
192 } 212 }
193 } 213 }
194} 214}
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 6de97fc66029..d6a1a6e5539a 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -46,7 +46,7 @@ static void intel_crt_dpms(struct drm_encoder *encoder, int mode)
46 46
47 temp = I915_READ(reg); 47 temp = I915_READ(reg);
48 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE); 48 temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
49 temp |= ADPA_DAC_ENABLE; 49 temp &= ~ADPA_DAC_ENABLE;
50 50
51 switch(mode) { 51 switch(mode) {
52 case DRM_MODE_DPMS_ON: 52 case DRM_MODE_DPMS_ON:
@@ -428,8 +428,34 @@ static void intel_crt_destroy(struct drm_connector *connector)
428 428
429static int intel_crt_get_modes(struct drm_connector *connector) 429static int intel_crt_get_modes(struct drm_connector *connector)
430{ 430{
431 int ret;
431 struct intel_output *intel_output = to_intel_output(connector); 432 struct intel_output *intel_output = to_intel_output(connector);
432 return intel_ddc_get_modes(intel_output); 433 struct i2c_adapter *ddcbus;
434 struct drm_device *dev = connector->dev;
435
436
437 ret = intel_ddc_get_modes(intel_output);
438 if (ret || !IS_G4X(dev))
439 goto end;
440
441 ddcbus = intel_output->ddc_bus;
442 /* Try to probe digital port for output in DVI-I -> VGA mode. */
443 intel_output->ddc_bus =
444 intel_i2c_create(connector->dev, GPIOD, "CRTDDC_D");
445
446 if (!intel_output->ddc_bus) {
447 intel_output->ddc_bus = ddcbus;
448 dev_printk(KERN_ERR, &connector->dev->pdev->dev,
449 "DDC bus registration failed for CRTDDC_D.\n");
450 goto end;
451 }
452 /* Try to get modes by GPIOD port */
453 ret = intel_ddc_get_modes(intel_output);
454 intel_i2c_destroy(ddcbus);
455
456end:
457 return ret;
458
433} 459}
434 460
435static int intel_crt_set_property(struct drm_connector *connector, 461static int intel_crt_set_property(struct drm_connector *connector,
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 3e1c78162119..508838ee31e0 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -25,14 +25,17 @@
25 */ 25 */
26 26
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/kernel.h>
28#include "drmP.h" 29#include "drmP.h"
29#include "intel_drv.h" 30#include "intel_drv.h"
30#include "i915_drm.h" 31#include "i915_drm.h"
31#include "i915_drv.h" 32#include "i915_drv.h"
33#include "intel_dp.h"
32 34
33#include "drm_crtc_helper.h" 35#include "drm_crtc_helper.h"
34 36
35bool intel_pipe_has_type (struct drm_crtc *crtc, int type); 37bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
38static void intel_update_watermarks(struct drm_device *dev);
36 39
37typedef struct { 40typedef struct {
38 /* given values */ 41 /* given values */
@@ -127,19 +130,6 @@ struct intel_limit {
127#define I9XX_P2_LVDS_FAST 7 130#define I9XX_P2_LVDS_FAST 7
128#define I9XX_P2_LVDS_SLOW_LIMIT 112000 131#define I9XX_P2_LVDS_SLOW_LIMIT 112000
129 132
130#define INTEL_LIMIT_I8XX_DVO_DAC 0
131#define INTEL_LIMIT_I8XX_LVDS 1
132#define INTEL_LIMIT_I9XX_SDVO_DAC 2
133#define INTEL_LIMIT_I9XX_LVDS 3
134#define INTEL_LIMIT_G4X_SDVO 4
135#define INTEL_LIMIT_G4X_HDMI_DAC 5
136#define INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS 6
137#define INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS 7
138#define INTEL_LIMIT_IGD_SDVO_DAC 8
139#define INTEL_LIMIT_IGD_LVDS 9
140#define INTEL_LIMIT_IGDNG_SDVO_DAC 10
141#define INTEL_LIMIT_IGDNG_LVDS 11
142
143/*The parameter is for SDVO on G4x platform*/ 133/*The parameter is for SDVO on G4x platform*/
144#define G4X_DOT_SDVO_MIN 25000 134#define G4X_DOT_SDVO_MIN 25000
145#define G4X_DOT_SDVO_MAX 270000 135#define G4X_DOT_SDVO_MAX 270000
@@ -218,6 +208,25 @@ struct intel_limit {
218#define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7 208#define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
219#define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0 209#define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
220 210
211/*The parameter is for DISPLAY PORT on G4x platform*/
212#define G4X_DOT_DISPLAY_PORT_MIN 161670
213#define G4X_DOT_DISPLAY_PORT_MAX 227000
214#define G4X_N_DISPLAY_PORT_MIN 1
215#define G4X_N_DISPLAY_PORT_MAX 2
216#define G4X_M_DISPLAY_PORT_MIN 97
217#define G4X_M_DISPLAY_PORT_MAX 108
218#define G4X_M1_DISPLAY_PORT_MIN 0x10
219#define G4X_M1_DISPLAY_PORT_MAX 0x12
220#define G4X_M2_DISPLAY_PORT_MIN 0x05
221#define G4X_M2_DISPLAY_PORT_MAX 0x06
222#define G4X_P_DISPLAY_PORT_MIN 10
223#define G4X_P_DISPLAY_PORT_MAX 20
224#define G4X_P1_DISPLAY_PORT_MIN 1
225#define G4X_P1_DISPLAY_PORT_MAX 2
226#define G4X_P2_DISPLAY_PORT_SLOW 10
227#define G4X_P2_DISPLAY_PORT_FAST 10
228#define G4X_P2_DISPLAY_PORT_LIMIT 0
229
221/* IGDNG */ 230/* IGDNG */
222/* as we calculate clock using (register_value + 2) for 231/* as we calculate clock using (register_value + 2) for
223 N/M1/M2, so here the range value for them is (actual_value-2). 232 N/M1/M2, so here the range value for them is (actual_value-2).
@@ -256,8 +265,11 @@ static bool
256intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, 265intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
257 int target, int refclk, intel_clock_t *best_clock); 266 int target, int refclk, intel_clock_t *best_clock);
258 267
259static const intel_limit_t intel_limits[] = { 268static bool
260 { /* INTEL_LIMIT_I8XX_DVO_DAC */ 269intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
270 int target, int refclk, intel_clock_t *best_clock);
271
272static const intel_limit_t intel_limits_i8xx_dvo = {
261 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, 273 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
262 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, 274 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
263 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, 275 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
@@ -269,8 +281,9 @@ static const intel_limit_t intel_limits[] = {
269 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, 281 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
270 .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST }, 282 .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
271 .find_pll = intel_find_best_PLL, 283 .find_pll = intel_find_best_PLL,
272 }, 284};
273 { /* INTEL_LIMIT_I8XX_LVDS */ 285
286static const intel_limit_t intel_limits_i8xx_lvds = {
274 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, 287 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
275 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, 288 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
276 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, 289 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
@@ -282,8 +295,9 @@ static const intel_limit_t intel_limits[] = {
282 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, 295 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
283 .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST }, 296 .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
284 .find_pll = intel_find_best_PLL, 297 .find_pll = intel_find_best_PLL,
285 }, 298};
286 { /* INTEL_LIMIT_I9XX_SDVO_DAC */ 299
300static const intel_limit_t intel_limits_i9xx_sdvo = {
287 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 301 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
288 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, 302 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
289 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, 303 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
@@ -295,8 +309,9 @@ static const intel_limit_t intel_limits[] = {
295 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, 309 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
296 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, 310 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
297 .find_pll = intel_find_best_PLL, 311 .find_pll = intel_find_best_PLL,
298 }, 312};
299 { /* INTEL_LIMIT_I9XX_LVDS */ 313
314static const intel_limit_t intel_limits_i9xx_lvds = {
300 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 315 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
301 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, 316 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
302 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, 317 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
@@ -311,9 +326,10 @@ static const intel_limit_t intel_limits[] = {
311 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, 326 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
312 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST }, 327 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
313 .find_pll = intel_find_best_PLL, 328 .find_pll = intel_find_best_PLL,
314 }, 329};
330
315 /* below parameter and function is for G4X Chipset Family*/ 331 /* below parameter and function is for G4X Chipset Family*/
316 { /* INTEL_LIMIT_G4X_SDVO */ 332static const intel_limit_t intel_limits_g4x_sdvo = {
317 .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX }, 333 .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
318 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, 334 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
319 .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX }, 335 .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
@@ -327,8 +343,9 @@ static const intel_limit_t intel_limits[] = {
327 .p2_fast = G4X_P2_SDVO_FAST 343 .p2_fast = G4X_P2_SDVO_FAST
328 }, 344 },
329 .find_pll = intel_g4x_find_best_PLL, 345 .find_pll = intel_g4x_find_best_PLL,
330 }, 346};
331 { /* INTEL_LIMIT_G4X_HDMI_DAC */ 347
348static const intel_limit_t intel_limits_g4x_hdmi = {
332 .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX }, 349 .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
333 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, 350 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
334 .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX }, 351 .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
@@ -342,8 +359,9 @@ static const intel_limit_t intel_limits[] = {
342 .p2_fast = G4X_P2_HDMI_DAC_FAST 359 .p2_fast = G4X_P2_HDMI_DAC_FAST
343 }, 360 },
344 .find_pll = intel_g4x_find_best_PLL, 361 .find_pll = intel_g4x_find_best_PLL,
345 }, 362};
346 { /* INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS */ 363
364static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
347 .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN, 365 .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
348 .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX }, 366 .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
349 .vco = { .min = G4X_VCO_MIN, 367 .vco = { .min = G4X_VCO_MIN,
@@ -365,8 +383,9 @@ static const intel_limit_t intel_limits[] = {
365 .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST 383 .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
366 }, 384 },
367 .find_pll = intel_g4x_find_best_PLL, 385 .find_pll = intel_g4x_find_best_PLL,
368 }, 386};
369 { /* INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS */ 387
388static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
370 .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN, 389 .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
371 .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX }, 390 .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
372 .vco = { .min = G4X_VCO_MIN, 391 .vco = { .min = G4X_VCO_MIN,
@@ -388,8 +407,32 @@ static const intel_limit_t intel_limits[] = {
388 .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST 407 .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
389 }, 408 },
390 .find_pll = intel_g4x_find_best_PLL, 409 .find_pll = intel_g4x_find_best_PLL,
391 }, 410};
392 { /* INTEL_LIMIT_IGD_SDVO */ 411
412static const intel_limit_t intel_limits_g4x_display_port = {
413 .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
414 .max = G4X_DOT_DISPLAY_PORT_MAX },
415 .vco = { .min = G4X_VCO_MIN,
416 .max = G4X_VCO_MAX},
417 .n = { .min = G4X_N_DISPLAY_PORT_MIN,
418 .max = G4X_N_DISPLAY_PORT_MAX },
419 .m = { .min = G4X_M_DISPLAY_PORT_MIN,
420 .max = G4X_M_DISPLAY_PORT_MAX },
421 .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
422 .max = G4X_M1_DISPLAY_PORT_MAX },
423 .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
424 .max = G4X_M2_DISPLAY_PORT_MAX },
425 .p = { .min = G4X_P_DISPLAY_PORT_MIN,
426 .max = G4X_P_DISPLAY_PORT_MAX },
427 .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
428 .max = G4X_P1_DISPLAY_PORT_MAX},
429 .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
430 .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
431 .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
432 .find_pll = intel_find_pll_g4x_dp,
433};
434
435static const intel_limit_t intel_limits_igd_sdvo = {
393 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX}, 436 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
394 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, 437 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
395 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, 438 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
@@ -401,8 +444,9 @@ static const intel_limit_t intel_limits[] = {
401 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, 444 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
402 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, 445 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
403 .find_pll = intel_find_best_PLL, 446 .find_pll = intel_find_best_PLL,
404 }, 447};
405 { /* INTEL_LIMIT_IGD_LVDS */ 448
449static const intel_limit_t intel_limits_igd_lvds = {
406 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 450 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
407 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, 451 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
408 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, 452 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
@@ -415,8 +459,9 @@ static const intel_limit_t intel_limits[] = {
415 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, 459 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
416 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW }, 460 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
417 .find_pll = intel_find_best_PLL, 461 .find_pll = intel_find_best_PLL,
418 }, 462};
419 { /* INTEL_LIMIT_IGDNG_SDVO_DAC */ 463
464static const intel_limit_t intel_limits_igdng_sdvo = {
420 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, 465 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
421 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, 466 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
422 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, 467 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
@@ -429,8 +474,9 @@ static const intel_limit_t intel_limits[] = {
429 .p2_slow = IGDNG_P2_SDVO_DAC_SLOW, 474 .p2_slow = IGDNG_P2_SDVO_DAC_SLOW,
430 .p2_fast = IGDNG_P2_SDVO_DAC_FAST }, 475 .p2_fast = IGDNG_P2_SDVO_DAC_FAST },
431 .find_pll = intel_igdng_find_best_PLL, 476 .find_pll = intel_igdng_find_best_PLL,
432 }, 477};
433 { /* INTEL_LIMIT_IGDNG_LVDS */ 478
479static const intel_limit_t intel_limits_igdng_lvds = {
434 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, 480 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
435 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, 481 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
436 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, 482 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
@@ -443,16 +489,15 @@ static const intel_limit_t intel_limits[] = {
443 .p2_slow = IGDNG_P2_LVDS_SLOW, 489 .p2_slow = IGDNG_P2_LVDS_SLOW,
444 .p2_fast = IGDNG_P2_LVDS_FAST }, 490 .p2_fast = IGDNG_P2_LVDS_FAST },
445 .find_pll = intel_igdng_find_best_PLL, 491 .find_pll = intel_igdng_find_best_PLL,
446 },
447}; 492};
448 493
449static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc) 494static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc)
450{ 495{
451 const intel_limit_t *limit; 496 const intel_limit_t *limit;
452 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 497 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
453 limit = &intel_limits[INTEL_LIMIT_IGDNG_LVDS]; 498 limit = &intel_limits_igdng_lvds;
454 else 499 else
455 limit = &intel_limits[INTEL_LIMIT_IGDNG_SDVO_DAC]; 500 limit = &intel_limits_igdng_sdvo;
456 501
457 return limit; 502 return limit;
458} 503}
@@ -467,19 +512,19 @@ static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
467 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == 512 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
468 LVDS_CLKB_POWER_UP) 513 LVDS_CLKB_POWER_UP)
469 /* LVDS with dual channel */ 514 /* LVDS with dual channel */
470 limit = &intel_limits 515 limit = &intel_limits_g4x_dual_channel_lvds;
471 [INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS];
472 else 516 else
473 /* LVDS with dual channel */ 517 /* LVDS with dual channel */
474 limit = &intel_limits 518 limit = &intel_limits_g4x_single_channel_lvds;
475 [INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS];
476 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || 519 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
477 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { 520 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
478 limit = &intel_limits[INTEL_LIMIT_G4X_HDMI_DAC]; 521 limit = &intel_limits_g4x_hdmi;
479 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { 522 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
480 limit = &intel_limits[INTEL_LIMIT_G4X_SDVO]; 523 limit = &intel_limits_g4x_sdvo;
524 } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
525 limit = &intel_limits_g4x_display_port;
481 } else /* The option is for other outputs */ 526 } else /* The option is for other outputs */
482 limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC]; 527 limit = &intel_limits_i9xx_sdvo;
483 528
484 return limit; 529 return limit;
485} 530}
@@ -495,19 +540,19 @@ static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
495 limit = intel_g4x_limit(crtc); 540 limit = intel_g4x_limit(crtc);
496 } else if (IS_I9XX(dev) && !IS_IGD(dev)) { 541 } else if (IS_I9XX(dev) && !IS_IGD(dev)) {
497 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 542 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
498 limit = &intel_limits[INTEL_LIMIT_I9XX_LVDS]; 543 limit = &intel_limits_i9xx_lvds;
499 else 544 else
500 limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC]; 545 limit = &intel_limits_i9xx_sdvo;
501 } else if (IS_IGD(dev)) { 546 } else if (IS_IGD(dev)) {
502 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 547 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
503 limit = &intel_limits[INTEL_LIMIT_IGD_LVDS]; 548 limit = &intel_limits_igd_lvds;
504 else 549 else
505 limit = &intel_limits[INTEL_LIMIT_IGD_SDVO_DAC]; 550 limit = &intel_limits_igd_sdvo;
506 } else { 551 } else {
507 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 552 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
508 limit = &intel_limits[INTEL_LIMIT_I8XX_LVDS]; 553 limit = &intel_limits_i8xx_lvds;
509 else 554 else
510 limit = &intel_limits[INTEL_LIMIT_I8XX_DVO_DAC]; 555 limit = &intel_limits_i8xx_dvo;
511 } 556 }
512 return limit; 557 return limit;
513} 558}
@@ -764,6 +809,32 @@ out:
764 return found; 809 return found;
765} 810}
766 811
812/* DisplayPort has only two frequencies, 162MHz and 270MHz */
813static bool
814intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
815 int target, int refclk, intel_clock_t *best_clock)
816{
817 intel_clock_t clock;
818 if (target < 200000) {
819 clock.p1 = 2;
820 clock.p2 = 10;
821 clock.n = 2;
822 clock.m1 = 23;
823 clock.m2 = 8;
824 } else {
825 clock.p1 = 1;
826 clock.p2 = 10;
827 clock.n = 1;
828 clock.m1 = 14;
829 clock.m2 = 2;
830 }
831 clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
832 clock.p = (clock.p1 * clock.p2);
833 clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
834 memcpy(best_clock, &clock, sizeof(intel_clock_t));
835 return true;
836}
837
767void 838void
768intel_wait_for_vblank(struct drm_device *dev) 839intel_wait_for_vblank(struct drm_device *dev)
769{ 840{
@@ -933,7 +1004,7 @@ static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode)
933 struct drm_i915_private *dev_priv = dev->dev_private; 1004 struct drm_i915_private *dev_priv = dev->dev_private;
934 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 1005 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
935 int pipe = intel_crtc->pipe; 1006 int pipe = intel_crtc->pipe;
936 int plane = intel_crtc->pipe; 1007 int plane = intel_crtc->plane;
937 int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; 1008 int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
938 int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; 1009 int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
939 int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR; 1010 int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
@@ -1263,8 +1334,10 @@ static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
1263 1334
1264 /* Give the overlay scaler a chance to enable if it's on this pipe */ 1335 /* Give the overlay scaler a chance to enable if it's on this pipe */
1265 //intel_crtc_dpms_video(crtc, true); TODO 1336 //intel_crtc_dpms_video(crtc, true); TODO
1337 intel_update_watermarks(dev);
1266 break; 1338 break;
1267 case DRM_MODE_DPMS_OFF: 1339 case DRM_MODE_DPMS_OFF:
1340 intel_update_watermarks(dev);
1268 /* Give the overlay scaler a chance to disable if it's on this pipe */ 1341 /* Give the overlay scaler a chance to disable if it's on this pipe */
1269 //intel_crtc_dpms_video(crtc, FALSE); TODO 1342 //intel_crtc_dpms_video(crtc, FALSE); TODO
1270 1343
@@ -1443,7 +1516,6 @@ static int intel_get_core_clock_speed(struct drm_device *dev)
1443 return 0; /* Silence gcc warning */ 1516 return 0; /* Silence gcc warning */
1444} 1517}
1445 1518
1446
1447/** 1519/**
1448 * Return the pipe currently connected to the panel fitter, 1520 * Return the pipe currently connected to the panel fitter,
1449 * or -1 if the panel fitter is not present or not in use 1521 * or -1 if the panel fitter is not present or not in use
@@ -1502,7 +1574,7 @@ igdng_compute_m_n(int bytes_per_pixel, int nlanes,
1502 1574
1503 temp = (u64) DATA_N * pixel_clock; 1575 temp = (u64) DATA_N * pixel_clock;
1504 temp = div_u64(temp, link_clock); 1576 temp = div_u64(temp, link_clock);
1505 m_n->gmch_m = (temp * bytes_per_pixel) / nlanes; 1577 m_n->gmch_m = div_u64(temp * bytes_per_pixel, nlanes);
1506 m_n->gmch_n = DATA_N; 1578 m_n->gmch_n = DATA_N;
1507 fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); 1579 fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
1508 1580
@@ -1513,6 +1585,420 @@ igdng_compute_m_n(int bytes_per_pixel, int nlanes,
1513} 1585}
1514 1586
1515 1587
1588struct intel_watermark_params {
1589 unsigned long fifo_size;
1590 unsigned long max_wm;
1591 unsigned long default_wm;
1592 unsigned long guard_size;
1593 unsigned long cacheline_size;
1594};
1595
1596/* IGD has different values for various configs */
1597static struct intel_watermark_params igd_display_wm = {
1598 IGD_DISPLAY_FIFO,
1599 IGD_MAX_WM,
1600 IGD_DFT_WM,
1601 IGD_GUARD_WM,
1602 IGD_FIFO_LINE_SIZE
1603};
1604static struct intel_watermark_params igd_display_hplloff_wm = {
1605 IGD_DISPLAY_FIFO,
1606 IGD_MAX_WM,
1607 IGD_DFT_HPLLOFF_WM,
1608 IGD_GUARD_WM,
1609 IGD_FIFO_LINE_SIZE
1610};
1611static struct intel_watermark_params igd_cursor_wm = {
1612 IGD_CURSOR_FIFO,
1613 IGD_CURSOR_MAX_WM,
1614 IGD_CURSOR_DFT_WM,
1615 IGD_CURSOR_GUARD_WM,
1616 IGD_FIFO_LINE_SIZE,
1617};
1618static struct intel_watermark_params igd_cursor_hplloff_wm = {
1619 IGD_CURSOR_FIFO,
1620 IGD_CURSOR_MAX_WM,
1621 IGD_CURSOR_DFT_WM,
1622 IGD_CURSOR_GUARD_WM,
1623 IGD_FIFO_LINE_SIZE
1624};
1625static struct intel_watermark_params i945_wm_info = {
1626 I915_FIFO_LINE_SIZE,
1627 I915_MAX_WM,
1628 1,
1629 0,
1630 IGD_FIFO_LINE_SIZE
1631};
1632static struct intel_watermark_params i915_wm_info = {
1633 I945_FIFO_SIZE,
1634 I915_MAX_WM,
1635 1,
1636 0,
1637 I915_FIFO_LINE_SIZE
1638};
1639static struct intel_watermark_params i855_wm_info = {
1640 I855GM_FIFO_SIZE,
1641 I915_MAX_WM,
1642 1,
1643 0,
1644 I830_FIFO_LINE_SIZE
1645};
1646static struct intel_watermark_params i830_wm_info = {
1647 I830_FIFO_SIZE,
1648 I915_MAX_WM,
1649 1,
1650 0,
1651 I830_FIFO_LINE_SIZE
1652};
1653
1654static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
1655 struct intel_watermark_params *wm,
1656 int pixel_size,
1657 unsigned long latency_ns)
1658{
1659 unsigned long bytes_required, wm_size;
1660
1661 bytes_required = (clock_in_khz * pixel_size * latency_ns) / 1000000;
1662 bytes_required /= wm->cacheline_size;
1663 wm_size = wm->fifo_size - bytes_required - wm->guard_size;
1664
1665 if (wm_size > wm->max_wm)
1666 wm_size = wm->max_wm;
1667 if (wm_size == 0)
1668 wm_size = wm->default_wm;
1669 return wm_size;
1670}
1671
1672struct cxsr_latency {
1673 int is_desktop;
1674 unsigned long fsb_freq;
1675 unsigned long mem_freq;
1676 unsigned long display_sr;
1677 unsigned long display_hpll_disable;
1678 unsigned long cursor_sr;
1679 unsigned long cursor_hpll_disable;
1680};
1681
1682static struct cxsr_latency cxsr_latency_table[] = {
1683 {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
1684 {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
1685 {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
1686
1687 {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
1688 {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
1689 {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
1690
1691 {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
1692 {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
1693 {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
1694
1695 {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
1696 {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
1697 {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
1698
1699 {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
1700 {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
1701 {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
1702
1703 {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
1704 {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
1705 {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
1706};
1707
1708static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb,
1709 int mem)
1710{
1711 int i;
1712 struct cxsr_latency *latency;
1713
1714 if (fsb == 0 || mem == 0)
1715 return NULL;
1716
1717 for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
1718 latency = &cxsr_latency_table[i];
1719 if (is_desktop == latency->is_desktop &&
1720 fsb == latency->fsb_freq && mem == latency->mem_freq)
1721 break;
1722 }
1723 if (i >= ARRAY_SIZE(cxsr_latency_table)) {
1724 DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
1725 return NULL;
1726 }
1727 return latency;
1728}
1729
1730static void igd_disable_cxsr(struct drm_device *dev)
1731{
1732 struct drm_i915_private *dev_priv = dev->dev_private;
1733 u32 reg;
1734
1735 /* deactivate cxsr */
1736 reg = I915_READ(DSPFW3);
1737 reg &= ~(IGD_SELF_REFRESH_EN);
1738 I915_WRITE(DSPFW3, reg);
1739 DRM_INFO("Big FIFO is disabled\n");
1740}
1741
1742static void igd_enable_cxsr(struct drm_device *dev, unsigned long clock,
1743 int pixel_size)
1744{
1745 struct drm_i915_private *dev_priv = dev->dev_private;
1746 u32 reg;
1747 unsigned long wm;
1748 struct cxsr_latency *latency;
1749
1750 latency = intel_get_cxsr_latency(IS_IGDG(dev), dev_priv->fsb_freq,
1751 dev_priv->mem_freq);
1752 if (!latency) {
1753 DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
1754 igd_disable_cxsr(dev);
1755 return;
1756 }
1757
1758 /* Display SR */
1759 wm = intel_calculate_wm(clock, &igd_display_wm, pixel_size,
1760 latency->display_sr);
1761 reg = I915_READ(DSPFW1);
1762 reg &= 0x7fffff;
1763 reg |= wm << 23;
1764 I915_WRITE(DSPFW1, reg);
1765 DRM_DEBUG("DSPFW1 register is %x\n", reg);
1766
1767 /* cursor SR */
1768 wm = intel_calculate_wm(clock, &igd_cursor_wm, pixel_size,
1769 latency->cursor_sr);
1770 reg = I915_READ(DSPFW3);
1771 reg &= ~(0x3f << 24);
1772 reg |= (wm & 0x3f) << 24;
1773 I915_WRITE(DSPFW3, reg);
1774
1775 /* Display HPLL off SR */
1776 wm = intel_calculate_wm(clock, &igd_display_hplloff_wm,
1777 latency->display_hpll_disable, I915_FIFO_LINE_SIZE);
1778 reg = I915_READ(DSPFW3);
1779 reg &= 0xfffffe00;
1780 reg |= wm & 0x1ff;
1781 I915_WRITE(DSPFW3, reg);
1782
1783 /* cursor HPLL off SR */
1784 wm = intel_calculate_wm(clock, &igd_cursor_hplloff_wm, pixel_size,
1785 latency->cursor_hpll_disable);
1786 reg = I915_READ(DSPFW3);
1787 reg &= ~(0x3f << 16);
1788 reg |= (wm & 0x3f) << 16;
1789 I915_WRITE(DSPFW3, reg);
1790 DRM_DEBUG("DSPFW3 register is %x\n", reg);
1791
1792 /* activate cxsr */
1793 reg = I915_READ(DSPFW3);
1794 reg |= IGD_SELF_REFRESH_EN;
1795 I915_WRITE(DSPFW3, reg);
1796
1797 DRM_INFO("Big FIFO is enabled\n");
1798
1799 return;
1800}
1801
1802const static int latency_ns = 5000; /* default for non-igd platforms */
1803
1804
1805static void i965_update_wm(struct drm_device *dev)
1806{
1807 struct drm_i915_private *dev_priv = dev->dev_private;
1808
1809 DRM_DEBUG("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR 8\n");
1810
1811 /* 965 has limitations... */
1812 I915_WRITE(DSPFW1, (8 << 16) | (8 << 8) | (8 << 0));
1813 I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
1814}
1815
1816static void i9xx_update_wm(struct drm_device *dev, int planea_clock,
1817 int planeb_clock, int sr_hdisplay, int pixel_size)
1818{
1819 struct drm_i915_private *dev_priv = dev->dev_private;
1820 uint32_t fwater_lo = I915_READ(FW_BLC) & MM_FIFO_WATERMARK;
1821 uint32_t fwater_hi = I915_READ(FW_BLC2) & LM_FIFO_WATERMARK;
1822 int bsize, asize, cwm, bwm = 1, awm = 1, srwm = 1;
1823 uint32_t dsparb = I915_READ(DSPARB);
1824 int planea_entries, planeb_entries;
1825 struct intel_watermark_params *wm_params;
1826 unsigned long line_time_us;
1827 int sr_clock, sr_entries = 0;
1828
1829 if (IS_I965GM(dev) || IS_I945GM(dev))
1830 wm_params = &i945_wm_info;
1831 else if (IS_I9XX(dev))
1832 wm_params = &i915_wm_info;
1833 else
1834 wm_params = &i855_wm_info;
1835
1836 planea_entries = intel_calculate_wm(planea_clock, wm_params,
1837 pixel_size, latency_ns);
1838 planeb_entries = intel_calculate_wm(planeb_clock, wm_params,
1839 pixel_size, latency_ns);
1840
1841 DRM_DEBUG("FIFO entries - A: %d, B: %d\n", planea_entries,
1842 planeb_entries);
1843
1844 if (IS_I9XX(dev)) {
1845 asize = dsparb & 0x7f;
1846 bsize = (dsparb >> DSPARB_CSTART_SHIFT) & 0x7f;
1847 } else {
1848 asize = dsparb & 0x1ff;
1849 bsize = (dsparb >> DSPARB_BEND_SHIFT) & 0x1ff;
1850 }
1851 DRM_DEBUG("FIFO size - A: %d, B: %d\n", asize, bsize);
1852
1853 /* Two extra entries for padding */
1854 awm = asize - (planea_entries + 2);
1855 bwm = bsize - (planeb_entries + 2);
1856
1857 /* Sanity check against potentially bad FIFO allocations */
1858 if (awm <= 0) {
1859 /* pipe is on but has too few FIFO entries */
1860 if (planea_entries != 0)
1861 DRM_DEBUG("plane A needs more FIFO entries\n");
1862 awm = 1;
1863 }
1864 if (bwm <= 0) {
1865 if (planeb_entries != 0)
1866 DRM_DEBUG("plane B needs more FIFO entries\n");
1867 bwm = 1;
1868 }
1869
1870 /*
1871 * Overlay gets an aggressive default since video jitter is bad.
1872 */
1873 cwm = 2;
1874
1875 /* Calc sr entries for one pipe configs */
1876 if (!planea_clock || !planeb_clock) {
1877 sr_clock = planea_clock ? planea_clock : planeb_clock;
1878 line_time_us = (sr_hdisplay * 1000) / sr_clock;
1879 sr_entries = (((latency_ns / line_time_us) + 1) * pixel_size *
1880 sr_hdisplay) / 1000;
1881 sr_entries = roundup(sr_entries / wm_params->cacheline_size, 1);
1882 if (sr_entries < wm_params->fifo_size)
1883 srwm = wm_params->fifo_size - sr_entries;
1884 }
1885
1886 DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
1887 awm, bwm, cwm, srwm);
1888
1889 fwater_lo = fwater_lo | ((bwm & 0x3f) << 16) | (awm & 0x3f);
1890 fwater_hi = fwater_hi | (cwm & 0x1f);
1891
1892 I915_WRITE(FW_BLC, fwater_lo);
1893 I915_WRITE(FW_BLC2, fwater_hi);
1894 if (IS_I9XX(dev))
1895 I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f));
1896}
1897
1898static void i830_update_wm(struct drm_device *dev, int planea_clock,
1899 int pixel_size)
1900{
1901 struct drm_i915_private *dev_priv = dev->dev_private;
1902 uint32_t dsparb = I915_READ(DSPARB);
1903 uint32_t fwater_lo = I915_READ(FW_BLC) & MM_FIFO_WATERMARK;
1904 unsigned int asize, awm;
1905 int planea_entries;
1906
1907 planea_entries = intel_calculate_wm(planea_clock, &i830_wm_info,
1908 pixel_size, latency_ns);
1909
1910 asize = dsparb & 0x7f;
1911
1912 awm = asize - planea_entries;
1913
1914 fwater_lo = fwater_lo | awm;
1915
1916 I915_WRITE(FW_BLC, fwater_lo);
1917}
1918
1919/**
1920 * intel_update_watermarks - update FIFO watermark values based on current modes
1921 *
1922 * Calculate watermark values for the various WM regs based on current mode
1923 * and plane configuration.
1924 *
1925 * There are several cases to deal with here:
1926 * - normal (i.e. non-self-refresh)
1927 * - self-refresh (SR) mode
1928 * - lines are large relative to FIFO size (buffer can hold up to 2)
1929 * - lines are small relative to FIFO size (buffer can hold more than 2
1930 * lines), so need to account for TLB latency
1931 *
1932 * The normal calculation is:
1933 * watermark = dotclock * bytes per pixel * latency
1934 * where latency is platform & configuration dependent (we assume pessimal
1935 * values here).
1936 *
1937 * The SR calculation is:
1938 * watermark = (trunc(latency/line time)+1) * surface width *
1939 * bytes per pixel
1940 * where
1941 * line time = htotal / dotclock
1942 * and latency is assumed to be high, as above.
1943 *
1944 * The final value programmed to the register should always be rounded up,
1945 * and include an extra 2 entries to account for clock crossings.
1946 *
1947 * We don't use the sprite, so we can ignore that. And on Crestline we have
1948 * to set the non-SR watermarks to 8.
1949 */
1950static void intel_update_watermarks(struct drm_device *dev)
1951{
1952 struct drm_crtc *crtc;
1953 struct intel_crtc *intel_crtc;
1954 int sr_hdisplay = 0;
1955 unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0;
1956 int enabled = 0, pixel_size = 0;
1957
1958 if (DSPARB_HWCONTROL(dev))
1959 return;
1960
1961 /* Get the clock config from both planes */
1962 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1963 intel_crtc = to_intel_crtc(crtc);
1964 if (crtc->enabled) {
1965 enabled++;
1966 if (intel_crtc->plane == 0) {
1967 DRM_DEBUG("plane A (pipe %d) clock: %d\n",
1968 intel_crtc->pipe, crtc->mode.clock);
1969 planea_clock = crtc->mode.clock;
1970 } else {
1971 DRM_DEBUG("plane B (pipe %d) clock: %d\n",
1972 intel_crtc->pipe, crtc->mode.clock);
1973 planeb_clock = crtc->mode.clock;
1974 }
1975 sr_hdisplay = crtc->mode.hdisplay;
1976 sr_clock = crtc->mode.clock;
1977 if (crtc->fb)
1978 pixel_size = crtc->fb->bits_per_pixel / 8;
1979 else
1980 pixel_size = 4; /* by default */
1981 }
1982 }
1983
1984 if (enabled <= 0)
1985 return;
1986
1987 /* Single pipe configs can enable self refresh */
1988 if (enabled == 1 && IS_IGD(dev))
1989 igd_enable_cxsr(dev, sr_clock, pixel_size);
1990 else if (IS_IGD(dev))
1991 igd_disable_cxsr(dev);
1992
1993 if (IS_I965G(dev))
1994 i965_update_wm(dev);
1995 else if (IS_I9XX(dev) || IS_MOBILE(dev))
1996 i9xx_update_wm(dev, planea_clock, planeb_clock, sr_hdisplay,
1997 pixel_size);
1998 else
1999 i830_update_wm(dev, planea_clock, pixel_size);
2000}
2001
1516static int intel_crtc_mode_set(struct drm_crtc *crtc, 2002static int intel_crtc_mode_set(struct drm_crtc *crtc,
1517 struct drm_display_mode *mode, 2003 struct drm_display_mode *mode,
1518 struct drm_display_mode *adjusted_mode, 2004 struct drm_display_mode *adjusted_mode,
@@ -1541,7 +2027,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1541 intel_clock_t clock; 2027 intel_clock_t clock;
1542 u32 dpll = 0, fp = 0, dspcntr, pipeconf; 2028 u32 dpll = 0, fp = 0, dspcntr, pipeconf;
1543 bool ok, is_sdvo = false, is_dvo = false; 2029 bool ok, is_sdvo = false, is_dvo = false;
1544 bool is_crt = false, is_lvds = false, is_tv = false; 2030 bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
1545 struct drm_mode_config *mode_config = &dev->mode_config; 2031 struct drm_mode_config *mode_config = &dev->mode_config;
1546 struct drm_connector *connector; 2032 struct drm_connector *connector;
1547 const intel_limit_t *limit; 2033 const intel_limit_t *limit;
@@ -1585,6 +2071,9 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1585 case INTEL_OUTPUT_ANALOG: 2071 case INTEL_OUTPUT_ANALOG:
1586 is_crt = true; 2072 is_crt = true;
1587 break; 2073 break;
2074 case INTEL_OUTPUT_DISPLAYPORT:
2075 is_dp = true;
2076 break;
1588 } 2077 }
1589 2078
1590 num_outputs++; 2079 num_outputs++;
@@ -1600,6 +2089,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1600 } else { 2089 } else {
1601 refclk = 48000; 2090 refclk = 48000;
1602 } 2091 }
2092
1603 2093
1604 /* 2094 /*
1605 * Returns a set of divisors for the desired target clock with the given 2095 * Returns a set of divisors for the desired target clock with the given
@@ -1662,6 +2152,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1662 else if (IS_IGDNG(dev)) 2152 else if (IS_IGDNG(dev))
1663 dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; 2153 dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
1664 } 2154 }
2155 if (is_dp)
2156 dpll |= DPLL_DVO_HIGH_SPEED;
1665 2157
1666 /* compute bitmask from p1 value */ 2158 /* compute bitmask from p1 value */
1667 if (IS_IGD(dev)) 2159 if (IS_IGD(dev))
@@ -1809,6 +2301,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1809 I915_WRITE(lvds_reg, lvds); 2301 I915_WRITE(lvds_reg, lvds);
1810 I915_READ(lvds_reg); 2302 I915_READ(lvds_reg);
1811 } 2303 }
2304 if (is_dp)
2305 intel_dp_set_m_n(crtc, mode, adjusted_mode);
1812 2306
1813 I915_WRITE(fp_reg, fp); 2307 I915_WRITE(fp_reg, fp);
1814 I915_WRITE(dpll_reg, dpll); 2308 I915_WRITE(dpll_reg, dpll);
@@ -1871,6 +2365,9 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1871 2365
1872 /* Flush the plane changes */ 2366 /* Flush the plane changes */
1873 ret = intel_pipe_set_base(crtc, x, y, old_fb); 2367 ret = intel_pipe_set_base(crtc, x, y, old_fb);
2368
2369 intel_update_watermarks(dev);
2370
1874 drm_vblank_post_modeset(dev, pipe); 2371 drm_vblank_post_modeset(dev, pipe);
1875 2372
1876 return ret; 2373 return ret;
@@ -2359,6 +2856,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
2359 2856
2360 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); 2857 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
2361 intel_crtc->pipe = pipe; 2858 intel_crtc->pipe = pipe;
2859 intel_crtc->plane = pipe;
2362 for (i = 0; i < 256; i++) { 2860 for (i = 0; i < 256; i++) {
2363 intel_crtc->lut_r[i] = i; 2861 intel_crtc->lut_r[i] = i;
2364 intel_crtc->lut_g[i] = i; 2862 intel_crtc->lut_g[i] = i;
@@ -2475,6 +2973,8 @@ static void intel_setup_outputs(struct drm_device *dev)
2475 found = intel_sdvo_init(dev, SDVOB); 2973 found = intel_sdvo_init(dev, SDVOB);
2476 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) 2974 if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
2477 intel_hdmi_init(dev, SDVOB); 2975 intel_hdmi_init(dev, SDVOB);
2976 if (!found && SUPPORTS_INTEGRATED_DP(dev))
2977 intel_dp_init(dev, DP_B);
2478 } 2978 }
2479 2979
2480 /* Before G4X SDVOC doesn't have its own detect register */ 2980 /* Before G4X SDVOC doesn't have its own detect register */
@@ -2487,7 +2987,11 @@ static void intel_setup_outputs(struct drm_device *dev)
2487 found = intel_sdvo_init(dev, SDVOC); 2987 found = intel_sdvo_init(dev, SDVOC);
2488 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) 2988 if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
2489 intel_hdmi_init(dev, SDVOC); 2989 intel_hdmi_init(dev, SDVOC);
2990 if (!found && SUPPORTS_INTEGRATED_DP(dev))
2991 intel_dp_init(dev, DP_C);
2490 } 2992 }
2993 if (SUPPORTS_INTEGRATED_DP(dev) && (I915_READ(DP_D) & DP_DETECTED))
2994 intel_dp_init(dev, DP_D);
2491 } else 2995 } else
2492 intel_dvo_init(dev); 2996 intel_dvo_init(dev);
2493 2997
@@ -2530,6 +3034,11 @@ static void intel_setup_outputs(struct drm_device *dev)
2530 (1 << 1)); 3034 (1 << 1));
2531 clone_mask = (1 << INTEL_OUTPUT_TVOUT); 3035 clone_mask = (1 << INTEL_OUTPUT_TVOUT);
2532 break; 3036 break;
3037 case INTEL_OUTPUT_DISPLAYPORT:
3038 crtc_mask = ((1 << 0) |
3039 (1 << 1));
3040 clone_mask = (1 << INTEL_OUTPUT_DISPLAYPORT);
3041 break;
2533 } 3042 }
2534 encoder->possible_crtcs = crtc_mask; 3043 encoder->possible_crtcs = crtc_mask;
2535 encoder->possible_clones = intel_connector_clones(dev, clone_mask); 3044 encoder->possible_clones = intel_connector_clones(dev, clone_mask);
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
new file mode 100644
index 000000000000..6770ae88370d
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -0,0 +1,1156 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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 DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
29#include "drmP.h"
30#include "drm.h"
31#include "drm_crtc.h"
32#include "drm_crtc_helper.h"
33#include "intel_drv.h"
34#include "i915_drm.h"
35#include "i915_drv.h"
36#include "intel_dp.h"
37
38#define DP_LINK_STATUS_SIZE 6
39#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
40
41#define DP_LINK_CONFIGURATION_SIZE 9
42
43struct intel_dp_priv {
44 uint32_t output_reg;
45 uint32_t DP;
46 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
47 uint32_t save_DP;
48 uint8_t save_link_configuration[DP_LINK_CONFIGURATION_SIZE];
49 bool has_audio;
50 int dpms_mode;
51 uint8_t link_bw;
52 uint8_t lane_count;
53 uint8_t dpcd[4];
54 struct intel_output *intel_output;
55 struct i2c_adapter adapter;
56 struct i2c_algo_dp_aux_data algo;
57};
58
59static void
60intel_dp_link_train(struct intel_output *intel_output, uint32_t DP,
61 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]);
62
63static void
64intel_dp_link_down(struct intel_output *intel_output, uint32_t DP);
65
66static int
67intel_dp_max_lane_count(struct intel_output *intel_output)
68{
69 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
70 int max_lane_count = 4;
71
72 if (dp_priv->dpcd[0] >= 0x11) {
73 max_lane_count = dp_priv->dpcd[2] & 0x1f;
74 switch (max_lane_count) {
75 case 1: case 2: case 4:
76 break;
77 default:
78 max_lane_count = 4;
79 }
80 }
81 return max_lane_count;
82}
83
84static int
85intel_dp_max_link_bw(struct intel_output *intel_output)
86{
87 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
88 int max_link_bw = dp_priv->dpcd[1];
89
90 switch (max_link_bw) {
91 case DP_LINK_BW_1_62:
92 case DP_LINK_BW_2_7:
93 break;
94 default:
95 max_link_bw = DP_LINK_BW_1_62;
96 break;
97 }
98 return max_link_bw;
99}
100
101static int
102intel_dp_link_clock(uint8_t link_bw)
103{
104 if (link_bw == DP_LINK_BW_2_7)
105 return 270000;
106 else
107 return 162000;
108}
109
110/* I think this is a fiction */
111static int
112intel_dp_link_required(int pixel_clock)
113{
114 return pixel_clock * 3;
115}
116
117static int
118intel_dp_mode_valid(struct drm_connector *connector,
119 struct drm_display_mode *mode)
120{
121 struct intel_output *intel_output = to_intel_output(connector);
122 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_output));
123 int max_lanes = intel_dp_max_lane_count(intel_output);
124
125 if (intel_dp_link_required(mode->clock) > max_link_clock * max_lanes)
126 return MODE_CLOCK_HIGH;
127
128 if (mode->clock < 10000)
129 return MODE_CLOCK_LOW;
130
131 return MODE_OK;
132}
133
134static uint32_t
135pack_aux(uint8_t *src, int src_bytes)
136{
137 int i;
138 uint32_t v = 0;
139
140 if (src_bytes > 4)
141 src_bytes = 4;
142 for (i = 0; i < src_bytes; i++)
143 v |= ((uint32_t) src[i]) << ((3-i) * 8);
144 return v;
145}
146
147static void
148unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
149{
150 int i;
151 if (dst_bytes > 4)
152 dst_bytes = 4;
153 for (i = 0; i < dst_bytes; i++)
154 dst[i] = src >> ((3-i) * 8);
155}
156
157/* hrawclock is 1/4 the FSB frequency */
158static int
159intel_hrawclk(struct drm_device *dev)
160{
161 struct drm_i915_private *dev_priv = dev->dev_private;
162 uint32_t clkcfg;
163
164 clkcfg = I915_READ(CLKCFG);
165 switch (clkcfg & CLKCFG_FSB_MASK) {
166 case CLKCFG_FSB_400:
167 return 100;
168 case CLKCFG_FSB_533:
169 return 133;
170 case CLKCFG_FSB_667:
171 return 166;
172 case CLKCFG_FSB_800:
173 return 200;
174 case CLKCFG_FSB_1067:
175 return 266;
176 case CLKCFG_FSB_1333:
177 return 333;
178 /* these two are just a guess; one of them might be right */
179 case CLKCFG_FSB_1600:
180 case CLKCFG_FSB_1600_ALT:
181 return 400;
182 default:
183 return 133;
184 }
185}
186
187static int
188intel_dp_aux_ch(struct intel_output *intel_output,
189 uint8_t *send, int send_bytes,
190 uint8_t *recv, int recv_size)
191{
192 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
193 uint32_t output_reg = dp_priv->output_reg;
194 struct drm_device *dev = intel_output->base.dev;
195 struct drm_i915_private *dev_priv = dev->dev_private;
196 uint32_t ch_ctl = output_reg + 0x10;
197 uint32_t ch_data = ch_ctl + 4;
198 int i;
199 int recv_bytes;
200 uint32_t ctl;
201 uint32_t status;
202 uint32_t aux_clock_divider;
203 int try;
204
205 /* The clock divider is based off the hrawclk,
206 * and would like to run at 2MHz. So, take the
207 * hrawclk value and divide by 2 and use that
208 */
209 aux_clock_divider = intel_hrawclk(dev) / 2;
210 /* Must try at least 3 times according to DP spec */
211 for (try = 0; try < 5; try++) {
212 /* Load the send data into the aux channel data registers */
213 for (i = 0; i < send_bytes; i += 4) {
214 uint32_t d = pack_aux(send + i, send_bytes - i);;
215
216 I915_WRITE(ch_data + i, d);
217 }
218
219 ctl = (DP_AUX_CH_CTL_SEND_BUSY |
220 DP_AUX_CH_CTL_TIME_OUT_400us |
221 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
222 (5 << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
223 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
224 DP_AUX_CH_CTL_DONE |
225 DP_AUX_CH_CTL_TIME_OUT_ERROR |
226 DP_AUX_CH_CTL_RECEIVE_ERROR);
227
228 /* Send the command and wait for it to complete */
229 I915_WRITE(ch_ctl, ctl);
230 (void) I915_READ(ch_ctl);
231 for (;;) {
232 udelay(100);
233 status = I915_READ(ch_ctl);
234 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
235 break;
236 }
237
238 /* Clear done status and any errors */
239 I915_WRITE(ch_ctl, (ctl |
240 DP_AUX_CH_CTL_DONE |
241 DP_AUX_CH_CTL_TIME_OUT_ERROR |
242 DP_AUX_CH_CTL_RECEIVE_ERROR));
243 (void) I915_READ(ch_ctl);
244 if ((status & DP_AUX_CH_CTL_TIME_OUT_ERROR) == 0)
245 break;
246 }
247
248 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
249 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
250 return -EBUSY;
251 }
252
253 /* Check for timeout or receive error.
254 * Timeouts occur when the sink is not connected
255 */
256 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
257 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
258 return -EIO;
259 }
260
261 /* Timeouts occur when the device isn't connected, so they're
262 * "normal" -- don't fill the kernel log with these */
263 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
264 DRM_DEBUG("dp_aux_ch timeout status 0x%08x\n", status);
265 return -ETIMEDOUT;
266 }
267
268 /* Unload any bytes sent back from the other side */
269 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
270 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
271
272 if (recv_bytes > recv_size)
273 recv_bytes = recv_size;
274
275 for (i = 0; i < recv_bytes; i += 4) {
276 uint32_t d = I915_READ(ch_data + i);
277
278 unpack_aux(d, recv + i, recv_bytes - i);
279 }
280
281 return recv_bytes;
282}
283
284/* Write data to the aux channel in native mode */
285static int
286intel_dp_aux_native_write(struct intel_output *intel_output,
287 uint16_t address, uint8_t *send, int send_bytes)
288{
289 int ret;
290 uint8_t msg[20];
291 int msg_bytes;
292 uint8_t ack;
293
294 if (send_bytes > 16)
295 return -1;
296 msg[0] = AUX_NATIVE_WRITE << 4;
297 msg[1] = address >> 8;
298 msg[2] = address;
299 msg[3] = send_bytes - 1;
300 memcpy(&msg[4], send, send_bytes);
301 msg_bytes = send_bytes + 4;
302 for (;;) {
303 ret = intel_dp_aux_ch(intel_output, msg, msg_bytes, &ack, 1);
304 if (ret < 0)
305 return ret;
306 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
307 break;
308 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
309 udelay(100);
310 else
311 return -EIO;
312 }
313 return send_bytes;
314}
315
316/* Write a single byte to the aux channel in native mode */
317static int
318intel_dp_aux_native_write_1(struct intel_output *intel_output,
319 uint16_t address, uint8_t byte)
320{
321 return intel_dp_aux_native_write(intel_output, address, &byte, 1);
322}
323
324/* read bytes from a native aux channel */
325static int
326intel_dp_aux_native_read(struct intel_output *intel_output,
327 uint16_t address, uint8_t *recv, int recv_bytes)
328{
329 uint8_t msg[4];
330 int msg_bytes;
331 uint8_t reply[20];
332 int reply_bytes;
333 uint8_t ack;
334 int ret;
335
336 msg[0] = AUX_NATIVE_READ << 4;
337 msg[1] = address >> 8;
338 msg[2] = address & 0xff;
339 msg[3] = recv_bytes - 1;
340
341 msg_bytes = 4;
342 reply_bytes = recv_bytes + 1;
343
344 for (;;) {
345 ret = intel_dp_aux_ch(intel_output, msg, msg_bytes,
346 reply, reply_bytes);
347 if (ret == 0)
348 return -EPROTO;
349 if (ret < 0)
350 return ret;
351 ack = reply[0];
352 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
353 memcpy(recv, reply + 1, ret - 1);
354 return ret - 1;
355 }
356 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
357 udelay(100);
358 else
359 return -EIO;
360 }
361}
362
363static int
364intel_dp_i2c_aux_ch(struct i2c_adapter *adapter,
365 uint8_t *send, int send_bytes,
366 uint8_t *recv, int recv_bytes)
367{
368 struct intel_dp_priv *dp_priv = container_of(adapter,
369 struct intel_dp_priv,
370 adapter);
371 struct intel_output *intel_output = dp_priv->intel_output;
372
373 return intel_dp_aux_ch(intel_output,
374 send, send_bytes, recv, recv_bytes);
375}
376
377static int
378intel_dp_i2c_init(struct intel_output *intel_output, const char *name)
379{
380 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
381
382 DRM_ERROR("i2c_init %s\n", name);
383 dp_priv->algo.running = false;
384 dp_priv->algo.address = 0;
385 dp_priv->algo.aux_ch = intel_dp_i2c_aux_ch;
386
387 memset(&dp_priv->adapter, '\0', sizeof (dp_priv->adapter));
388 dp_priv->adapter.owner = THIS_MODULE;
389 dp_priv->adapter.class = I2C_CLASS_DDC;
390 strncpy (dp_priv->adapter.name, name, sizeof dp_priv->adapter.name - 1);
391 dp_priv->adapter.name[sizeof dp_priv->adapter.name - 1] = '\0';
392 dp_priv->adapter.algo_data = &dp_priv->algo;
393 dp_priv->adapter.dev.parent = &intel_output->base.kdev;
394
395 return i2c_dp_aux_add_bus(&dp_priv->adapter);
396}
397
398static bool
399intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
400 struct drm_display_mode *adjusted_mode)
401{
402 struct intel_output *intel_output = enc_to_intel_output(encoder);
403 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
404 int lane_count, clock;
405 int max_lane_count = intel_dp_max_lane_count(intel_output);
406 int max_clock = intel_dp_max_link_bw(intel_output) == DP_LINK_BW_2_7 ? 1 : 0;
407 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
408
409 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
410 for (clock = 0; clock <= max_clock; clock++) {
411 int link_avail = intel_dp_link_clock(bws[clock]) * lane_count;
412
413 if (intel_dp_link_required(mode->clock) <= link_avail) {
414 dp_priv->link_bw = bws[clock];
415 dp_priv->lane_count = lane_count;
416 adjusted_mode->clock = intel_dp_link_clock(dp_priv->link_bw);
417 DRM_DEBUG("Display port link bw %02x lane count %d clock %d\n",
418 dp_priv->link_bw, dp_priv->lane_count,
419 adjusted_mode->clock);
420 return true;
421 }
422 }
423 }
424 return false;
425}
426
427struct intel_dp_m_n {
428 uint32_t tu;
429 uint32_t gmch_m;
430 uint32_t gmch_n;
431 uint32_t link_m;
432 uint32_t link_n;
433};
434
435static void
436intel_reduce_ratio(uint32_t *num, uint32_t *den)
437{
438 while (*num > 0xffffff || *den > 0xffffff) {
439 *num >>= 1;
440 *den >>= 1;
441 }
442}
443
444static void
445intel_dp_compute_m_n(int bytes_per_pixel,
446 int nlanes,
447 int pixel_clock,
448 int link_clock,
449 struct intel_dp_m_n *m_n)
450{
451 m_n->tu = 64;
452 m_n->gmch_m = pixel_clock * bytes_per_pixel;
453 m_n->gmch_n = link_clock * nlanes;
454 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
455 m_n->link_m = pixel_clock;
456 m_n->link_n = link_clock;
457 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
458}
459
460void
461intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
462 struct drm_display_mode *adjusted_mode)
463{
464 struct drm_device *dev = crtc->dev;
465 struct drm_mode_config *mode_config = &dev->mode_config;
466 struct drm_connector *connector;
467 struct drm_i915_private *dev_priv = dev->dev_private;
468 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
469 int lane_count = 4;
470 struct intel_dp_m_n m_n;
471
472 /*
473 * Find the lane count in the intel_output private
474 */
475 list_for_each_entry(connector, &mode_config->connector_list, head) {
476 struct intel_output *intel_output = to_intel_output(connector);
477 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
478
479 if (!connector->encoder || connector->encoder->crtc != crtc)
480 continue;
481
482 if (intel_output->type == INTEL_OUTPUT_DISPLAYPORT) {
483 lane_count = dp_priv->lane_count;
484 break;
485 }
486 }
487
488 /*
489 * Compute the GMCH and Link ratios. The '3' here is
490 * the number of bytes_per_pixel post-LUT, which we always
491 * set up for 8-bits of R/G/B, or 3 bytes total.
492 */
493 intel_dp_compute_m_n(3, lane_count,
494 mode->clock, adjusted_mode->clock, &m_n);
495
496 if (intel_crtc->pipe == 0) {
497 I915_WRITE(PIPEA_GMCH_DATA_M,
498 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
499 m_n.gmch_m);
500 I915_WRITE(PIPEA_GMCH_DATA_N,
501 m_n.gmch_n);
502 I915_WRITE(PIPEA_DP_LINK_M, m_n.link_m);
503 I915_WRITE(PIPEA_DP_LINK_N, m_n.link_n);
504 } else {
505 I915_WRITE(PIPEB_GMCH_DATA_M,
506 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
507 m_n.gmch_m);
508 I915_WRITE(PIPEB_GMCH_DATA_N,
509 m_n.gmch_n);
510 I915_WRITE(PIPEB_DP_LINK_M, m_n.link_m);
511 I915_WRITE(PIPEB_DP_LINK_N, m_n.link_n);
512 }
513}
514
515static void
516intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
517 struct drm_display_mode *adjusted_mode)
518{
519 struct intel_output *intel_output = enc_to_intel_output(encoder);
520 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
521 struct drm_crtc *crtc = intel_output->enc.crtc;
522 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
523
524 dp_priv->DP = (DP_LINK_TRAIN_OFF |
525 DP_VOLTAGE_0_4 |
526 DP_PRE_EMPHASIS_0 |
527 DP_SYNC_VS_HIGH |
528 DP_SYNC_HS_HIGH);
529
530 switch (dp_priv->lane_count) {
531 case 1:
532 dp_priv->DP |= DP_PORT_WIDTH_1;
533 break;
534 case 2:
535 dp_priv->DP |= DP_PORT_WIDTH_2;
536 break;
537 case 4:
538 dp_priv->DP |= DP_PORT_WIDTH_4;
539 break;
540 }
541 if (dp_priv->has_audio)
542 dp_priv->DP |= DP_AUDIO_OUTPUT_ENABLE;
543
544 memset(dp_priv->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
545 dp_priv->link_configuration[0] = dp_priv->link_bw;
546 dp_priv->link_configuration[1] = dp_priv->lane_count;
547
548 /*
549 * Check for DPCD version > 1.1,
550 * enable enahanced frame stuff in that case
551 */
552 if (dp_priv->dpcd[0] >= 0x11) {
553 dp_priv->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
554 dp_priv->DP |= DP_ENHANCED_FRAMING;
555 }
556
557 if (intel_crtc->pipe == 1)
558 dp_priv->DP |= DP_PIPEB_SELECT;
559}
560
561
562static void
563intel_dp_dpms(struct drm_encoder *encoder, int mode)
564{
565 struct intel_output *intel_output = enc_to_intel_output(encoder);
566 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
567 struct drm_device *dev = intel_output->base.dev;
568 struct drm_i915_private *dev_priv = dev->dev_private;
569 uint32_t dp_reg = I915_READ(dp_priv->output_reg);
570
571 if (mode != DRM_MODE_DPMS_ON) {
572 if (dp_reg & DP_PORT_EN)
573 intel_dp_link_down(intel_output, dp_priv->DP);
574 } else {
575 if (!(dp_reg & DP_PORT_EN))
576 intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration);
577 }
578 dp_priv->dpms_mode = mode;
579}
580
581/*
582 * Fetch AUX CH registers 0x202 - 0x207 which contain
583 * link status information
584 */
585static bool
586intel_dp_get_link_status(struct intel_output *intel_output,
587 uint8_t link_status[DP_LINK_STATUS_SIZE])
588{
589 int ret;
590
591 ret = intel_dp_aux_native_read(intel_output,
592 DP_LANE0_1_STATUS,
593 link_status, DP_LINK_STATUS_SIZE);
594 if (ret != DP_LINK_STATUS_SIZE)
595 return false;
596 return true;
597}
598
599static uint8_t
600intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
601 int r)
602{
603 return link_status[r - DP_LANE0_1_STATUS];
604}
605
606static void
607intel_dp_save(struct drm_connector *connector)
608{
609 struct intel_output *intel_output = to_intel_output(connector);
610 struct drm_device *dev = intel_output->base.dev;
611 struct drm_i915_private *dev_priv = dev->dev_private;
612 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
613
614 dp_priv->save_DP = I915_READ(dp_priv->output_reg);
615 intel_dp_aux_native_read(intel_output, DP_LINK_BW_SET,
616 dp_priv->save_link_configuration,
617 sizeof (dp_priv->save_link_configuration));
618}
619
620static uint8_t
621intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
622 int lane)
623{
624 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
625 int s = ((lane & 1) ?
626 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
627 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
628 uint8_t l = intel_dp_link_status(link_status, i);
629
630 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
631}
632
633static uint8_t
634intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
635 int lane)
636{
637 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
638 int s = ((lane & 1) ?
639 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
640 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
641 uint8_t l = intel_dp_link_status(link_status, i);
642
643 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
644}
645
646
647#if 0
648static char *voltage_names[] = {
649 "0.4V", "0.6V", "0.8V", "1.2V"
650};
651static char *pre_emph_names[] = {
652 "0dB", "3.5dB", "6dB", "9.5dB"
653};
654static char *link_train_names[] = {
655 "pattern 1", "pattern 2", "idle", "off"
656};
657#endif
658
659/*
660 * These are source-specific values; current Intel hardware supports
661 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
662 */
663#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
664
665static uint8_t
666intel_dp_pre_emphasis_max(uint8_t voltage_swing)
667{
668 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
669 case DP_TRAIN_VOLTAGE_SWING_400:
670 return DP_TRAIN_PRE_EMPHASIS_6;
671 case DP_TRAIN_VOLTAGE_SWING_600:
672 return DP_TRAIN_PRE_EMPHASIS_6;
673 case DP_TRAIN_VOLTAGE_SWING_800:
674 return DP_TRAIN_PRE_EMPHASIS_3_5;
675 case DP_TRAIN_VOLTAGE_SWING_1200:
676 default:
677 return DP_TRAIN_PRE_EMPHASIS_0;
678 }
679}
680
681static void
682intel_get_adjust_train(struct intel_output *intel_output,
683 uint8_t link_status[DP_LINK_STATUS_SIZE],
684 int lane_count,
685 uint8_t train_set[4])
686{
687 uint8_t v = 0;
688 uint8_t p = 0;
689 int lane;
690
691 for (lane = 0; lane < lane_count; lane++) {
692 uint8_t this_v = intel_get_adjust_request_voltage(link_status, lane);
693 uint8_t this_p = intel_get_adjust_request_pre_emphasis(link_status, lane);
694
695 if (this_v > v)
696 v = this_v;
697 if (this_p > p)
698 p = this_p;
699 }
700
701 if (v >= I830_DP_VOLTAGE_MAX)
702 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
703
704 if (p >= intel_dp_pre_emphasis_max(v))
705 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
706
707 for (lane = 0; lane < 4; lane++)
708 train_set[lane] = v | p;
709}
710
711static uint32_t
712intel_dp_signal_levels(uint8_t train_set, int lane_count)
713{
714 uint32_t signal_levels = 0;
715
716 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
717 case DP_TRAIN_VOLTAGE_SWING_400:
718 default:
719 signal_levels |= DP_VOLTAGE_0_4;
720 break;
721 case DP_TRAIN_VOLTAGE_SWING_600:
722 signal_levels |= DP_VOLTAGE_0_6;
723 break;
724 case DP_TRAIN_VOLTAGE_SWING_800:
725 signal_levels |= DP_VOLTAGE_0_8;
726 break;
727 case DP_TRAIN_VOLTAGE_SWING_1200:
728 signal_levels |= DP_VOLTAGE_1_2;
729 break;
730 }
731 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
732 case DP_TRAIN_PRE_EMPHASIS_0:
733 default:
734 signal_levels |= DP_PRE_EMPHASIS_0;
735 break;
736 case DP_TRAIN_PRE_EMPHASIS_3_5:
737 signal_levels |= DP_PRE_EMPHASIS_3_5;
738 break;
739 case DP_TRAIN_PRE_EMPHASIS_6:
740 signal_levels |= DP_PRE_EMPHASIS_6;
741 break;
742 case DP_TRAIN_PRE_EMPHASIS_9_5:
743 signal_levels |= DP_PRE_EMPHASIS_9_5;
744 break;
745 }
746 return signal_levels;
747}
748
749static uint8_t
750intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
751 int lane)
752{
753 int i = DP_LANE0_1_STATUS + (lane >> 1);
754 int s = (lane & 1) * 4;
755 uint8_t l = intel_dp_link_status(link_status, i);
756
757 return (l >> s) & 0xf;
758}
759
760/* Check for clock recovery is done on all channels */
761static bool
762intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
763{
764 int lane;
765 uint8_t lane_status;
766
767 for (lane = 0; lane < lane_count; lane++) {
768 lane_status = intel_get_lane_status(link_status, lane);
769 if ((lane_status & DP_LANE_CR_DONE) == 0)
770 return false;
771 }
772 return true;
773}
774
775/* Check to see if channel eq is done on all channels */
776#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
777 DP_LANE_CHANNEL_EQ_DONE|\
778 DP_LANE_SYMBOL_LOCKED)
779static bool
780intel_channel_eq_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
781{
782 uint8_t lane_align;
783 uint8_t lane_status;
784 int lane;
785
786 lane_align = intel_dp_link_status(link_status,
787 DP_LANE_ALIGN_STATUS_UPDATED);
788 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
789 return false;
790 for (lane = 0; lane < lane_count; lane++) {
791 lane_status = intel_get_lane_status(link_status, lane);
792 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
793 return false;
794 }
795 return true;
796}
797
798static bool
799intel_dp_set_link_train(struct intel_output *intel_output,
800 uint32_t dp_reg_value,
801 uint8_t dp_train_pat,
802 uint8_t train_set[4],
803 bool first)
804{
805 struct drm_device *dev = intel_output->base.dev;
806 struct drm_i915_private *dev_priv = dev->dev_private;
807 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
808 int ret;
809
810 I915_WRITE(dp_priv->output_reg, dp_reg_value);
811 POSTING_READ(dp_priv->output_reg);
812 if (first)
813 intel_wait_for_vblank(dev);
814
815 intel_dp_aux_native_write_1(intel_output,
816 DP_TRAINING_PATTERN_SET,
817 dp_train_pat);
818
819 ret = intel_dp_aux_native_write(intel_output,
820 DP_TRAINING_LANE0_SET, train_set, 4);
821 if (ret != 4)
822 return false;
823
824 return true;
825}
826
827static void
828intel_dp_link_train(struct intel_output *intel_output, uint32_t DP,
829 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE])
830{
831 struct drm_device *dev = intel_output->base.dev;
832 struct drm_i915_private *dev_priv = dev->dev_private;
833 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
834 uint8_t train_set[4];
835 uint8_t link_status[DP_LINK_STATUS_SIZE];
836 int i;
837 uint8_t voltage;
838 bool clock_recovery = false;
839 bool channel_eq = false;
840 bool first = true;
841 int tries;
842
843 /* Write the link configuration data */
844 intel_dp_aux_native_write(intel_output, 0x100,
845 link_configuration, DP_LINK_CONFIGURATION_SIZE);
846
847 DP |= DP_PORT_EN;
848 DP &= ~DP_LINK_TRAIN_MASK;
849 memset(train_set, 0, 4);
850 voltage = 0xff;
851 tries = 0;
852 clock_recovery = false;
853 for (;;) {
854 /* Use train_set[0] to set the voltage and pre emphasis values */
855 uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count);
856 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
857
858 if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_1,
859 DP_TRAINING_PATTERN_1, train_set, first))
860 break;
861 first = false;
862 /* Set training pattern 1 */
863
864 udelay(100);
865 if (!intel_dp_get_link_status(intel_output, link_status))
866 break;
867
868 if (intel_clock_recovery_ok(link_status, dp_priv->lane_count)) {
869 clock_recovery = true;
870 break;
871 }
872
873 /* Check to see if we've tried the max voltage */
874 for (i = 0; i < dp_priv->lane_count; i++)
875 if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
876 break;
877 if (i == dp_priv->lane_count)
878 break;
879
880 /* Check to see if we've tried the same voltage 5 times */
881 if ((train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
882 ++tries;
883 if (tries == 5)
884 break;
885 } else
886 tries = 0;
887 voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
888
889 /* Compute new train_set as requested by target */
890 intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set);
891 }
892
893 /* channel equalization */
894 tries = 0;
895 channel_eq = false;
896 for (;;) {
897 /* Use train_set[0] to set the voltage and pre emphasis values */
898 uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count);
899 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
900
901 /* channel eq pattern */
902 if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_2,
903 DP_TRAINING_PATTERN_2, train_set,
904 false))
905 break;
906
907 udelay(400);
908 if (!intel_dp_get_link_status(intel_output, link_status))
909 break;
910
911 if (intel_channel_eq_ok(link_status, dp_priv->lane_count)) {
912 channel_eq = true;
913 break;
914 }
915
916 /* Try 5 times */
917 if (tries > 5)
918 break;
919
920 /* Compute new train_set as requested by target */
921 intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set);
922 ++tries;
923 }
924
925 I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_OFF);
926 POSTING_READ(dp_priv->output_reg);
927 intel_dp_aux_native_write_1(intel_output,
928 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
929}
930
931static void
932intel_dp_link_down(struct intel_output *intel_output, uint32_t DP)
933{
934 struct drm_device *dev = intel_output->base.dev;
935 struct drm_i915_private *dev_priv = dev->dev_private;
936 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
937
938 I915_WRITE(dp_priv->output_reg, DP & ~DP_PORT_EN);
939 POSTING_READ(dp_priv->output_reg);
940}
941
942static void
943intel_dp_restore(struct drm_connector *connector)
944{
945 struct intel_output *intel_output = to_intel_output(connector);
946 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
947
948 if (dp_priv->save_DP & DP_PORT_EN)
949 intel_dp_link_train(intel_output, dp_priv->save_DP, dp_priv->save_link_configuration);
950 else
951 intel_dp_link_down(intel_output, dp_priv->save_DP);
952}
953
954/*
955 * According to DP spec
956 * 5.1.2:
957 * 1. Read DPCD
958 * 2. Configure link according to Receiver Capabilities
959 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
960 * 4. Check link status on receipt of hot-plug interrupt
961 */
962
963static void
964intel_dp_check_link_status(struct intel_output *intel_output)
965{
966 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
967 uint8_t link_status[DP_LINK_STATUS_SIZE];
968
969 if (!intel_output->enc.crtc)
970 return;
971
972 if (!intel_dp_get_link_status(intel_output, link_status)) {
973 intel_dp_link_down(intel_output, dp_priv->DP);
974 return;
975 }
976
977 if (!intel_channel_eq_ok(link_status, dp_priv->lane_count))
978 intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration);
979}
980
981/**
982 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
983 *
984 * \return true if DP port is connected.
985 * \return false if DP port is disconnected.
986 */
987static enum drm_connector_status
988intel_dp_detect(struct drm_connector *connector)
989{
990 struct intel_output *intel_output = to_intel_output(connector);
991 struct drm_device *dev = intel_output->base.dev;
992 struct drm_i915_private *dev_priv = dev->dev_private;
993 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
994 uint32_t temp, bit;
995 enum drm_connector_status status;
996
997 dp_priv->has_audio = false;
998
999 temp = I915_READ(PORT_HOTPLUG_EN);
1000
1001 I915_WRITE(PORT_HOTPLUG_EN,
1002 temp |
1003 DPB_HOTPLUG_INT_EN |
1004 DPC_HOTPLUG_INT_EN |
1005 DPD_HOTPLUG_INT_EN);
1006
1007 POSTING_READ(PORT_HOTPLUG_EN);
1008
1009 switch (dp_priv->output_reg) {
1010 case DP_B:
1011 bit = DPB_HOTPLUG_INT_STATUS;
1012 break;
1013 case DP_C:
1014 bit = DPC_HOTPLUG_INT_STATUS;
1015 break;
1016 case DP_D:
1017 bit = DPD_HOTPLUG_INT_STATUS;
1018 break;
1019 default:
1020 return connector_status_unknown;
1021 }
1022
1023 temp = I915_READ(PORT_HOTPLUG_STAT);
1024
1025 if ((temp & bit) == 0)
1026 return connector_status_disconnected;
1027
1028 status = connector_status_disconnected;
1029 if (intel_dp_aux_native_read(intel_output,
1030 0x000, dp_priv->dpcd,
1031 sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd))
1032 {
1033 if (dp_priv->dpcd[0] != 0)
1034 status = connector_status_connected;
1035 }
1036 return status;
1037}
1038
1039static int intel_dp_get_modes(struct drm_connector *connector)
1040{
1041 struct intel_output *intel_output = to_intel_output(connector);
1042
1043 /* We should parse the EDID data and find out if it has an audio sink
1044 */
1045
1046 return intel_ddc_get_modes(intel_output);
1047}
1048
1049static void
1050intel_dp_destroy (struct drm_connector *connector)
1051{
1052 struct intel_output *intel_output = to_intel_output(connector);
1053
1054 if (intel_output->i2c_bus)
1055 intel_i2c_destroy(intel_output->i2c_bus);
1056 drm_sysfs_connector_remove(connector);
1057 drm_connector_cleanup(connector);
1058 kfree(intel_output);
1059}
1060
1061static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
1062 .dpms = intel_dp_dpms,
1063 .mode_fixup = intel_dp_mode_fixup,
1064 .prepare = intel_encoder_prepare,
1065 .mode_set = intel_dp_mode_set,
1066 .commit = intel_encoder_commit,
1067};
1068
1069static const struct drm_connector_funcs intel_dp_connector_funcs = {
1070 .dpms = drm_helper_connector_dpms,
1071 .save = intel_dp_save,
1072 .restore = intel_dp_restore,
1073 .detect = intel_dp_detect,
1074 .fill_modes = drm_helper_probe_single_connector_modes,
1075 .destroy = intel_dp_destroy,
1076};
1077
1078static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
1079 .get_modes = intel_dp_get_modes,
1080 .mode_valid = intel_dp_mode_valid,
1081 .best_encoder = intel_best_encoder,
1082};
1083
1084static void intel_dp_enc_destroy(struct drm_encoder *encoder)
1085{
1086 drm_encoder_cleanup(encoder);
1087}
1088
1089static const struct drm_encoder_funcs intel_dp_enc_funcs = {
1090 .destroy = intel_dp_enc_destroy,
1091};
1092
1093void
1094intel_dp_hot_plug(struct intel_output *intel_output)
1095{
1096 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
1097
1098 if (dp_priv->dpms_mode == DRM_MODE_DPMS_ON)
1099 intel_dp_check_link_status(intel_output);
1100}
1101
1102void
1103intel_dp_init(struct drm_device *dev, int output_reg)
1104{
1105 struct drm_i915_private *dev_priv = dev->dev_private;
1106 struct drm_connector *connector;
1107 struct intel_output *intel_output;
1108 struct intel_dp_priv *dp_priv;
1109
1110 intel_output = kcalloc(sizeof(struct intel_output) +
1111 sizeof(struct intel_dp_priv), 1, GFP_KERNEL);
1112 if (!intel_output)
1113 return;
1114
1115 dp_priv = (struct intel_dp_priv *)(intel_output + 1);
1116
1117 connector = &intel_output->base;
1118 drm_connector_init(dev, connector, &intel_dp_connector_funcs,
1119 DRM_MODE_CONNECTOR_DisplayPort);
1120 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
1121
1122 intel_output->type = INTEL_OUTPUT_DISPLAYPORT;
1123
1124 connector->interlace_allowed = true;
1125 connector->doublescan_allowed = 0;
1126
1127 dp_priv->intel_output = intel_output;
1128 dp_priv->output_reg = output_reg;
1129 dp_priv->has_audio = false;
1130 dp_priv->dpms_mode = DRM_MODE_DPMS_ON;
1131 intel_output->dev_priv = dp_priv;
1132
1133 drm_encoder_init(dev, &intel_output->enc, &intel_dp_enc_funcs,
1134 DRM_MODE_ENCODER_TMDS);
1135 drm_encoder_helper_add(&intel_output->enc, &intel_dp_helper_funcs);
1136
1137 drm_mode_connector_attach_encoder(&intel_output->base,
1138 &intel_output->enc);
1139 drm_sysfs_connector_add(connector);
1140
1141 /* Set up the DDC bus. */
1142 intel_dp_i2c_init(intel_output,
1143 (output_reg == DP_B) ? "DPDDC-B" :
1144 (output_reg == DP_C) ? "DPDDC-C" : "DPDDC-D");
1145 intel_output->ddc_bus = &dp_priv->adapter;
1146 intel_output->hot_plug = intel_dp_hot_plug;
1147
1148 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1149 * 0xd. Failure to do so will result in spurious interrupts being
1150 * generated on the port when a cable is not attached.
1151 */
1152 if (IS_G4X(dev) && !IS_GM45(dev)) {
1153 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1154 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1155 }
1156}
diff --git a/drivers/gpu/drm/i915/intel_dp.h b/drivers/gpu/drm/i915/intel_dp.h
new file mode 100644
index 000000000000..2b38054d3b6d
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp.h
@@ -0,0 +1,144 @@
1/*
2 * Copyright © 2008 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _INTEL_DP_H_
24#define _INTEL_DP_H_
25
26/* From the VESA DisplayPort spec */
27
28#define AUX_NATIVE_WRITE 0x8
29#define AUX_NATIVE_READ 0x9
30#define AUX_I2C_WRITE 0x0
31#define AUX_I2C_READ 0x1
32#define AUX_I2C_STATUS 0x2
33#define AUX_I2C_MOT 0x4
34
35#define AUX_NATIVE_REPLY_ACK (0x0 << 4)
36#define AUX_NATIVE_REPLY_NACK (0x1 << 4)
37#define AUX_NATIVE_REPLY_DEFER (0x2 << 4)
38#define AUX_NATIVE_REPLY_MASK (0x3 << 4)
39
40#define AUX_I2C_REPLY_ACK (0x0 << 6)
41#define AUX_I2C_REPLY_NACK (0x1 << 6)
42#define AUX_I2C_REPLY_DEFER (0x2 << 6)
43#define AUX_I2C_REPLY_MASK (0x3 << 6)
44
45/* AUX CH addresses */
46#define DP_LINK_BW_SET 0x100
47# define DP_LINK_BW_1_62 0x06
48# define DP_LINK_BW_2_7 0x0a
49
50#define DP_LANE_COUNT_SET 0x101
51# define DP_LANE_COUNT_MASK 0x0f
52# define DP_LANE_COUNT_ENHANCED_FRAME_EN (1 << 7)
53
54#define DP_TRAINING_PATTERN_SET 0x102
55
56# define DP_TRAINING_PATTERN_DISABLE 0
57# define DP_TRAINING_PATTERN_1 1
58# define DP_TRAINING_PATTERN_2 2
59# define DP_TRAINING_PATTERN_MASK 0x3
60
61# define DP_LINK_QUAL_PATTERN_DISABLE (0 << 2)
62# define DP_LINK_QUAL_PATTERN_D10_2 (1 << 2)
63# define DP_LINK_QUAL_PATTERN_ERROR_RATE (2 << 2)
64# define DP_LINK_QUAL_PATTERN_PRBS7 (3 << 2)
65# define DP_LINK_QUAL_PATTERN_MASK (3 << 2)
66
67# define DP_RECOVERED_CLOCK_OUT_EN (1 << 4)
68# define DP_LINK_SCRAMBLING_DISABLE (1 << 5)
69
70# define DP_SYMBOL_ERROR_COUNT_BOTH (0 << 6)
71# define DP_SYMBOL_ERROR_COUNT_DISPARITY (1 << 6)
72# define DP_SYMBOL_ERROR_COUNT_SYMBOL (2 << 6)
73# define DP_SYMBOL_ERROR_COUNT_MASK (3 << 6)
74
75#define DP_TRAINING_LANE0_SET 0x103
76#define DP_TRAINING_LANE1_SET 0x104
77#define DP_TRAINING_LANE2_SET 0x105
78#define DP_TRAINING_LANE3_SET 0x106
79
80# define DP_TRAIN_VOLTAGE_SWING_MASK 0x3
81# define DP_TRAIN_VOLTAGE_SWING_SHIFT 0
82# define DP_TRAIN_MAX_SWING_REACHED (1 << 2)
83# define DP_TRAIN_VOLTAGE_SWING_400 (0 << 0)
84# define DP_TRAIN_VOLTAGE_SWING_600 (1 << 0)
85# define DP_TRAIN_VOLTAGE_SWING_800 (2 << 0)
86# define DP_TRAIN_VOLTAGE_SWING_1200 (3 << 0)
87
88# define DP_TRAIN_PRE_EMPHASIS_MASK (3 << 3)
89# define DP_TRAIN_PRE_EMPHASIS_0 (0 << 3)
90# define DP_TRAIN_PRE_EMPHASIS_3_5 (1 << 3)
91# define DP_TRAIN_PRE_EMPHASIS_6 (2 << 3)
92# define DP_TRAIN_PRE_EMPHASIS_9_5 (3 << 3)
93
94# define DP_TRAIN_PRE_EMPHASIS_SHIFT 3
95# define DP_TRAIN_MAX_PRE_EMPHASIS_REACHED (1 << 5)
96
97#define DP_DOWNSPREAD_CTRL 0x107
98# define DP_SPREAD_AMP_0_5 (1 << 4)
99
100#define DP_MAIN_LINK_CHANNEL_CODING_SET 0x108
101# define DP_SET_ANSI_8B10B (1 << 0)
102
103#define DP_LANE0_1_STATUS 0x202
104#define DP_LANE2_3_STATUS 0x203
105
106# define DP_LANE_CR_DONE (1 << 0)
107# define DP_LANE_CHANNEL_EQ_DONE (1 << 1)
108# define DP_LANE_SYMBOL_LOCKED (1 << 2)
109
110#define DP_LANE_ALIGN_STATUS_UPDATED 0x204
111
112#define DP_INTERLANE_ALIGN_DONE (1 << 0)
113#define DP_DOWNSTREAM_PORT_STATUS_CHANGED (1 << 6)
114#define DP_LINK_STATUS_UPDATED (1 << 7)
115
116#define DP_SINK_STATUS 0x205
117
118#define DP_RECEIVE_PORT_0_STATUS (1 << 0)
119#define DP_RECEIVE_PORT_1_STATUS (1 << 1)
120
121#define DP_ADJUST_REQUEST_LANE0_1 0x206
122#define DP_ADJUST_REQUEST_LANE2_3 0x207
123
124#define DP_ADJUST_VOLTAGE_SWING_LANE0_MASK 0x03
125#define DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT 0
126#define DP_ADJUST_PRE_EMPHASIS_LANE0_MASK 0x0c
127#define DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT 2
128#define DP_ADJUST_VOLTAGE_SWING_LANE1_MASK 0x30
129#define DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT 4
130#define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK 0xc0
131#define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT 6
132
133struct i2c_algo_dp_aux_data {
134 bool running;
135 u16 address;
136 int (*aux_ch) (struct i2c_adapter *adapter,
137 uint8_t *send, int send_bytes,
138 uint8_t *recv, int recv_bytes);
139};
140
141int
142i2c_dp_aux_add_bus(struct i2c_adapter *adapter);
143
144#endif /* _INTEL_DP_H_ */
diff --git a/drivers/gpu/drm/i915/intel_dp_i2c.c b/drivers/gpu/drm/i915/intel_dp_i2c.c
new file mode 100644
index 000000000000..a63b6f57d2d4
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp_i2c.c
@@ -0,0 +1,273 @@
1/*
2 * Copyright © 2009 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/init.h>
28#include <linux/errno.h>
29#include <linux/sched.h>
30#include <linux/i2c.h>
31#include "intel_dp.h"
32#include "drmP.h"
33
34/* Run a single AUX_CH I2C transaction, writing/reading data as necessary */
35
36#define MODE_I2C_START 1
37#define MODE_I2C_WRITE 2
38#define MODE_I2C_READ 4
39#define MODE_I2C_STOP 8
40
41static int
42i2c_algo_dp_aux_transaction(struct i2c_adapter *adapter, int mode,
43 uint8_t write_byte, uint8_t *read_byte)
44{
45 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
46 uint16_t address = algo_data->address;
47 uint8_t msg[5];
48 uint8_t reply[2];
49 int msg_bytes;
50 int reply_bytes;
51 int ret;
52
53 /* Set up the command byte */
54 if (mode & MODE_I2C_READ)
55 msg[0] = AUX_I2C_READ << 4;
56 else
57 msg[0] = AUX_I2C_WRITE << 4;
58
59 if (!(mode & MODE_I2C_STOP))
60 msg[0] |= AUX_I2C_MOT << 4;
61
62 msg[1] = address >> 8;
63 msg[2] = address;
64
65 switch (mode) {
66 case MODE_I2C_WRITE:
67 msg[3] = 0;
68 msg[4] = write_byte;
69 msg_bytes = 5;
70 reply_bytes = 1;
71 break;
72 case MODE_I2C_READ:
73 msg[3] = 0;
74 msg_bytes = 4;
75 reply_bytes = 2;
76 break;
77 default:
78 msg_bytes = 3;
79 reply_bytes = 1;
80 break;
81 }
82
83 for (;;) {
84 ret = (*algo_data->aux_ch)(adapter,
85 msg, msg_bytes,
86 reply, reply_bytes);
87 if (ret < 0) {
88 DRM_DEBUG("aux_ch failed %d\n", ret);
89 return ret;
90 }
91 switch (reply[0] & AUX_I2C_REPLY_MASK) {
92 case AUX_I2C_REPLY_ACK:
93 if (mode == MODE_I2C_READ) {
94 *read_byte = reply[1];
95 }
96 return reply_bytes - 1;
97 case AUX_I2C_REPLY_NACK:
98 DRM_DEBUG("aux_ch nack\n");
99 return -EREMOTEIO;
100 case AUX_I2C_REPLY_DEFER:
101 DRM_DEBUG("aux_ch defer\n");
102 udelay(100);
103 break;
104 default:
105 DRM_ERROR("aux_ch invalid reply 0x%02x\n", reply[0]);
106 return -EREMOTEIO;
107 }
108 }
109}
110
111/*
112 * I2C over AUX CH
113 */
114
115/*
116 * Send the address. If the I2C link is running, this 'restarts'
117 * the connection with the new address, this is used for doing
118 * a write followed by a read (as needed for DDC)
119 */
120static int
121i2c_algo_dp_aux_address(struct i2c_adapter *adapter, u16 address, bool reading)
122{
123 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
124 int mode = MODE_I2C_START;
125 int ret;
126
127 if (reading)
128 mode |= MODE_I2C_READ;
129 else
130 mode |= MODE_I2C_WRITE;
131 algo_data->address = address;
132 algo_data->running = true;
133 ret = i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL);
134 return ret;
135}
136
137/*
138 * Stop the I2C transaction. This closes out the link, sending
139 * a bare address packet with the MOT bit turned off
140 */
141static void
142i2c_algo_dp_aux_stop(struct i2c_adapter *adapter, bool reading)
143{
144 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
145 int mode = MODE_I2C_STOP;
146
147 if (reading)
148 mode |= MODE_I2C_READ;
149 else
150 mode |= MODE_I2C_WRITE;
151 if (algo_data->running) {
152 (void) i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL);
153 algo_data->running = false;
154 }
155}
156
157/*
158 * Write a single byte to the current I2C address, the
159 * the I2C link must be running or this returns -EIO
160 */
161static int
162i2c_algo_dp_aux_put_byte(struct i2c_adapter *adapter, u8 byte)
163{
164 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
165 int ret;
166
167 if (!algo_data->running)
168 return -EIO;
169
170 ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_WRITE, byte, NULL);
171 return ret;
172}
173
174/*
175 * Read a single byte from the current I2C address, the
176 * I2C link must be running or this returns -EIO
177 */
178static int
179i2c_algo_dp_aux_get_byte(struct i2c_adapter *adapter, u8 *byte_ret)
180{
181 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
182 int ret;
183
184 if (!algo_data->running)
185 return -EIO;
186
187 ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_READ, 0, byte_ret);
188 return ret;
189}
190
191static int
192i2c_algo_dp_aux_xfer(struct i2c_adapter *adapter,
193 struct i2c_msg *msgs,
194 int num)
195{
196 int ret = 0;
197 bool reading = false;
198 int m;
199 int b;
200
201 for (m = 0; m < num; m++) {
202 u16 len = msgs[m].len;
203 u8 *buf = msgs[m].buf;
204 reading = (msgs[m].flags & I2C_M_RD) != 0;
205 ret = i2c_algo_dp_aux_address(adapter, msgs[m].addr, reading);
206 if (ret < 0)
207 break;
208 if (reading) {
209 for (b = 0; b < len; b++) {
210 ret = i2c_algo_dp_aux_get_byte(adapter, &buf[b]);
211 if (ret < 0)
212 break;
213 }
214 } else {
215 for (b = 0; b < len; b++) {
216 ret = i2c_algo_dp_aux_put_byte(adapter, buf[b]);
217 if (ret < 0)
218 break;
219 }
220 }
221 if (ret < 0)
222 break;
223 }
224 if (ret >= 0)
225 ret = num;
226 i2c_algo_dp_aux_stop(adapter, reading);
227 DRM_DEBUG("dp_aux_xfer return %d\n", ret);
228 return ret;
229}
230
231static u32
232i2c_algo_dp_aux_functionality(struct i2c_adapter *adapter)
233{
234 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
235 I2C_FUNC_SMBUS_READ_BLOCK_DATA |
236 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
237 I2C_FUNC_10BIT_ADDR;
238}
239
240static const struct i2c_algorithm i2c_dp_aux_algo = {
241 .master_xfer = i2c_algo_dp_aux_xfer,
242 .functionality = i2c_algo_dp_aux_functionality,
243};
244
245static void
246i2c_dp_aux_reset_bus(struct i2c_adapter *adapter)
247{
248 (void) i2c_algo_dp_aux_address(adapter, 0, false);
249 (void) i2c_algo_dp_aux_stop(adapter, false);
250
251}
252
253static int
254i2c_dp_aux_prepare_bus(struct i2c_adapter *adapter)
255{
256 adapter->algo = &i2c_dp_aux_algo;
257 adapter->retries = 3;
258 i2c_dp_aux_reset_bus(adapter);
259 return 0;
260}
261
262int
263i2c_dp_aux_add_bus(struct i2c_adapter *adapter)
264{
265 int error;
266
267 error = i2c_dp_aux_prepare_bus(adapter);
268 if (error)
269 return error;
270 error = i2c_add_adapter(adapter);
271 return error;
272}
273EXPORT_SYMBOL(i2c_dp_aux_add_bus);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index cd4b9c5f715e..004541c935a8 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -54,6 +54,7 @@
54#define INTEL_OUTPUT_LVDS 4 54#define INTEL_OUTPUT_LVDS 4
55#define INTEL_OUTPUT_TVOUT 5 55#define INTEL_OUTPUT_TVOUT 5
56#define INTEL_OUTPUT_HDMI 6 56#define INTEL_OUTPUT_HDMI 6
57#define INTEL_OUTPUT_DISPLAYPORT 7
57 58
58#define INTEL_DVO_CHIP_NONE 0 59#define INTEL_DVO_CHIP_NONE 0
59#define INTEL_DVO_CHIP_LVDS 1 60#define INTEL_DVO_CHIP_LVDS 1
@@ -65,7 +66,6 @@ struct intel_i2c_chan {
65 u32 reg; /* GPIO reg */ 66 u32 reg; /* GPIO reg */
66 struct i2c_adapter adapter; 67 struct i2c_adapter adapter;
67 struct i2c_algo_bit_data algo; 68 struct i2c_algo_bit_data algo;
68 u8 slave_addr;
69}; 69};
70 70
71struct intel_framebuffer { 71struct intel_framebuffer {
@@ -79,11 +79,12 @@ struct intel_output {
79 79
80 struct drm_encoder enc; 80 struct drm_encoder enc;
81 int type; 81 int type;
82 struct intel_i2c_chan *i2c_bus; /* for control functions */ 82 struct i2c_adapter *i2c_bus;
83 struct intel_i2c_chan *ddc_bus; /* for DDC only stuff */ 83 struct i2c_adapter *ddc_bus;
84 bool load_detect_temp; 84 bool load_detect_temp;
85 bool needs_tv_clock; 85 bool needs_tv_clock;
86 void *dev_priv; 86 void *dev_priv;
87 void (*hot_plug)(struct intel_output *);
87}; 88};
88 89
89struct intel_crtc { 90struct intel_crtc {
@@ -104,9 +105,9 @@ struct intel_crtc {
104#define enc_to_intel_output(x) container_of(x, struct intel_output, enc) 105#define enc_to_intel_output(x) container_of(x, struct intel_output, enc)
105#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base) 106#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
106 107
107struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg, 108struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg,
108 const char *name); 109 const char *name);
109void intel_i2c_destroy(struct intel_i2c_chan *chan); 110void intel_i2c_destroy(struct i2c_adapter *adapter);
110int intel_ddc_get_modes(struct intel_output *intel_output); 111int intel_ddc_get_modes(struct intel_output *intel_output);
111extern bool intel_ddc_probe(struct intel_output *intel_output); 112extern bool intel_ddc_probe(struct intel_output *intel_output);
112void intel_i2c_quirk_set(struct drm_device *dev, bool enable); 113void intel_i2c_quirk_set(struct drm_device *dev, bool enable);
@@ -116,6 +117,10 @@ extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
116extern void intel_dvo_init(struct drm_device *dev); 117extern void intel_dvo_init(struct drm_device *dev);
117extern void intel_tv_init(struct drm_device *dev); 118extern void intel_tv_init(struct drm_device *dev);
118extern void intel_lvds_init(struct drm_device *dev); 119extern void intel_lvds_init(struct drm_device *dev);
120extern void intel_dp_init(struct drm_device *dev, int dp_reg);
121void
122intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
123 struct drm_display_mode *adjusted_mode);
119 124
120extern void intel_crtc_load_lut(struct drm_crtc *crtc); 125extern void intel_crtc_load_lut(struct drm_crtc *crtc);
121extern void intel_encoder_prepare (struct drm_encoder *encoder); 126extern void intel_encoder_prepare (struct drm_encoder *encoder);
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
index 1ee3007d6ec0..13bff20930e8 100644
--- a/drivers/gpu/drm/i915/intel_dvo.c
+++ b/drivers/gpu/drm/i915/intel_dvo.c
@@ -384,10 +384,9 @@ void intel_dvo_init(struct drm_device *dev)
384{ 384{
385 struct intel_output *intel_output; 385 struct intel_output *intel_output;
386 struct intel_dvo_device *dvo; 386 struct intel_dvo_device *dvo;
387 struct intel_i2c_chan *i2cbus = NULL; 387 struct i2c_adapter *i2cbus = NULL;
388 int ret = 0; 388 int ret = 0;
389 int i; 389 int i;
390 int gpio_inited = 0;
391 int encoder_type = DRM_MODE_ENCODER_NONE; 390 int encoder_type = DRM_MODE_ENCODER_NONE;
392 intel_output = kzalloc (sizeof(struct intel_output), GFP_KERNEL); 391 intel_output = kzalloc (sizeof(struct intel_output), GFP_KERNEL);
393 if (!intel_output) 392 if (!intel_output)
@@ -420,14 +419,11 @@ void intel_dvo_init(struct drm_device *dev)
420 * It appears that everything is on GPIOE except for panels 419 * It appears that everything is on GPIOE except for panels
421 * on i830 laptops, which are on GPIOB (DVOA). 420 * on i830 laptops, which are on GPIOB (DVOA).
422 */ 421 */
423 if (gpio_inited != gpio) { 422 if (i2cbus != NULL)
424 if (i2cbus != NULL) 423 intel_i2c_destroy(i2cbus);
425 intel_i2c_destroy(i2cbus); 424 if (!(i2cbus = intel_i2c_create(dev, gpio,
426 if (!(i2cbus = intel_i2c_create(dev, gpio, 425 gpio == GPIOB ? "DVOI2C_B" : "DVOI2C_E"))) {
427 gpio == GPIOB ? "DVOI2C_B" : "DVOI2C_E"))) { 426 continue;
428 continue;
429 }
430 gpio_inited = gpio;
431 } 427 }
432 428
433 if (dvo->dev_ops!= NULL) 429 if (dvo->dev_ops!= NULL)
diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c
index 1af7d68e3807..1d30802e773e 100644
--- a/drivers/gpu/drm/i915/intel_fb.c
+++ b/drivers/gpu/drm/i915/intel_fb.c
@@ -453,7 +453,7 @@ static int intelfb_create(struct drm_device *dev, uint32_t fb_width,
453 size = ALIGN(size, PAGE_SIZE); 453 size = ALIGN(size, PAGE_SIZE);
454 fbo = drm_gem_object_alloc(dev, size); 454 fbo = drm_gem_object_alloc(dev, size);
455 if (!fbo) { 455 if (!fbo) {
456 printk(KERN_ERR "failed to allocate framebuffer\n"); 456 DRM_ERROR("failed to allocate framebuffer\n");
457 ret = -ENOMEM; 457 ret = -ENOMEM;
458 goto out; 458 goto out;
459 } 459 }
@@ -610,8 +610,8 @@ static int intelfb_create(struct drm_device *dev, uint32_t fb_width,
610 par->dev = dev; 610 par->dev = dev;
611 611
612 /* To allow resizeing without swapping buffers */ 612 /* To allow resizeing without swapping buffers */
613 printk("allocated %dx%d fb: 0x%08x, bo %p\n", intel_fb->base.width, 613 DRM_DEBUG("allocated %dx%d fb: 0x%08x, bo %p\n", intel_fb->base.width,
614 intel_fb->base.height, obj_priv->gtt_offset, fbo); 614 intel_fb->base.height, obj_priv->gtt_offset, fbo);
615 615
616 mutex_unlock(&dev->struct_mutex); 616 mutex_unlock(&dev->struct_mutex);
617 return 0; 617 return 0;
@@ -698,13 +698,13 @@ static int intelfb_multi_fb_probe_crtc(struct drm_device *dev, struct drm_crtc *
698 } else 698 } else
699 intelfb_set_par(info); 699 intelfb_set_par(info);
700 700
701 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, 701 DRM_INFO("fb%d: %s frame buffer device\n", info->node,
702 info->fix.id); 702 info->fix.id);
703 703
704 /* Switch back to kernel console on panic */ 704 /* Switch back to kernel console on panic */
705 kernelfb_mode = *modeset; 705 kernelfb_mode = *modeset;
706 atomic_notifier_chain_register(&panic_notifier_list, &paniced); 706 atomic_notifier_chain_register(&panic_notifier_list, &paniced);
707 printk(KERN_INFO "registered panic notifier\n"); 707 DRM_DEBUG("registered panic notifier\n");
708 708
709 return 0; 709 return 0;
710} 710}
@@ -852,13 +852,13 @@ static int intelfb_single_fb_probe(struct drm_device *dev)
852 } else 852 } else
853 intelfb_set_par(info); 853 intelfb_set_par(info);
854 854
855 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, 855 DRM_INFO("fb%d: %s frame buffer device\n", info->node,
856 info->fix.id); 856 info->fix.id);
857 857
858 /* Switch back to kernel console on panic */ 858 /* Switch back to kernel console on panic */
859 kernelfb_mode = *modeset; 859 kernelfb_mode = *modeset;
860 atomic_notifier_chain_register(&panic_notifier_list, &paniced); 860 atomic_notifier_chain_register(&panic_notifier_list, &paniced);
861 printk(KERN_INFO "registered panic notifier\n"); 861 DRM_DEBUG("registered panic notifier\n");
862 862
863 return 0; 863 return 0;
864} 864}
@@ -872,8 +872,8 @@ void intelfb_restore(void)
872{ 872{
873 int ret; 873 int ret;
874 if ((ret = drm_crtc_helper_set_config(&kernelfb_mode)) != 0) { 874 if ((ret = drm_crtc_helper_set_config(&kernelfb_mode)) != 0) {
875 printk(KERN_ERR "Failed to restore crtc configuration: %d\n", 875 DRM_ERROR("Failed to restore crtc configuration: %d\n",
876 ret); 876 ret);
877 } 877 }
878} 878}
879 879
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 4ea2a651b92c..9e30daae37dc 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -31,6 +31,7 @@
31#include "drmP.h" 31#include "drmP.h"
32#include "drm.h" 32#include "drm.h"
33#include "drm_crtc.h" 33#include "drm_crtc.h"
34#include "drm_edid.h"
34#include "intel_drv.h" 35#include "intel_drv.h"
35#include "i915_drm.h" 36#include "i915_drm.h"
36#include "i915_drv.h" 37#include "i915_drv.h"
@@ -56,8 +57,7 @@ static void intel_hdmi_mode_set(struct drm_encoder *encoder,
56 sdvox = SDVO_ENCODING_HDMI | 57 sdvox = SDVO_ENCODING_HDMI |
57 SDVO_BORDER_ENABLE | 58 SDVO_BORDER_ENABLE |
58 SDVO_VSYNC_ACTIVE_HIGH | 59 SDVO_VSYNC_ACTIVE_HIGH |
59 SDVO_HSYNC_ACTIVE_HIGH | 60 SDVO_HSYNC_ACTIVE_HIGH;
60 SDVO_NULL_PACKETS_DURING_VSYNC;
61 61
62 if (hdmi_priv->has_hdmi_sink) 62 if (hdmi_priv->has_hdmi_sink)
63 sdvox |= SDVO_AUDIO_ENABLE; 63 sdvox |= SDVO_AUDIO_ENABLE;
@@ -129,20 +129,26 @@ static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
129 return true; 129 return true;
130} 130}
131 131
132static void 132static enum drm_connector_status
133intel_hdmi_sink_detect(struct drm_connector *connector) 133intel_hdmi_edid_detect(struct drm_connector *connector)
134{ 134{
135 struct intel_output *intel_output = to_intel_output(connector); 135 struct intel_output *intel_output = to_intel_output(connector);
136 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; 136 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
137 struct edid *edid = NULL; 137 struct edid *edid = NULL;
138 enum drm_connector_status status = connector_status_disconnected;
138 139
139 edid = drm_get_edid(&intel_output->base, 140 edid = drm_get_edid(&intel_output->base,
140 &intel_output->ddc_bus->adapter); 141 intel_output->ddc_bus);
141 if (edid != NULL) { 142 hdmi_priv->has_hdmi_sink = false;
142 hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid); 143 if (edid) {
143 kfree(edid); 144 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
145 status = connector_status_connected;
146 hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
147 }
144 intel_output->base.display_info.raw_edid = NULL; 148 intel_output->base.display_info.raw_edid = NULL;
149 kfree(edid);
145 } 150 }
151 return status;
146} 152}
147 153
148static enum drm_connector_status 154static enum drm_connector_status
@@ -154,11 +160,7 @@ igdng_hdmi_detect(struct drm_connector *connector)
154 /* FIXME hotplug detect */ 160 /* FIXME hotplug detect */
155 161
156 hdmi_priv->has_hdmi_sink = false; 162 hdmi_priv->has_hdmi_sink = false;
157 intel_hdmi_sink_detect(connector); 163 return intel_hdmi_edid_detect(connector);
158 if (hdmi_priv->has_hdmi_sink)
159 return connector_status_connected;
160 else
161 return connector_status_disconnected;
162} 164}
163 165
164static enum drm_connector_status 166static enum drm_connector_status
@@ -201,10 +203,9 @@ intel_hdmi_detect(struct drm_connector *connector)
201 return connector_status_unknown; 203 return connector_status_unknown;
202 } 204 }
203 205
204 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) != 0) { 206 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) != 0)
205 intel_hdmi_sink_detect(connector); 207 return intel_hdmi_edid_detect(connector);
206 return connector_status_connected; 208 else
207 } else
208 return connector_status_disconnected; 209 return connector_status_disconnected;
209} 210}
210 211
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index f7061f68d050..62b8bead7652 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -124,6 +124,7 @@ static void set_data(void *data, int state_high)
124 * @output: driver specific output device 124 * @output: driver specific output device
125 * @reg: GPIO reg to use 125 * @reg: GPIO reg to use
126 * @name: name for this bus 126 * @name: name for this bus
127 * @slave_addr: slave address (if fixed)
127 * 128 *
128 * Creates and registers a new i2c bus with the Linux i2c layer, for use 129 * Creates and registers a new i2c bus with the Linux i2c layer, for use
129 * in output probing and control (e.g. DDC or SDVO control functions). 130 * in output probing and control (e.g. DDC or SDVO control functions).
@@ -139,8 +140,8 @@ static void set_data(void *data, int state_high)
139 * %GPIOH 140 * %GPIOH
140 * see PRM for details on how these different busses are used. 141 * see PRM for details on how these different busses are used.
141 */ 142 */
142struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg, 143struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg,
143 const char *name) 144 const char *name)
144{ 145{
145 struct intel_i2c_chan *chan; 146 struct intel_i2c_chan *chan;
146 147
@@ -174,7 +175,7 @@ struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg,
174 intel_i2c_quirk_set(dev, false); 175 intel_i2c_quirk_set(dev, false);
175 udelay(20); 176 udelay(20);
176 177
177 return chan; 178 return &chan->adapter;
178 179
179out_free: 180out_free:
180 kfree(chan); 181 kfree(chan);
@@ -187,11 +188,16 @@ out_free:
187 * 188 *
188 * Unregister the adapter from the i2c layer, then free the structure. 189 * Unregister the adapter from the i2c layer, then free the structure.
189 */ 190 */
190void intel_i2c_destroy(struct intel_i2c_chan *chan) 191void intel_i2c_destroy(struct i2c_adapter *adapter)
191{ 192{
192 if (!chan) 193 struct intel_i2c_chan *chan;
194
195 if (!adapter)
193 return; 196 return;
194 197
198 chan = container_of(adapter,
199 struct intel_i2c_chan,
200 adapter);
195 i2c_del_adapter(&chan->adapter); 201 i2c_del_adapter(&chan->adapter);
196 kfree(chan); 202 kfree(chan);
197} 203}
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index f073ed8432e8..9ab38efffecf 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -36,9 +36,25 @@
36#include "intel_drv.h" 36#include "intel_drv.h"
37#include "i915_drm.h" 37#include "i915_drm.h"
38#include "i915_drv.h" 38#include "i915_drv.h"
39#include <linux/acpi.h>
39 40
40#define I915_LVDS "i915_lvds" 41#define I915_LVDS "i915_lvds"
41 42
43/*
44 * the following four scaling options are defined.
45 * #define DRM_MODE_SCALE_NON_GPU 0
46 * #define DRM_MODE_SCALE_FULLSCREEN 1
47 * #define DRM_MODE_SCALE_NO_SCALE 2
48 * #define DRM_MODE_SCALE_ASPECT 3
49 */
50
51/* Private structure for the integrated LVDS support */
52struct intel_lvds_priv {
53 int fitting_mode;
54 u32 pfit_control;
55 u32 pfit_pgm_ratios;
56};
57
42/** 58/**
43 * Sets the backlight level. 59 * Sets the backlight level.
44 * 60 *
@@ -213,26 +229,45 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
213 struct drm_display_mode *mode, 229 struct drm_display_mode *mode,
214 struct drm_display_mode *adjusted_mode) 230 struct drm_display_mode *adjusted_mode)
215{ 231{
232 /*
233 * float point operation is not supported . So the PANEL_RATIO_FACTOR
234 * is defined, which can avoid the float point computation when
235 * calculating the panel ratio.
236 */
237#define PANEL_RATIO_FACTOR 8192
216 struct drm_device *dev = encoder->dev; 238 struct drm_device *dev = encoder->dev;
217 struct drm_i915_private *dev_priv = dev->dev_private; 239 struct drm_i915_private *dev_priv = dev->dev_private;
218 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); 240 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
219 struct drm_encoder *tmp_encoder; 241 struct drm_encoder *tmp_encoder;
242 struct intel_output *intel_output = enc_to_intel_output(encoder);
243 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
244 u32 pfit_control = 0, pfit_pgm_ratios = 0;
245 int left_border = 0, right_border = 0, top_border = 0;
246 int bottom_border = 0;
247 bool border = 0;
248 int panel_ratio, desired_ratio, vert_scale, horiz_scale;
249 int horiz_ratio, vert_ratio;
250 u32 hsync_width, vsync_width;
251 u32 hblank_width, vblank_width;
252 u32 hsync_pos, vsync_pos;
220 253
221 /* Should never happen!! */ 254 /* Should never happen!! */
222 if (!IS_I965G(dev) && intel_crtc->pipe == 0) { 255 if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
223 printk(KERN_ERR "Can't support LVDS on pipe A\n"); 256 DRM_ERROR("Can't support LVDS on pipe A\n");
224 return false; 257 return false;
225 } 258 }
226 259
227 /* Should never happen!! */ 260 /* Should never happen!! */
228 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) { 261 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
229 if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) { 262 if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
230 printk(KERN_ERR "Can't enable LVDS and another " 263 DRM_ERROR("Can't enable LVDS and another "
231 "encoder on the same pipe\n"); 264 "encoder on the same pipe\n");
232 return false; 265 return false;
233 } 266 }
234 } 267 }
235 268 /* If we don't have a panel mode, there is nothing we can do */
269 if (dev_priv->panel_fixed_mode == NULL)
270 return true;
236 /* 271 /*
237 * If we have timings from the BIOS for the panel, put them in 272 * If we have timings from the BIOS for the panel, put them in
238 * to the adjusted mode. The CRTC will be set up for this mode, 273 * to the adjusted mode. The CRTC will be set up for this mode,
@@ -256,6 +291,243 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
256 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); 291 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
257 } 292 }
258 293
294 /* Make sure pre-965s set dither correctly */
295 if (!IS_I965G(dev)) {
296 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
297 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
298 }
299
300 /* Native modes don't need fitting */
301 if (adjusted_mode->hdisplay == mode->hdisplay &&
302 adjusted_mode->vdisplay == mode->vdisplay) {
303 pfit_pgm_ratios = 0;
304 border = 0;
305 goto out;
306 }
307
308 /* 965+ wants fuzzy fitting */
309 if (IS_I965G(dev))
310 pfit_control |= (intel_crtc->pipe << PFIT_PIPE_SHIFT) |
311 PFIT_FILTER_FUZZY;
312
313 hsync_width = adjusted_mode->crtc_hsync_end -
314 adjusted_mode->crtc_hsync_start;
315 vsync_width = adjusted_mode->crtc_vsync_end -
316 adjusted_mode->crtc_vsync_start;
317 hblank_width = adjusted_mode->crtc_hblank_end -
318 adjusted_mode->crtc_hblank_start;
319 vblank_width = adjusted_mode->crtc_vblank_end -
320 adjusted_mode->crtc_vblank_start;
321 /*
322 * Deal with panel fitting options. Figure out how to stretch the
323 * image based on its aspect ratio & the current panel fitting mode.
324 */
325 panel_ratio = adjusted_mode->hdisplay * PANEL_RATIO_FACTOR /
326 adjusted_mode->vdisplay;
327 desired_ratio = mode->hdisplay * PANEL_RATIO_FACTOR /
328 mode->vdisplay;
329 /*
330 * Enable automatic panel scaling for non-native modes so that they fill
331 * the screen. Should be enabled before the pipe is enabled, according
332 * to register description and PRM.
333 * Change the value here to see the borders for debugging
334 */
335 I915_WRITE(BCLRPAT_A, 0);
336 I915_WRITE(BCLRPAT_B, 0);
337
338 switch (lvds_priv->fitting_mode) {
339 case DRM_MODE_SCALE_NO_SCALE:
340 /*
341 * For centered modes, we have to calculate border widths &
342 * heights and modify the values programmed into the CRTC.
343 */
344 left_border = (adjusted_mode->hdisplay - mode->hdisplay) / 2;
345 right_border = left_border;
346 if (mode->hdisplay & 1)
347 right_border++;
348 top_border = (adjusted_mode->vdisplay - mode->vdisplay) / 2;
349 bottom_border = top_border;
350 if (mode->vdisplay & 1)
351 bottom_border++;
352 /* Set active & border values */
353 adjusted_mode->crtc_hdisplay = mode->hdisplay;
354 /* Keep the boder be even */
355 if (right_border & 1)
356 right_border++;
357 /* use the border directly instead of border minuse one */
358 adjusted_mode->crtc_hblank_start = mode->hdisplay +
359 right_border;
360 /* keep the blank width constant */
361 adjusted_mode->crtc_hblank_end =
362 adjusted_mode->crtc_hblank_start + hblank_width;
363 /* get the hsync pos relative to hblank start */
364 hsync_pos = (hblank_width - hsync_width) / 2;
365 /* keep the hsync pos be even */
366 if (hsync_pos & 1)
367 hsync_pos++;
368 adjusted_mode->crtc_hsync_start =
369 adjusted_mode->crtc_hblank_start + hsync_pos;
370 /* keep the hsync width constant */
371 adjusted_mode->crtc_hsync_end =
372 adjusted_mode->crtc_hsync_start + hsync_width;
373 adjusted_mode->crtc_vdisplay = mode->vdisplay;
374 /* use the border instead of border minus one */
375 adjusted_mode->crtc_vblank_start = mode->vdisplay +
376 bottom_border;
377 /* keep the vblank width constant */
378 adjusted_mode->crtc_vblank_end =
379 adjusted_mode->crtc_vblank_start + vblank_width;
380 /* get the vsync start postion relative to vblank start */
381 vsync_pos = (vblank_width - vsync_width) / 2;
382 adjusted_mode->crtc_vsync_start =
383 adjusted_mode->crtc_vblank_start + vsync_pos;
384 /* keep the vsync width constant */
385 adjusted_mode->crtc_vsync_end =
386 adjusted_mode->crtc_vblank_start + vsync_width;
387 border = 1;
388 break;
389 case DRM_MODE_SCALE_ASPECT:
390 /* Scale but preserve the spect ratio */
391 pfit_control |= PFIT_ENABLE;
392 if (IS_I965G(dev)) {
393 /* 965+ is easy, it does everything in hw */
394 if (panel_ratio > desired_ratio)
395 pfit_control |= PFIT_SCALING_PILLAR;
396 else if (panel_ratio < desired_ratio)
397 pfit_control |= PFIT_SCALING_LETTER;
398 else
399 pfit_control |= PFIT_SCALING_AUTO;
400 } else {
401 /*
402 * For earlier chips we have to calculate the scaling
403 * ratio by hand and program it into the
404 * PFIT_PGM_RATIO register
405 */
406 u32 horiz_bits, vert_bits, bits = 12;
407 horiz_ratio = mode->hdisplay * PANEL_RATIO_FACTOR/
408 adjusted_mode->hdisplay;
409 vert_ratio = mode->vdisplay * PANEL_RATIO_FACTOR/
410 adjusted_mode->vdisplay;
411 horiz_scale = adjusted_mode->hdisplay *
412 PANEL_RATIO_FACTOR / mode->hdisplay;
413 vert_scale = adjusted_mode->vdisplay *
414 PANEL_RATIO_FACTOR / mode->vdisplay;
415
416 /* retain aspect ratio */
417 if (panel_ratio > desired_ratio) { /* Pillar */
418 u32 scaled_width;
419 scaled_width = mode->hdisplay * vert_scale /
420 PANEL_RATIO_FACTOR;
421 horiz_ratio = vert_ratio;
422 pfit_control |= (VERT_AUTO_SCALE |
423 VERT_INTERP_BILINEAR |
424 HORIZ_INTERP_BILINEAR);
425 /* Pillar will have left/right borders */
426 left_border = (adjusted_mode->hdisplay -
427 scaled_width) / 2;
428 right_border = left_border;
429 if (mode->hdisplay & 1) /* odd resolutions */
430 right_border++;
431 /* keep the border be even */
432 if (right_border & 1)
433 right_border++;
434 adjusted_mode->crtc_hdisplay = scaled_width;
435 /* use border instead of border minus one */
436 adjusted_mode->crtc_hblank_start =
437 scaled_width + right_border;
438 /* keep the hblank width constant */
439 adjusted_mode->crtc_hblank_end =
440 adjusted_mode->crtc_hblank_start +
441 hblank_width;
442 /*
443 * get the hsync start pos relative to
444 * hblank start
445 */
446 hsync_pos = (hblank_width - hsync_width) / 2;
447 /* keep the hsync_pos be even */
448 if (hsync_pos & 1)
449 hsync_pos++;
450 adjusted_mode->crtc_hsync_start =
451 adjusted_mode->crtc_hblank_start +
452 hsync_pos;
453 /* keept hsync width constant */
454 adjusted_mode->crtc_hsync_end =
455 adjusted_mode->crtc_hsync_start +
456 hsync_width;
457 border = 1;
458 } else if (panel_ratio < desired_ratio) { /* letter */
459 u32 scaled_height = mode->vdisplay *
460 horiz_scale / PANEL_RATIO_FACTOR;
461 vert_ratio = horiz_ratio;
462 pfit_control |= (HORIZ_AUTO_SCALE |
463 VERT_INTERP_BILINEAR |
464 HORIZ_INTERP_BILINEAR);
465 /* Letterbox will have top/bottom border */
466 top_border = (adjusted_mode->vdisplay -
467 scaled_height) / 2;
468 bottom_border = top_border;
469 if (mode->vdisplay & 1)
470 bottom_border++;
471 adjusted_mode->crtc_vdisplay = scaled_height;
472 /* use border instead of border minus one */
473 adjusted_mode->crtc_vblank_start =
474 scaled_height + bottom_border;
475 /* keep the vblank width constant */
476 adjusted_mode->crtc_vblank_end =
477 adjusted_mode->crtc_vblank_start +
478 vblank_width;
479 /*
480 * get the vsync start pos relative to
481 * vblank start
482 */
483 vsync_pos = (vblank_width - vsync_width) / 2;
484 adjusted_mode->crtc_vsync_start =
485 adjusted_mode->crtc_vblank_start +
486 vsync_pos;
487 /* keep the vsync width constant */
488 adjusted_mode->crtc_vsync_end =
489 adjusted_mode->crtc_vsync_start +
490 vsync_width;
491 border = 1;
492 } else {
493 /* Aspects match, Let hw scale both directions */
494 pfit_control |= (VERT_AUTO_SCALE |
495 HORIZ_AUTO_SCALE |
496 VERT_INTERP_BILINEAR |
497 HORIZ_INTERP_BILINEAR);
498 }
499 horiz_bits = (1 << bits) * horiz_ratio /
500 PANEL_RATIO_FACTOR;
501 vert_bits = (1 << bits) * vert_ratio /
502 PANEL_RATIO_FACTOR;
503 pfit_pgm_ratios =
504 ((vert_bits << PFIT_VERT_SCALE_SHIFT) &
505 PFIT_VERT_SCALE_MASK) |
506 ((horiz_bits << PFIT_HORIZ_SCALE_SHIFT) &
507 PFIT_HORIZ_SCALE_MASK);
508 }
509 break;
510
511 case DRM_MODE_SCALE_FULLSCREEN:
512 /*
513 * Full scaling, even if it changes the aspect ratio.
514 * Fortunately this is all done for us in hw.
515 */
516 pfit_control |= PFIT_ENABLE;
517 if (IS_I965G(dev))
518 pfit_control |= PFIT_SCALING_AUTO;
519 else
520 pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
521 VERT_INTERP_BILINEAR |
522 HORIZ_INTERP_BILINEAR);
523 break;
524 default:
525 break;
526 }
527
528out:
529 lvds_priv->pfit_control = pfit_control;
530 lvds_priv->pfit_pgm_ratios = pfit_pgm_ratios;
259 /* 531 /*
260 * XXX: It would be nice to support lower refresh rates on the 532 * XXX: It would be nice to support lower refresh rates on the
261 * panels to reduce power consumption, and perhaps match the 533 * panels to reduce power consumption, and perhaps match the
@@ -301,8 +573,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
301{ 573{
302 struct drm_device *dev = encoder->dev; 574 struct drm_device *dev = encoder->dev;
303 struct drm_i915_private *dev_priv = dev->dev_private; 575 struct drm_i915_private *dev_priv = dev->dev_private;
304 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); 576 struct intel_output *intel_output = enc_to_intel_output(encoder);
305 u32 pfit_control; 577 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
306 578
307 /* 579 /*
308 * The LVDS pin pair will already have been turned on in the 580 * The LVDS pin pair will already have been turned on in the
@@ -319,22 +591,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
319 * screen. Should be enabled before the pipe is enabled, according to 591 * screen. Should be enabled before the pipe is enabled, according to
320 * register description and PRM. 592 * register description and PRM.
321 */ 593 */
322 if (mode->hdisplay != adjusted_mode->hdisplay || 594 I915_WRITE(PFIT_PGM_RATIOS, lvds_priv->pfit_pgm_ratios);
323 mode->vdisplay != adjusted_mode->vdisplay) 595 I915_WRITE(PFIT_CONTROL, lvds_priv->pfit_control);
324 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
325 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
326 HORIZ_INTERP_BILINEAR);
327 else
328 pfit_control = 0;
329
330 if (!IS_I965G(dev)) {
331 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
332 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
333 }
334 else
335 pfit_control |= intel_crtc->pipe << PFIT_PIPE_SHIFT;
336
337 I915_WRITE(PFIT_CONTROL, pfit_control);
338} 596}
339 597
340/** 598/**
@@ -406,6 +664,34 @@ static int intel_lvds_set_property(struct drm_connector *connector,
406 struct drm_property *property, 664 struct drm_property *property,
407 uint64_t value) 665 uint64_t value)
408{ 666{
667 struct drm_device *dev = connector->dev;
668 struct intel_output *intel_output =
669 to_intel_output(connector);
670
671 if (property == dev->mode_config.scaling_mode_property &&
672 connector->encoder) {
673 struct drm_crtc *crtc = connector->encoder->crtc;
674 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
675 if (value == DRM_MODE_SCALE_NON_GPU) {
676 DRM_DEBUG_KMS(I915_LVDS,
677 "non_GPU property is unsupported\n");
678 return 0;
679 }
680 if (lvds_priv->fitting_mode == value) {
681 /* the LVDS scaling property is not changed */
682 return 0;
683 }
684 lvds_priv->fitting_mode = value;
685 if (crtc && crtc->enabled) {
686 /*
687 * If the CRTC is enabled, the display will be changed
688 * according to the new panel fitting mode.
689 */
690 drm_crtc_helper_set_mode(crtc, &crtc->mode,
691 crtc->x, crtc->y, crtc->fb);
692 }
693 }
694
409 return 0; 695 return 0;
410} 696}
411 697
@@ -456,7 +742,7 @@ static const struct dmi_system_id intel_no_lvds[] = {
456 .callback = intel_no_lvds_dmi_callback, 742 .callback = intel_no_lvds_dmi_callback,
457 .ident = "Apple Mac Mini (Core series)", 743 .ident = "Apple Mac Mini (Core series)",
458 .matches = { 744 .matches = {
459 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 745 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
460 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"), 746 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
461 }, 747 },
462 }, 748 },
@@ -464,7 +750,7 @@ static const struct dmi_system_id intel_no_lvds[] = {
464 .callback = intel_no_lvds_dmi_callback, 750 .callback = intel_no_lvds_dmi_callback,
465 .ident = "Apple Mac Mini (Core 2 series)", 751 .ident = "Apple Mac Mini (Core 2 series)",
466 .matches = { 752 .matches = {
467 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 753 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
468 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"), 754 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
469 }, 755 },
470 }, 756 },
@@ -503,6 +789,65 @@ static const struct dmi_system_id intel_no_lvds[] = {
503 { } /* terminating entry */ 789 { } /* terminating entry */
504}; 790};
505 791
792#ifdef CONFIG_ACPI
793/*
794 * check_lid_device -- check whether @handle is an ACPI LID device.
795 * @handle: ACPI device handle
796 * @level : depth in the ACPI namespace tree
797 * @context: the number of LID device when we find the device
798 * @rv: a return value to fill if desired (Not use)
799 */
800static acpi_status
801check_lid_device(acpi_handle handle, u32 level, void *context,
802 void **return_value)
803{
804 struct acpi_device *acpi_dev;
805 int *lid_present = context;
806
807 acpi_dev = NULL;
808 /* Get the acpi device for device handle */
809 if (acpi_bus_get_device(handle, &acpi_dev) || !acpi_dev) {
810 /* If there is no ACPI device for handle, return */
811 return AE_OK;
812 }
813
814 if (!strncmp(acpi_device_hid(acpi_dev), "PNP0C0D", 7))
815 *lid_present = 1;
816
817 return AE_OK;
818}
819
820/**
821 * check whether there exists the ACPI LID device by enumerating the ACPI
822 * device tree.
823 */
824static int intel_lid_present(void)
825{
826 int lid_present = 0;
827
828 if (acpi_disabled) {
829 /* If ACPI is disabled, there is no ACPI device tree to
830 * check, so assume the LID device would have been present.
831 */
832 return 1;
833 }
834
835 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
836 ACPI_UINT32_MAX,
837 check_lid_device, &lid_present, NULL);
838
839 return lid_present;
840}
841#else
842static int intel_lid_present(void)
843{
844 /* In the absence of ACPI built in, assume that the LID device would
845 * have been present.
846 */
847 return 1;
848}
849#endif
850
506/** 851/**
507 * intel_lvds_init - setup LVDS connectors on this device 852 * intel_lvds_init - setup LVDS connectors on this device
508 * @dev: drm device 853 * @dev: drm device
@@ -518,6 +863,7 @@ void intel_lvds_init(struct drm_device *dev)
518 struct drm_encoder *encoder; 863 struct drm_encoder *encoder;
519 struct drm_display_mode *scan; /* *modes, *bios_mode; */ 864 struct drm_display_mode *scan; /* *modes, *bios_mode; */
520 struct drm_crtc *crtc; 865 struct drm_crtc *crtc;
866 struct intel_lvds_priv *lvds_priv;
521 u32 lvds; 867 u32 lvds;
522 int pipe, gpio = GPIOC; 868 int pipe, gpio = GPIOC;
523 869
@@ -525,13 +871,24 @@ void intel_lvds_init(struct drm_device *dev)
525 if (dmi_check_system(intel_no_lvds)) 871 if (dmi_check_system(intel_no_lvds))
526 return; 872 return;
527 873
874 /* Assume that any device without an ACPI LID device also doesn't
875 * have an integrated LVDS. We would be better off parsing the BIOS
876 * to get a reliable indicator, but that code isn't written yet.
877 *
878 * In the case of all-in-one desktops using LVDS that we've seen,
879 * they're using SDVO LVDS.
880 */
881 if (!intel_lid_present())
882 return;
883
528 if (IS_IGDNG(dev)) { 884 if (IS_IGDNG(dev)) {
529 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0) 885 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
530 return; 886 return;
531 gpio = PCH_GPIOC; 887 gpio = PCH_GPIOC;
532 } 888 }
533 889
534 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); 890 intel_output = kzalloc(sizeof(struct intel_output) +
891 sizeof(struct intel_lvds_priv), GFP_KERNEL);
535 if (!intel_output) { 892 if (!intel_output) {
536 return; 893 return;
537 } 894 }
@@ -553,7 +910,18 @@ void intel_lvds_init(struct drm_device *dev)
553 connector->interlace_allowed = false; 910 connector->interlace_allowed = false;
554 connector->doublescan_allowed = false; 911 connector->doublescan_allowed = false;
555 912
913 lvds_priv = (struct intel_lvds_priv *)(intel_output + 1);
914 intel_output->dev_priv = lvds_priv;
915 /* create the scaling mode property */
916 drm_mode_create_scaling_mode_property(dev);
917 /*
918 * the initial panel fitting mode will be FULL_SCREEN.
919 */
556 920
921 drm_connector_attach_property(&intel_output->base,
922 dev->mode_config.scaling_mode_property,
923 DRM_MODE_SCALE_FULLSCREEN);
924 lvds_priv->fitting_mode = DRM_MODE_SCALE_FULLSCREEN;
557 /* 925 /*
558 * LVDS discovery: 926 * LVDS discovery:
559 * 1) check for EDID on DDC 927 * 1) check for EDID on DDC
@@ -649,5 +1017,5 @@ failed:
649 if (intel_output->ddc_bus) 1017 if (intel_output->ddc_bus)
650 intel_i2c_destroy(intel_output->ddc_bus); 1018 intel_i2c_destroy(intel_output->ddc_bus);
651 drm_connector_cleanup(connector); 1019 drm_connector_cleanup(connector);
652 kfree(connector); 1020 kfree(intel_output);
653} 1021}
diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
index e0910fefce87..67e2f4632a24 100644
--- a/drivers/gpu/drm/i915/intel_modes.c
+++ b/drivers/gpu/drm/i915/intel_modes.c
@@ -53,10 +53,9 @@ bool intel_ddc_probe(struct intel_output *intel_output)
53 } 53 }
54 }; 54 };
55 55
56 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, true); 56 intel_i2c_quirk_set(intel_output->base.dev, true);
57 ret = i2c_transfer(&intel_output->ddc_bus->adapter, msgs, 2); 57 ret = i2c_transfer(intel_output->ddc_bus, msgs, 2);
58 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, false); 58 intel_i2c_quirk_set(intel_output->base.dev, false);
59
60 if (ret == 2) 59 if (ret == 2)
61 return true; 60 return true;
62 61
@@ -74,10 +73,9 @@ int intel_ddc_get_modes(struct intel_output *intel_output)
74 struct edid *edid; 73 struct edid *edid;
75 int ret = 0; 74 int ret = 0;
76 75
77 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, true); 76 intel_i2c_quirk_set(intel_output->base.dev, true);
78 edid = drm_get_edid(&intel_output->base, 77 edid = drm_get_edid(&intel_output->base, intel_output->ddc_bus);
79 &intel_output->ddc_bus->adapter); 78 intel_i2c_quirk_set(intel_output->base.dev, false);
80 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, false);
81 if (edid) { 79 if (edid) {
82 drm_mode_connector_update_edid_property(&intel_output->base, 80 drm_mode_connector_update_edid_property(&intel_output->base,
83 edid); 81 edid);
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 9a00adb3a508..4f0c30948bc4 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -38,8 +38,7 @@
38#undef SDVO_DEBUG 38#undef SDVO_DEBUG
39#define I915_SDVO "i915_sdvo" 39#define I915_SDVO "i915_sdvo"
40struct intel_sdvo_priv { 40struct intel_sdvo_priv {
41 struct intel_i2c_chan *i2c_bus; 41 u8 slave_addr;
42 int slaveaddr;
43 42
44 /* Register for the SDVO device: SDVOB or SDVOC */ 43 /* Register for the SDVO device: SDVOB or SDVOC */
45 int output_device; 44 int output_device;
@@ -69,12 +68,23 @@ struct intel_sdvo_priv {
69 * This is set if we treat the device as HDMI, instead of DVI. 68 * This is set if we treat the device as HDMI, instead of DVI.
70 */ 69 */
71 bool is_hdmi; 70 bool is_hdmi;
71
72 /** 72 /**
73 * This is set if we detect output of sdvo device as LVDS. 73 * This is set if we detect output of sdvo device as LVDS.
74 */ 74 */
75 bool is_lvds; 75 bool is_lvds;
76 76
77 /** 77 /**
78 * This is sdvo flags for input timing.
79 */
80 uint8_t sdvo_flags;
81
82 /**
83 * This is sdvo fixed pannel mode pointer
84 */
85 struct drm_display_mode *sdvo_lvds_fixed_mode;
86
87 /**
78 * Returned SDTV resolutions allowed for the current format, if the 88 * Returned SDTV resolutions allowed for the current format, if the
79 * device reported it. 89 * device reported it.
80 */ 90 */
@@ -146,13 +156,13 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
146 156
147 struct i2c_msg msgs[] = { 157 struct i2c_msg msgs[] = {
148 { 158 {
149 .addr = sdvo_priv->i2c_bus->slave_addr, 159 .addr = sdvo_priv->slave_addr >> 1,
150 .flags = 0, 160 .flags = 0,
151 .len = 1, 161 .len = 1,
152 .buf = out_buf, 162 .buf = out_buf,
153 }, 163 },
154 { 164 {
155 .addr = sdvo_priv->i2c_bus->slave_addr, 165 .addr = sdvo_priv->slave_addr >> 1,
156 .flags = I2C_M_RD, 166 .flags = I2C_M_RD,
157 .len = 1, 167 .len = 1,
158 .buf = buf, 168 .buf = buf,
@@ -162,7 +172,7 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
162 out_buf[0] = addr; 172 out_buf[0] = addr;
163 out_buf[1] = 0; 173 out_buf[1] = 0;
164 174
165 if ((ret = i2c_transfer(&sdvo_priv->i2c_bus->adapter, msgs, 2)) == 2) 175 if ((ret = i2c_transfer(intel_output->i2c_bus, msgs, 2)) == 2)
166 { 176 {
167 *ch = buf[0]; 177 *ch = buf[0];
168 return true; 178 return true;
@@ -175,10 +185,11 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
175static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr, 185static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
176 u8 ch) 186 u8 ch)
177{ 187{
188 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
178 u8 out_buf[2]; 189 u8 out_buf[2];
179 struct i2c_msg msgs[] = { 190 struct i2c_msg msgs[] = {
180 { 191 {
181 .addr = intel_output->i2c_bus->slave_addr, 192 .addr = sdvo_priv->slave_addr >> 1,
182 .flags = 0, 193 .flags = 0,
183 .len = 2, 194 .len = 2,
184 .buf = out_buf, 195 .buf = out_buf,
@@ -188,7 +199,7 @@ static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
188 out_buf[0] = addr; 199 out_buf[0] = addr;
189 out_buf[1] = ch; 200 out_buf[1] = ch;
190 201
191 if (i2c_transfer(&intel_output->i2c_bus->adapter, msgs, 1) == 1) 202 if (i2c_transfer(intel_output->i2c_bus, msgs, 1) == 1)
192 { 203 {
193 return true; 204 return true;
194 } 205 }
@@ -592,6 +603,7 @@ intel_sdvo_create_preferred_input_timing(struct intel_output *output,
592 uint16_t height) 603 uint16_t height)
593{ 604{
594 struct intel_sdvo_preferred_input_timing_args args; 605 struct intel_sdvo_preferred_input_timing_args args;
606 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
595 uint8_t status; 607 uint8_t status;
596 608
597 memset(&args, 0, sizeof(args)); 609 memset(&args, 0, sizeof(args));
@@ -599,7 +611,12 @@ intel_sdvo_create_preferred_input_timing(struct intel_output *output,
599 args.width = width; 611 args.width = width;
600 args.height = height; 612 args.height = height;
601 args.interlace = 0; 613 args.interlace = 0;
602 args.scaled = 0; 614
615 if (sdvo_priv->is_lvds &&
616 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
617 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
618 args.scaled = 1;
619
603 intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, 620 intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
604 &args, sizeof(args)); 621 &args, sizeof(args));
605 status = intel_sdvo_read_response(output, NULL, 0); 622 status = intel_sdvo_read_response(output, NULL, 0);
@@ -944,12 +961,7 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
944 struct intel_output *output = enc_to_intel_output(encoder); 961 struct intel_output *output = enc_to_intel_output(encoder);
945 struct intel_sdvo_priv *dev_priv = output->dev_priv; 962 struct intel_sdvo_priv *dev_priv = output->dev_priv;
946 963
947 if (!dev_priv->is_tv) { 964 if (dev_priv->is_tv) {
948 /* Make the CRTC code factor in the SDVO pixel multiplier. The
949 * SDVO device will be told of the multiplier during mode_set.
950 */
951 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
952 } else {
953 struct intel_sdvo_dtd output_dtd; 965 struct intel_sdvo_dtd output_dtd;
954 bool success; 966 bool success;
955 967
@@ -980,6 +992,7 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
980 intel_sdvo_get_preferred_input_timing(output, 992 intel_sdvo_get_preferred_input_timing(output,
981 &input_dtd); 993 &input_dtd);
982 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); 994 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
995 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
983 996
984 drm_mode_set_crtcinfo(adjusted_mode, 0); 997 drm_mode_set_crtcinfo(adjusted_mode, 0);
985 998
@@ -990,6 +1003,52 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
990 } else { 1003 } else {
991 return false; 1004 return false;
992 } 1005 }
1006 } else if (dev_priv->is_lvds) {
1007 struct intel_sdvo_dtd output_dtd;
1008 bool success;
1009
1010 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1011 /* Set output timings */
1012 intel_sdvo_get_dtd_from_mode(&output_dtd,
1013 dev_priv->sdvo_lvds_fixed_mode);
1014
1015 intel_sdvo_set_target_output(output,
1016 dev_priv->controlled_output);
1017 intel_sdvo_set_output_timing(output, &output_dtd);
1018
1019 /* Set the input timing to the screen. Assume always input 0. */
1020 intel_sdvo_set_target_input(output, true, false);
1021
1022
1023 success = intel_sdvo_create_preferred_input_timing(
1024 output,
1025 mode->clock / 10,
1026 mode->hdisplay,
1027 mode->vdisplay);
1028
1029 if (success) {
1030 struct intel_sdvo_dtd input_dtd;
1031
1032 intel_sdvo_get_preferred_input_timing(output,
1033 &input_dtd);
1034 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1035 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1036
1037 drm_mode_set_crtcinfo(adjusted_mode, 0);
1038
1039 mode->clock = adjusted_mode->clock;
1040
1041 adjusted_mode->clock *=
1042 intel_sdvo_get_pixel_multiplier(mode);
1043 } else {
1044 return false;
1045 }
1046
1047 } else {
1048 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1049 * SDVO device will be told of the multiplier during mode_set.
1050 */
1051 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
993 } 1052 }
994 return true; 1053 return true;
995} 1054}
@@ -1033,15 +1092,16 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1033 1092
1034 /* We have tried to get input timing in mode_fixup, and filled into 1093 /* We have tried to get input timing in mode_fixup, and filled into
1035 adjusted_mode */ 1094 adjusted_mode */
1036 if (sdvo_priv->is_tv) 1095 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
1037 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); 1096 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1038 else 1097 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1098 } else
1039 intel_sdvo_get_dtd_from_mode(&input_dtd, mode); 1099 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
1040 1100
1041 /* If it's a TV, we already set the output timing in mode_fixup. 1101 /* If it's a TV, we already set the output timing in mode_fixup.
1042 * Otherwise, the output timing is equal to the input timing. 1102 * Otherwise, the output timing is equal to the input timing.
1043 */ 1103 */
1044 if (!sdvo_priv->is_tv) { 1104 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
1045 /* Set the output timing to the screen */ 1105 /* Set the output timing to the screen */
1046 intel_sdvo_set_target_output(output, 1106 intel_sdvo_set_target_output(output,
1047 sdvo_priv->controlled_output); 1107 sdvo_priv->controlled_output);
@@ -1116,6 +1176,8 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1116 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT; 1176 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1117 } 1177 }
1118 1178
1179 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1180 sdvox |= SDVO_STALL_SELECT;
1119 intel_sdvo_write_sdvox(output, sdvox); 1181 intel_sdvo_write_sdvox(output, sdvox);
1120} 1182}
1121 1183
@@ -1276,6 +1338,17 @@ static int intel_sdvo_mode_valid(struct drm_connector *connector,
1276 if (sdvo_priv->pixel_clock_max < mode->clock) 1338 if (sdvo_priv->pixel_clock_max < mode->clock)
1277 return MODE_CLOCK_HIGH; 1339 return MODE_CLOCK_HIGH;
1278 1340
1341 if (sdvo_priv->is_lvds == true) {
1342 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1343 return MODE_PANEL;
1344
1345 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1346 return MODE_PANEL;
1347
1348 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1349 return MODE_PANEL;
1350 }
1351
1279 return MODE_OK; 1352 return MODE_OK;
1280} 1353}
1281 1354
@@ -1369,9 +1442,8 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1369 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; 1442 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1370 struct edid *edid = NULL; 1443 struct edid *edid = NULL;
1371 1444
1372 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1373 edid = drm_get_edid(&intel_output->base, 1445 edid = drm_get_edid(&intel_output->base,
1374 &intel_output->ddc_bus->adapter); 1446 intel_output->ddc_bus);
1375 if (edid != NULL) { 1447 if (edid != NULL) {
1376 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid); 1448 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid);
1377 kfree(edid); 1449 kfree(edid);
@@ -1549,23 +1621,21 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1549static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) 1621static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1550{ 1622{
1551 struct intel_output *intel_output = to_intel_output(connector); 1623 struct intel_output *intel_output = to_intel_output(connector);
1552 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1553 struct drm_i915_private *dev_priv = connector->dev->dev_private; 1624 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1625 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1626 struct drm_display_mode *newmode;
1554 1627
1555 /* 1628 /*
1556 * Attempt to get the mode list from DDC. 1629 * Attempt to get the mode list from DDC.
1557 * Assume that the preferred modes are 1630 * Assume that the preferred modes are
1558 * arranged in priority order. 1631 * arranged in priority order.
1559 */ 1632 */
1560 /* set the bus switch and get the modes */
1561 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1562 intel_ddc_get_modes(intel_output); 1633 intel_ddc_get_modes(intel_output);
1563 if (list_empty(&connector->probed_modes) == false) 1634 if (list_empty(&connector->probed_modes) == false)
1564 return; 1635 goto end;
1565 1636
1566 /* Fetch modes from VBT */ 1637 /* Fetch modes from VBT */
1567 if (dev_priv->sdvo_lvds_vbt_mode != NULL) { 1638 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
1568 struct drm_display_mode *newmode;
1569 newmode = drm_mode_duplicate(connector->dev, 1639 newmode = drm_mode_duplicate(connector->dev,
1570 dev_priv->sdvo_lvds_vbt_mode); 1640 dev_priv->sdvo_lvds_vbt_mode);
1571 if (newmode != NULL) { 1641 if (newmode != NULL) {
@@ -1575,6 +1645,16 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1575 drm_mode_probed_add(connector, newmode); 1645 drm_mode_probed_add(connector, newmode);
1576 } 1646 }
1577 } 1647 }
1648
1649end:
1650 list_for_each_entry(newmode, &connector->probed_modes, head) {
1651 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1652 sdvo_priv->sdvo_lvds_fixed_mode =
1653 drm_mode_duplicate(connector->dev, newmode);
1654 break;
1655 }
1656 }
1657
1578} 1658}
1579 1659
1580static int intel_sdvo_get_modes(struct drm_connector *connector) 1660static int intel_sdvo_get_modes(struct drm_connector *connector)
@@ -1597,14 +1677,20 @@ static int intel_sdvo_get_modes(struct drm_connector *connector)
1597static void intel_sdvo_destroy(struct drm_connector *connector) 1677static void intel_sdvo_destroy(struct drm_connector *connector)
1598{ 1678{
1599 struct intel_output *intel_output = to_intel_output(connector); 1679 struct intel_output *intel_output = to_intel_output(connector);
1680 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1600 1681
1601 if (intel_output->i2c_bus) 1682 if (intel_output->i2c_bus)
1602 intel_i2c_destroy(intel_output->i2c_bus); 1683 intel_i2c_destroy(intel_output->i2c_bus);
1603 if (intel_output->ddc_bus) 1684 if (intel_output->ddc_bus)
1604 intel_i2c_destroy(intel_output->ddc_bus); 1685 intel_i2c_destroy(intel_output->ddc_bus);
1605 1686
1687 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
1688 drm_mode_destroy(connector->dev,
1689 sdvo_priv->sdvo_lvds_fixed_mode);
1690
1606 drm_sysfs_connector_remove(connector); 1691 drm_sysfs_connector_remove(connector);
1607 drm_connector_cleanup(connector); 1692 drm_connector_cleanup(connector);
1693
1608 kfree(intel_output); 1694 kfree(intel_output);
1609} 1695}
1610 1696
@@ -1709,7 +1795,7 @@ intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan)
1709 1795
1710 list_for_each_entry(connector, 1796 list_for_each_entry(connector,
1711 &dev->mode_config.connector_list, head) { 1797 &dev->mode_config.connector_list, head) {
1712 if (to_intel_output(connector)->ddc_bus == chan) { 1798 if (to_intel_output(connector)->ddc_bus == &chan->adapter) {
1713 intel_output = to_intel_output(connector); 1799 intel_output = to_intel_output(connector);
1714 break; 1800 break;
1715 } 1801 }
@@ -1723,7 +1809,7 @@ static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
1723 struct intel_output *intel_output; 1809 struct intel_output *intel_output;
1724 struct intel_sdvo_priv *sdvo_priv; 1810 struct intel_sdvo_priv *sdvo_priv;
1725 struct i2c_algo_bit_data *algo_data; 1811 struct i2c_algo_bit_data *algo_data;
1726 struct i2c_algorithm *algo; 1812 const struct i2c_algorithm *algo;
1727 1813
1728 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; 1814 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
1729 intel_output = 1815 intel_output =
@@ -1733,7 +1819,7 @@ static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
1733 return -EINVAL; 1819 return -EINVAL;
1734 1820
1735 sdvo_priv = intel_output->dev_priv; 1821 sdvo_priv = intel_output->dev_priv;
1736 algo = (struct i2c_algorithm *)intel_output->i2c_bus->adapter.algo; 1822 algo = intel_output->i2c_bus->algo;
1737 1823
1738 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); 1824 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1739 return algo->master_xfer(i2c_adap, msgs, num); 1825 return algo->master_xfer(i2c_adap, msgs, num);
@@ -1785,13 +1871,11 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1785 struct drm_connector *connector; 1871 struct drm_connector *connector;
1786 struct intel_output *intel_output; 1872 struct intel_output *intel_output;
1787 struct intel_sdvo_priv *sdvo_priv; 1873 struct intel_sdvo_priv *sdvo_priv;
1788 struct intel_i2c_chan *i2cbus = NULL; 1874
1789 struct intel_i2c_chan *ddcbus = NULL;
1790 int connector_type; 1875 int connector_type;
1791 u8 ch[0x40]; 1876 u8 ch[0x40];
1792 int i; 1877 int i;
1793 int encoder_type, output_id; 1878 int encoder_type;
1794 u8 slave_addr;
1795 1879
1796 intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); 1880 intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
1797 if (!intel_output) { 1881 if (!intel_output) {
@@ -1799,29 +1883,24 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1799 } 1883 }
1800 1884
1801 sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1); 1885 sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1);
1886 sdvo_priv->output_device = output_device;
1887
1888 intel_output->dev_priv = sdvo_priv;
1802 intel_output->type = INTEL_OUTPUT_SDVO; 1889 intel_output->type = INTEL_OUTPUT_SDVO;
1803 1890
1804 /* setup the DDC bus. */ 1891 /* setup the DDC bus. */
1805 if (output_device == SDVOB) 1892 if (output_device == SDVOB)
1806 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); 1893 intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
1807 else 1894 else
1808 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); 1895 intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
1809 1896
1810 if (!i2cbus) 1897 if (!intel_output->i2c_bus)
1811 goto err_inteloutput; 1898 goto err_inteloutput;
1812 1899
1813 slave_addr = intel_sdvo_get_slave_addr(dev, output_device); 1900 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
1814 sdvo_priv->i2c_bus = i2cbus;
1815 1901
1816 if (output_device == SDVOB) { 1902 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
1817 output_id = 1; 1903 intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
1818 } else {
1819 output_id = 2;
1820 }
1821 sdvo_priv->i2c_bus->slave_addr = slave_addr >> 1;
1822 sdvo_priv->output_device = output_device;
1823 intel_output->i2c_bus = i2cbus;
1824 intel_output->dev_priv = sdvo_priv;
1825 1904
1826 /* Read the regs to test if we can talk to the device */ 1905 /* Read the regs to test if we can talk to the device */
1827 for (i = 0; i < 0x40; i++) { 1906 for (i = 0; i < 0x40; i++) {
@@ -1835,17 +1914,15 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1835 1914
1836 /* setup the DDC bus. */ 1915 /* setup the DDC bus. */
1837 if (output_device == SDVOB) 1916 if (output_device == SDVOB)
1838 ddcbus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS"); 1917 intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
1839 else 1918 else
1840 ddcbus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS"); 1919 intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
1841 1920
1842 if (ddcbus == NULL) 1921 if (intel_output->ddc_bus == NULL)
1843 goto err_i2c; 1922 goto err_i2c;
1844 1923
1845 intel_sdvo_i2c_bit_algo.functionality = 1924 /* Wrap with our custom algo which switches to DDC mode */
1846 intel_output->i2c_bus->adapter.algo->functionality; 1925 intel_output->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
1847 ddcbus->adapter.algo = &intel_sdvo_i2c_bit_algo;
1848 intel_output->ddc_bus = ddcbus;
1849 1926
1850 /* In defaut case sdvo lvds is false */ 1927 /* In defaut case sdvo lvds is false */
1851 sdvo_priv->is_lvds = false; 1928 sdvo_priv->is_lvds = false;
@@ -1965,9 +2042,10 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1965 return true; 2042 return true;
1966 2043
1967err_i2c: 2044err_i2c:
1968 if (ddcbus != NULL) 2045 if (intel_output->ddc_bus != NULL)
1969 intel_i2c_destroy(intel_output->ddc_bus); 2046 intel_i2c_destroy(intel_output->ddc_bus);
1970 intel_i2c_destroy(intel_output->i2c_bus); 2047 if (intel_output->i2c_bus != NULL)
2048 intel_i2c_destroy(intel_output->i2c_bus);
1971err_inteloutput: 2049err_inteloutput:
1972 kfree(intel_output); 2050 kfree(intel_output);
1973 2051
diff --git a/drivers/gpu/drm/i915/intel_sdvo_regs.h b/drivers/gpu/drm/i915/intel_sdvo_regs.h
index 193938b7d7f9..ba5cdf8ae40b 100644
--- a/drivers/gpu/drm/i915/intel_sdvo_regs.h
+++ b/drivers/gpu/drm/i915/intel_sdvo_regs.h
@@ -715,6 +715,7 @@ struct intel_sdvo_enhancements_arg {
715 #define SDVO_HBUF_TX_ONCE (2 << 6) 715 #define SDVO_HBUF_TX_ONCE (2 << 6)
716 #define SDVO_HBUF_TX_VSYNC (3 << 6) 716 #define SDVO_HBUF_TX_VSYNC (3 << 6)
717#define SDVO_CMD_GET_AUDIO_TX_INFO 0x9c 717#define SDVO_CMD_GET_AUDIO_TX_INFO 0x9c
718#define SDVO_NEED_TO_STALL (1 << 7)
718 719
719struct intel_sdvo_encode{ 720struct intel_sdvo_encode{
720 u8 dvi_rev; 721 u8 dvi_rev;
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
index ea68992e4416..a43c98e3f077 100644
--- a/drivers/gpu/drm/i915/intel_tv.c
+++ b/drivers/gpu/drm/i915/intel_tv.c
@@ -1383,34 +1383,31 @@ intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output)
1383 /* 1383 /*
1384 * Detect TV by polling) 1384 * Detect TV by polling)
1385 */ 1385 */
1386 if (intel_output->load_detect_temp) { 1386 save_tv_dac = tv_dac;
1387 /* TV not currently running, prod it with destructive detect */ 1387 tv_ctl = I915_READ(TV_CTL);
1388 save_tv_dac = tv_dac; 1388 save_tv_ctl = tv_ctl;
1389 tv_ctl = I915_READ(TV_CTL); 1389 tv_ctl &= ~TV_ENC_ENABLE;
1390 save_tv_ctl = tv_ctl; 1390 tv_ctl &= ~TV_TEST_MODE_MASK;
1391 tv_ctl &= ~TV_ENC_ENABLE; 1391 tv_ctl |= TV_TEST_MODE_MONITOR_DETECT;
1392 tv_ctl &= ~TV_TEST_MODE_MASK; 1392 tv_dac &= ~TVDAC_SENSE_MASK;
1393 tv_ctl |= TV_TEST_MODE_MONITOR_DETECT; 1393 tv_dac &= ~DAC_A_MASK;
1394 tv_dac &= ~TVDAC_SENSE_MASK; 1394 tv_dac &= ~DAC_B_MASK;
1395 tv_dac &= ~DAC_A_MASK; 1395 tv_dac &= ~DAC_C_MASK;
1396 tv_dac &= ~DAC_B_MASK; 1396 tv_dac |= (TVDAC_STATE_CHG_EN |
1397 tv_dac &= ~DAC_C_MASK; 1397 TVDAC_A_SENSE_CTL |
1398 tv_dac |= (TVDAC_STATE_CHG_EN | 1398 TVDAC_B_SENSE_CTL |
1399 TVDAC_A_SENSE_CTL | 1399 TVDAC_C_SENSE_CTL |
1400 TVDAC_B_SENSE_CTL | 1400 DAC_CTL_OVERRIDE |
1401 TVDAC_C_SENSE_CTL | 1401 DAC_A_0_7_V |
1402 DAC_CTL_OVERRIDE | 1402 DAC_B_0_7_V |
1403 DAC_A_0_7_V | 1403 DAC_C_0_7_V);
1404 DAC_B_0_7_V | 1404 I915_WRITE(TV_CTL, tv_ctl);
1405 DAC_C_0_7_V); 1405 I915_WRITE(TV_DAC, tv_dac);
1406 I915_WRITE(TV_CTL, tv_ctl); 1406 intel_wait_for_vblank(dev);
1407 I915_WRITE(TV_DAC, tv_dac); 1407 tv_dac = I915_READ(TV_DAC);
1408 intel_wait_for_vblank(dev); 1408 I915_WRITE(TV_DAC, save_tv_dac);
1409 tv_dac = I915_READ(TV_DAC); 1409 I915_WRITE(TV_CTL, save_tv_ctl);
1410 I915_WRITE(TV_DAC, save_tv_dac); 1410 intel_wait_for_vblank(dev);
1411 I915_WRITE(TV_CTL, save_tv_ctl);
1412 intel_wait_for_vblank(dev);
1413 }
1414 /* 1411 /*
1415 * A B C 1412 * A B C
1416 * 0 1 1 Composite 1413 * 0 1 1 Composite
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index f30aa7274a54..f97563db4e59 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -35,6 +35,23 @@
35#include "atom.h" 35#include "atom.h"
36 36
37/* 37/*
38 * Clear GPU surface registers.
39 */
40static void radeon_surface_init(struct radeon_device *rdev)
41{
42 /* FIXME: check this out */
43 if (rdev->family < CHIP_R600) {
44 int i;
45
46 for (i = 0; i < 8; i++) {
47 WREG32(RADEON_SURFACE0_INFO +
48 i * (RADEON_SURFACE1_INFO - RADEON_SURFACE0_INFO),
49 0);
50 }
51 }
52}
53
54/*
38 * GPU scratch registers helpers function. 55 * GPU scratch registers helpers function.
39 */ 56 */
40static void radeon_scratch_init(struct radeon_device *rdev) 57static void radeon_scratch_init(struct radeon_device *rdev)
@@ -496,6 +513,8 @@ int radeon_device_init(struct radeon_device *rdev,
496 radeon_errata(rdev); 513 radeon_errata(rdev);
497 /* Initialize scratch registers */ 514 /* Initialize scratch registers */
498 radeon_scratch_init(rdev); 515 radeon_scratch_init(rdev);
516 /* Initialize surface registers */
517 radeon_surface_init(rdev);
499 518
500 /* TODO: disable VGA need to use VGA request */ 519 /* TODO: disable VGA need to use VGA request */
501 /* BIOS*/ 520 /* BIOS*/
@@ -604,9 +623,6 @@ int radeon_device_init(struct radeon_device *rdev,
604 if (r) { 623 if (r) {
605 return r; 624 return r;
606 } 625 }
607 if (rdev->fbdev_rfb && rdev->fbdev_rfb->obj) {
608 rdev->fbdev_robj = rdev->fbdev_rfb->obj->driver_private;
609 }
610 if (!ret) { 626 if (!ret) {
611 DRM_INFO("radeon: kernel modesetting successfully initialized.\n"); 627 DRM_INFO("radeon: kernel modesetting successfully initialized.\n");
612 } 628 }
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 09c9fb9f6210..84ba69f48784 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -345,7 +345,7 @@ static void __exit radeon_exit(void)
345 drm_exit(driver); 345 drm_exit(driver);
346} 346}
347 347
348late_initcall(radeon_init); 348module_init(radeon_init);
349module_exit(radeon_exit); 349module_exit(radeon_exit);
350 350
351MODULE_AUTHOR(DRIVER_AUTHOR); 351MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c
index fa86d398945e..9e8f191eb64a 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -478,14 +478,16 @@ int radeonfb_create(struct radeon_device *rdev,
478{ 478{
479 struct fb_info *info; 479 struct fb_info *info;
480 struct radeon_fb_device *rfbdev; 480 struct radeon_fb_device *rfbdev;
481 struct drm_framebuffer *fb; 481 struct drm_framebuffer *fb = NULL;
482 struct radeon_framebuffer *rfb; 482 struct radeon_framebuffer *rfb;
483 struct drm_mode_fb_cmd mode_cmd; 483 struct drm_mode_fb_cmd mode_cmd;
484 struct drm_gem_object *gobj = NULL; 484 struct drm_gem_object *gobj = NULL;
485 struct radeon_object *robj = NULL; 485 struct radeon_object *robj = NULL;
486 struct device *device = &rdev->pdev->dev; 486 struct device *device = &rdev->pdev->dev;
487 int size, aligned_size, ret; 487 int size, aligned_size, ret;
488 u64 fb_gpuaddr;
488 void *fbptr = NULL; 489 void *fbptr = NULL;
490 unsigned long tmp;
489 491
490 mode_cmd.width = surface_width; 492 mode_cmd.width = surface_width;
491 mode_cmd.height = surface_height; 493 mode_cmd.height = surface_height;
@@ -498,11 +500,12 @@ int radeonfb_create(struct radeon_device *rdev,
498 aligned_size = ALIGN(size, PAGE_SIZE); 500 aligned_size = ALIGN(size, PAGE_SIZE);
499 501
500 ret = radeon_gem_object_create(rdev, aligned_size, 0, 502 ret = radeon_gem_object_create(rdev, aligned_size, 0,
501 RADEON_GEM_DOMAIN_VRAM, 503 RADEON_GEM_DOMAIN_VRAM,
502 false, ttm_bo_type_kernel, 504 false, ttm_bo_type_kernel,
503 false, &gobj); 505 false, &gobj);
504 if (ret) { 506 if (ret) {
505 printk(KERN_ERR "failed to allocate framebuffer\n"); 507 printk(KERN_ERR "failed to allocate framebuffer (%d %d)\n",
508 surface_width, surface_height);
506 ret = -ENOMEM; 509 ret = -ENOMEM;
507 goto out; 510 goto out;
508 } 511 }
@@ -515,12 +518,19 @@ int radeonfb_create(struct radeon_device *rdev,
515 ret = -ENOMEM; 518 ret = -ENOMEM;
516 goto out_unref; 519 goto out_unref;
517 } 520 }
521 ret = radeon_object_pin(robj, RADEON_GEM_DOMAIN_VRAM, &fb_gpuaddr);
522 if (ret) {
523 printk(KERN_ERR "failed to pin framebuffer\n");
524 ret = -ENOMEM;
525 goto out_unref;
526 }
518 527
519 list_add(&fb->filp_head, &rdev->ddev->mode_config.fb_kernel_list); 528 list_add(&fb->filp_head, &rdev->ddev->mode_config.fb_kernel_list);
520 529
521 rfb = to_radeon_framebuffer(fb); 530 rfb = to_radeon_framebuffer(fb);
522 *rfb_p = rfb; 531 *rfb_p = rfb;
523 rdev->fbdev_rfb = rfb; 532 rdev->fbdev_rfb = rfb;
533 rdev->fbdev_robj = robj;
524 534
525 info = framebuffer_alloc(sizeof(struct radeon_fb_device), device); 535 info = framebuffer_alloc(sizeof(struct radeon_fb_device), device);
526 if (info == NULL) { 536 if (info == NULL) {
@@ -541,13 +551,13 @@ int radeonfb_create(struct radeon_device *rdev,
541 info->fix.xpanstep = 1; /* doing it in hw */ 551 info->fix.xpanstep = 1; /* doing it in hw */
542 info->fix.ypanstep = 1; /* doing it in hw */ 552 info->fix.ypanstep = 1; /* doing it in hw */
543 info->fix.ywrapstep = 0; 553 info->fix.ywrapstep = 0;
544 info->fix.accel = FB_ACCEL_I830; 554 info->fix.accel = FB_ACCEL_NONE;
545 info->fix.type_aux = 0; 555 info->fix.type_aux = 0;
546 info->flags = FBINFO_DEFAULT; 556 info->flags = FBINFO_DEFAULT;
547 info->fbops = &radeonfb_ops; 557 info->fbops = &radeonfb_ops;
548 info->fix.line_length = fb->pitch; 558 info->fix.line_length = fb->pitch;
549 info->screen_base = fbptr; 559 tmp = fb_gpuaddr - rdev->mc.vram_location;
550 info->fix.smem_start = (unsigned long)fbptr; 560 info->fix.smem_start = rdev->mc.aper_base + tmp;
551 info->fix.smem_len = size; 561 info->fix.smem_len = size;
552 info->screen_base = fbptr; 562 info->screen_base = fbptr;
553 info->screen_size = size; 563 info->screen_size = size;
@@ -562,8 +572,8 @@ int radeonfb_create(struct radeon_device *rdev,
562 info->var.width = -1; 572 info->var.width = -1;
563 info->var.xres = fb_width; 573 info->var.xres = fb_width;
564 info->var.yres = fb_height; 574 info->var.yres = fb_height;
565 info->fix.mmio_start = pci_resource_start(rdev->pdev, 2); 575 info->fix.mmio_start = 0;
566 info->fix.mmio_len = pci_resource_len(rdev->pdev, 2); 576 info->fix.mmio_len = 0;
567 info->pixmap.size = 64*1024; 577 info->pixmap.size = 64*1024;
568 info->pixmap.buf_align = 8; 578 info->pixmap.buf_align = 8;
569 info->pixmap.access_align = 32; 579 info->pixmap.access_align = 32;
@@ -644,7 +654,7 @@ out_unref:
644 if (robj) { 654 if (robj) {
645 radeon_object_kunmap(robj); 655 radeon_object_kunmap(robj);
646 } 656 }
647 if (ret) { 657 if (fb && ret) {
648 list_del(&fb->filp_head); 658 list_del(&fb->filp_head);
649 drm_gem_object_unreference(gobj); 659 drm_gem_object_unreference(gobj);
650 drm_framebuffer_cleanup(fb); 660 drm_framebuffer_cleanup(fb);
@@ -813,6 +823,7 @@ int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb)
813 robj = rfb->obj->driver_private; 823 robj = rfb->obj->driver_private;
814 unregister_framebuffer(info); 824 unregister_framebuffer(info);
815 radeon_object_kunmap(robj); 825 radeon_object_kunmap(robj);
826 radeon_object_unpin(robj);
816 framebuffer_release(info); 827 framebuffer_release(info);
817 } 828 }
818 829
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 983e8df5e000..bac0d06c52ac 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -223,7 +223,6 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
223{ 223{
224 uint32_t flags; 224 uint32_t flags;
225 uint32_t tmp; 225 uint32_t tmp;
226 void *fbptr;
227 int r; 226 int r;
228 227
229 flags = radeon_object_flags_from_domain(domain); 228 flags = radeon_object_flags_from_domain(domain);
@@ -242,10 +241,6 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
242 DRM_ERROR("radeon: failed to reserve object for pinning it.\n"); 241 DRM_ERROR("radeon: failed to reserve object for pinning it.\n");
243 return r; 242 return r;
244 } 243 }
245 if (robj->rdev->fbdev_robj == robj) {
246 mutex_lock(&robj->rdev->fbdev_info->lock);
247 radeon_object_kunmap(robj);
248 }
249 tmp = robj->tobj.mem.placement; 244 tmp = robj->tobj.mem.placement;
250 ttm_flag_masked(&tmp, flags, TTM_PL_MASK_MEM); 245 ttm_flag_masked(&tmp, flags, TTM_PL_MASK_MEM);
251 robj->tobj.proposed_placement = tmp | TTM_PL_FLAG_NO_EVICT | TTM_PL_MASK_CACHING; 246 robj->tobj.proposed_placement = tmp | TTM_PL_FLAG_NO_EVICT | TTM_PL_MASK_CACHING;
@@ -261,23 +256,12 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
261 DRM_ERROR("radeon: failed to pin object.\n"); 256 DRM_ERROR("radeon: failed to pin object.\n");
262 } 257 }
263 radeon_object_unreserve(robj); 258 radeon_object_unreserve(robj);
264 if (robj->rdev->fbdev_robj == robj) {
265 if (!r) {
266 r = radeon_object_kmap(robj, &fbptr);
267 }
268 if (!r) {
269 robj->rdev->fbdev_info->screen_base = fbptr;
270 robj->rdev->fbdev_info->fix.smem_start = (unsigned long)fbptr;
271 }
272 mutex_unlock(&robj->rdev->fbdev_info->lock);
273 }
274 return r; 259 return r;
275} 260}
276 261
277void radeon_object_unpin(struct radeon_object *robj) 262void radeon_object_unpin(struct radeon_object *robj)
278{ 263{
279 uint32_t flags; 264 uint32_t flags;
280 void *fbptr;
281 int r; 265 int r;
282 266
283 spin_lock(&robj->tobj.lock); 267 spin_lock(&robj->tobj.lock);
@@ -297,10 +281,6 @@ void radeon_object_unpin(struct radeon_object *robj)
297 DRM_ERROR("radeon: failed to reserve object for unpinning it.\n"); 281 DRM_ERROR("radeon: failed to reserve object for unpinning it.\n");
298 return; 282 return;
299 } 283 }
300 if (robj->rdev->fbdev_robj == robj) {
301 mutex_lock(&robj->rdev->fbdev_info->lock);
302 radeon_object_kunmap(robj);
303 }
304 flags = robj->tobj.mem.placement; 284 flags = robj->tobj.mem.placement;
305 robj->tobj.proposed_placement = flags & ~TTM_PL_FLAG_NO_EVICT; 285 robj->tobj.proposed_placement = flags & ~TTM_PL_FLAG_NO_EVICT;
306 r = ttm_buffer_object_validate(&robj->tobj, 286 r = ttm_buffer_object_validate(&robj->tobj,
@@ -310,16 +290,6 @@ void radeon_object_unpin(struct radeon_object *robj)
310 DRM_ERROR("radeon: failed to unpin buffer.\n"); 290 DRM_ERROR("radeon: failed to unpin buffer.\n");
311 } 291 }
312 radeon_object_unreserve(robj); 292 radeon_object_unreserve(robj);
313 if (robj->rdev->fbdev_robj == robj) {
314 if (!r) {
315 r = radeon_object_kmap(robj, &fbptr);
316 }
317 if (!r) {
318 robj->rdev->fbdev_info->screen_base = fbptr;
319 robj->rdev->fbdev_info->fix.smem_start = (unsigned long)fbptr;
320 }
321 mutex_unlock(&robj->rdev->fbdev_info->lock);
322 }
323} 293}
324 294
325int radeon_object_wait(struct radeon_object *robj) 295int radeon_object_wait(struct radeon_object *robj)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 517c84559633..bdec583901eb 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -34,7 +34,6 @@
34#include <linux/highmem.h> 34#include <linux/highmem.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/version.h>
38#include <linux/module.h> 37#include <linux/module.h>
39 38
40void ttm_bo_free_old_node(struct ttm_buffer_object *bo) 39void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 27b146c54fbc..40b75032ea47 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -32,7 +32,6 @@
32#include <ttm/ttm_bo_driver.h> 32#include <ttm/ttm_bo_driver.h>
33#include <ttm/ttm_placement.h> 33#include <ttm/ttm_placement.h>
34#include <linux/mm.h> 34#include <linux/mm.h>
35#include <linux/version.h>
36#include <linux/rbtree.h> 35#include <linux/rbtree.h>
37#include <linux/module.h> 36#include <linux/module.h>
38#include <linux/uaccess.h> 37#include <linux/uaccess.h>
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 0331fa74cd3f..75dc8bd24592 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -28,7 +28,6 @@
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */ 29 */
30 30
31#include <linux/version.h>
32#include <linux/vmalloc.h> 31#include <linux/vmalloc.h>
33#include <linux/sched.h> 32#include <linux/sched.h>
34#include <linux/highmem.h> 33#include <linux/highmem.h>