Subversion Repositories Kolibri OS

Rev

Rev 5354 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5354 Rev 6084
Line 25... Line 25...
25
 *	Eric Anholt 
25
 *	Eric Anholt 
26
 */
26
 */
27
#include 
27
#include 
28
#include 
28
#include 
29
#include 
29
#include 
-
 
30
#include 
30
#include 
31
#include 
31
#include "intel_drv.h"
32
#include "intel_drv.h"
32
#include 
33
#include 
33
#include "i915_drv.h"
34
#include "i915_drv.h"
34
#include "dvo.h"
35
#include "dvo.h"
Line 77... Line 78...
77
	{
78
	{
78
		.type = INTEL_DVO_CHIP_LVDS,
79
		.type = INTEL_DVO_CHIP_LVDS,
79
		.name = "ch7017",
80
		.name = "ch7017",
80
		.dvo_reg = DVOC,
81
		.dvo_reg = DVOC,
81
		.slave_addr = 0x75,
82
		.slave_addr = 0x75,
82
		.gpio = GMBUS_PORT_DPB,
83
		.gpio = GMBUS_PIN_DPB,
83
		.dev_ops = &ch7017_ops,
84
		.dev_ops = &ch7017_ops,
84
	},
85
	},
85
	{
86
	{
86
	        .type = INTEL_DVO_CHIP_TMDS,
87
	        .type = INTEL_DVO_CHIP_TMDS,
87
		.name = "ns2501",
88
		.name = "ns2501",
Line 94... Line 95...
94
struct intel_dvo {
95
struct intel_dvo {
95
	struct intel_encoder base;
96
	struct intel_encoder base;
Line 96... Line 97...
96
 
97
 
Line 97... Line 98...
97
	struct intel_dvo_device dev;
98
	struct intel_dvo_device dev;
-
 
99
 
98
 
100
	struct intel_connector *attached_connector;
99
	struct drm_display_mode *panel_fixed_mode;
101
 
Line 100... Line 102...
100
	bool panel_wants_dither;
102
	bool panel_wants_dither;
101
};
103
};
Line 142... Line 144...
142
 
144
 
143
	return true;
145
	return true;
Line 144... Line 146...
144
}
146
}
145
 
147
 
146
static void intel_dvo_get_config(struct intel_encoder *encoder,
148
static void intel_dvo_get_config(struct intel_encoder *encoder,
147
				 struct intel_crtc_config *pipe_config)
149
				 struct intel_crtc_state *pipe_config)
148
{
150
{
149
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
151
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Line 158... Line 160...
158
	if (tmp & DVO_VSYNC_ACTIVE_HIGH)
160
	if (tmp & DVO_VSYNC_ACTIVE_HIGH)
159
		flags |= DRM_MODE_FLAG_PVSYNC;
161
		flags |= DRM_MODE_FLAG_PVSYNC;
160
	else
162
	else
161
		flags |= DRM_MODE_FLAG_NVSYNC;
163
		flags |= DRM_MODE_FLAG_NVSYNC;
Line 162... Line 164...
162
 
164
 
Line 163... Line 165...
163
	pipe_config->adjusted_mode.flags |= flags;
165
	pipe_config->base.adjusted_mode.flags |= flags;
164
 
166
 
Line 165... Line 167...
165
	pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
167
	pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
166
}
168
}
167
 
169
 
Line 184... Line 186...
184
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
186
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
185
	u32 dvo_reg = intel_dvo->dev.dvo_reg;
187
	u32 dvo_reg = intel_dvo->dev.dvo_reg;
186
	u32 temp = I915_READ(dvo_reg);
188
	u32 temp = I915_READ(dvo_reg);
Line 187... Line 189...
187
 
189
 
188
	intel_dvo->dev.dev_ops->mode_set(&intel_dvo->dev,
190
	intel_dvo->dev.dev_ops->mode_set(&intel_dvo->dev,
189
					 &crtc->config.requested_mode,
191
					 &crtc->config->base.mode,
Line 190... Line 192...
190
					 &crtc->config.adjusted_mode);
192
					 &crtc->config->base.adjusted_mode);
191
 
193
 
Line 192... Line 194...
192
	I915_WRITE(dvo_reg, temp | DVO_ENABLE);
194
	I915_WRITE(dvo_reg, temp | DVO_ENABLE);
193
	I915_READ(dvo_reg);
195
	I915_READ(dvo_reg);
Line 194... Line -...
194
 
-
 
195
	intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true);
-
 
196
}
-
 
197
 
-
 
198
/* Special dpms function to support cloning between dvo/sdvo/crt. */
-
 
199
static void intel_dvo_dpms(struct drm_connector *connector, int mode)
-
 
200
{
-
 
201
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
-
 
202
	struct drm_crtc *crtc;
-
 
203
	struct intel_crtc_config *config;
-
 
204
 
-
 
205
	/* dvo supports only 2 dpms states. */
-
 
206
	if (mode != DRM_MODE_DPMS_ON)
-
 
207
		mode = DRM_MODE_DPMS_OFF;
-
 
208
 
-
 
209
	if (mode == connector->dpms)
-
 
210
		return;
-
 
211
 
-
 
212
	connector->dpms = mode;
-
 
213
 
-
 
214
	/* Only need to change hw state when actually enabled */
-
 
215
	crtc = intel_dvo->base.base.crtc;
-
 
216
	if (!crtc) {
-
 
217
		intel_dvo->base.connectors_active = false;
-
 
218
		return;
-
 
219
	}
-
 
220
 
-
 
221
	/* We call connector dpms manually below in case pipe dpms doesn't
-
 
222
	 * change due to cloning. */
-
 
223
	if (mode == DRM_MODE_DPMS_ON) {
-
 
224
		config = &to_intel_crtc(crtc)->config;
-
 
225
 
-
 
226
		intel_dvo->base.connectors_active = true;
-
 
227
 
-
 
228
		intel_crtc_update_dpms(crtc);
-
 
229
 
-
 
230
		intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true);
-
 
231
	} else {
-
 
232
		intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, false);
-
 
233
 
-
 
234
		intel_dvo->base.connectors_active = false;
-
 
235
 
-
 
236
		intel_crtc_update_dpms(crtc);
-
 
237
	}
-
 
238
 
196
 
239
	intel_modeset_check_state(connector->dev);
197
	intel_dvo->dev.dev_ops->dpms(&intel_dvo->dev, true);
240
}
198
}
241
 
199
 
242
static enum drm_mode_status
200
static enum drm_mode_status
-
 
201
intel_dvo_mode_valid(struct drm_connector *connector,
-
 
202
		     struct drm_display_mode *mode)
-
 
203
{
-
 
204
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
Line 243... Line 205...
243
intel_dvo_mode_valid(struct drm_connector *connector,
205
	const struct drm_display_mode *fixed_mode =
244
				struct drm_display_mode *mode)
206
		to_intel_connector(connector)->panel.fixed_mode;
Line 245... Line 207...
245
{
207
	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Line 246... Line 208...
246
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
208
	int target_clock = mode->clock;
247
 
209
 
248
	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
210
	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
249
		return MODE_NO_DBLESCAN;
211
		return MODE_NO_DBLESCAN;
250
 
212
 
-
 
213
	/* XXX: Validate clock range */
-
 
214
 
251
	/* XXX: Validate clock range */
215
	if (fixed_mode) {
Line -... Line 216...
-
 
216
		if (mode->hdisplay > fixed_mode->hdisplay)
-
 
217
			return MODE_PANEL;
-
 
218
		if (mode->vdisplay > fixed_mode->vdisplay)
252
 
219
			return MODE_PANEL;
253
	if (intel_dvo->panel_fixed_mode) {
220
 
Line 254... Line 221...
254
		if (mode->hdisplay > intel_dvo->panel_fixed_mode->hdisplay)
221
		target_clock = fixed_mode->clock;
255
			return MODE_PANEL;
222
	}
256
		if (mode->vdisplay > intel_dvo->panel_fixed_mode->vdisplay)
223
 
257
			return MODE_PANEL;
224
	if (target_clock > max_dotclk)
-
 
225
		return MODE_CLOCK_HIGH;
-
 
226
 
258
	}
227
	return intel_dvo->dev.dev_ops->mode_valid(&intel_dvo->dev, mode);
Line 259... Line 228...
259
 
228
}
260
	return intel_dvo->dev.dev_ops->mode_valid(&intel_dvo->dev, mode);
229
 
261
}
230
static bool intel_dvo_compute_config(struct intel_encoder *encoder,
262
 
231
				     struct intel_crtc_state *pipe_config)
263
static bool intel_dvo_compute_config(struct intel_encoder *encoder,
232
{
264
				     struct intel_crtc_config *pipe_config)
-
 
265
{
-
 
266
	struct intel_dvo *intel_dvo = enc_to_dvo(encoder);
-
 
267
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
-
 
268
 
233
	struct intel_dvo *intel_dvo = enc_to_dvo(encoder);
269
	/* If we have timings from the BIOS for the panel, put them in
-
 
270
	 * to the adjusted mode.  The CRTC will be set up for this mode,
-
 
271
	 * with the panel scaling set up to source from the H/VDisplay
-
 
272
	 * of the original mode.
-
 
273
	 */
-
 
274
	if (intel_dvo->panel_fixed_mode != NULL) {
-
 
275
#define C(x) adjusted_mode->x = intel_dvo->panel_fixed_mode->x
-
 
276
		C(hdisplay);
-
 
277
		C(hsync_start);
234
	const struct drm_display_mode *fixed_mode =
278
		C(hsync_end);
-
 
Line 279... Line 235...
279
		C(htotal);
235
		intel_dvo->attached_connector->panel.fixed_mode;
280
		C(vdisplay);
236
	struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Line 281... Line 237...
281
		C(vsync_start);
237
 
282
		C(vsync_end);
238
	/* If we have timings from the BIOS for the panel, put them in
283
		C(vtotal);
239
	 * to the adjusted mode.  The CRTC will be set up for this mode,
284
		C(clock);
240
	 * with the panel scaling set up to source from the H/VDisplay
285
#undef C
241
	 * of the original mode.
286
 
242
	 */
287
		drm_mode_set_crtcinfo(adjusted_mode, 0);
243
	if (fixed_mode)
288
	}
244
		intel_fixed_panel_mode(fixed_mode, adjusted_mode);
289
 
245
 
290
	return true;
246
	return true;
Line 327... Line 283...
327
		dvo_val |= DVO_HSYNC_ACTIVE_HIGH;
283
		dvo_val |= DVO_HSYNC_ACTIVE_HIGH;
328
	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
284
	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
329
		dvo_val |= DVO_VSYNC_ACTIVE_HIGH;
285
		dvo_val |= DVO_VSYNC_ACTIVE_HIGH;
Line 330... Line 286...
330
 
286
 
331
	/*I915_WRITE(DVOB_SRCDIM,
287
	/*I915_WRITE(DVOB_SRCDIM,
332
	  (adjusted_mode->hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) |
288
	  (adjusted_mode->crtc_hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) |
333
	  (adjusted_mode->VDisplay << DVO_SRCDIM_VERTICAL_SHIFT));*/
289
	  (adjusted_mode->crtc_vdisplay << DVO_SRCDIM_VERTICAL_SHIFT));*/
334
	I915_WRITE(dvo_srcdim_reg,
290
	I915_WRITE(dvo_srcdim_reg,
335
		   (adjusted_mode->hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) |
291
		   (adjusted_mode->crtc_hdisplay << DVO_SRCDIM_HORIZONTAL_SHIFT) |
336
		   (adjusted_mode->vdisplay << DVO_SRCDIM_VERTICAL_SHIFT));
292
		   (adjusted_mode->crtc_vdisplay << DVO_SRCDIM_VERTICAL_SHIFT));
337
	/*I915_WRITE(DVOB, dvo_val);*/
293
	/*I915_WRITE(DVOB, dvo_val);*/
338
	I915_WRITE(dvo_reg, dvo_val);
294
	I915_WRITE(dvo_reg, dvo_val);
Line 339... Line 295...
339
}
295
}
Line 352... Line 308...
352
	return intel_dvo->dev.dev_ops->detect(&intel_dvo->dev);
308
	return intel_dvo->dev.dev_ops->detect(&intel_dvo->dev);
353
}
309
}
Line 354... Line 310...
354
 
310
 
355
static int intel_dvo_get_modes(struct drm_connector *connector)
311
static int intel_dvo_get_modes(struct drm_connector *connector)
356
{
-
 
357
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
312
{
-
 
313
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
-
 
314
	const struct drm_display_mode *fixed_mode =
Line 358... Line 315...
358
	struct drm_i915_private *dev_priv = connector->dev->dev_private;
315
		to_intel_connector(connector)->panel.fixed_mode;
359
 
316
 
360
	/* We should probably have an i2c driver get_modes function for those
317
	/* We should probably have an i2c driver get_modes function for those
361
	 * devices which will have a fixed set of modes determined by the chip
318
	 * devices which will have a fixed set of modes determined by the chip
362
	 * (TV-out, for example), but for now with just TMDS and LVDS,
319
	 * (TV-out, for example), but for now with just TMDS and LVDS,
363
	 * that's not the case.
320
	 * that's not the case.
364
	 */
321
	 */
365
	intel_ddc_get_modes(connector,
322
	intel_ddc_get_modes(connector,
366
			    intel_gmbus_get_adapter(dev_priv, GMBUS_PORT_DPC));
323
			    intel_gmbus_get_adapter(dev_priv, GMBUS_PIN_DPC));
Line 367... Line 324...
367
	if (!list_empty(&connector->probed_modes))
324
	if (!list_empty(&connector->probed_modes))
368
		return 1;
325
		return 1;
369
 
326
 
370
	if (intel_dvo->panel_fixed_mode != NULL) {
327
	if (fixed_mode) {
371
		struct drm_display_mode *mode;
328
		struct drm_display_mode *mode;
372
		mode = drm_mode_duplicate(connector->dev, intel_dvo->panel_fixed_mode);
329
		mode = drm_mode_duplicate(connector->dev, fixed_mode);
373
		if (mode) {
330
		if (mode) {
374
			drm_mode_probed_add(connector, mode);
331
			drm_mode_probed_add(connector, mode);
Line 380... Line 337...
380
}
337
}
Line 381... Line 338...
381
 
338
 
382
static void intel_dvo_destroy(struct drm_connector *connector)
339
static void intel_dvo_destroy(struct drm_connector *connector)
383
{
340
{
-
 
341
	drm_connector_cleanup(connector);
384
	drm_connector_cleanup(connector);
342
	intel_panel_fini(&to_intel_connector(connector)->panel);
385
	kfree(connector);
343
	kfree(connector);
Line 386... Line 344...
386
}
344
}
387
 
345
 
388
static const struct drm_connector_funcs intel_dvo_connector_funcs = {
346
static const struct drm_connector_funcs intel_dvo_connector_funcs = {
389
	.dpms = intel_dvo_dpms,
347
	.dpms = drm_atomic_helper_connector_dpms,
390
	.detect = intel_dvo_detect,
348
	.detect = intel_dvo_detect,
-
 
349
	.destroy = intel_dvo_destroy,
-
 
350
	.fill_modes = drm_helper_probe_single_connector_modes,
-
 
351
	.atomic_get_property = intel_connector_atomic_get_property,
391
	.destroy = intel_dvo_destroy,
352
	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Line 392... Line 353...
392
	.fill_modes = drm_helper_probe_single_connector_modes,
353
	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
393
};
354
};
394
 
355
 
Line 403... Line 364...
403
	struct intel_dvo *intel_dvo = enc_to_dvo(to_intel_encoder(encoder));
364
	struct intel_dvo *intel_dvo = enc_to_dvo(to_intel_encoder(encoder));
Line 404... Line 365...
404
 
365
 
405
	if (intel_dvo->dev.dev_ops->destroy)
366
	if (intel_dvo->dev.dev_ops->destroy)
Line 406... Line -...
406
		intel_dvo->dev.dev_ops->destroy(&intel_dvo->dev);
-
 
407
 
-
 
408
	kfree(intel_dvo->panel_fixed_mode);
367
		intel_dvo->dev.dev_ops->destroy(&intel_dvo->dev);
409
 
368
 
Line 410... Line 369...
410
	intel_encoder_destroy(encoder);
369
	intel_encoder_destroy(encoder);
411
}
370
}
Line 463... Line 422...
463
 
422
 
464
	intel_dvo = kzalloc(sizeof(*intel_dvo), GFP_KERNEL);
423
	intel_dvo = kzalloc(sizeof(*intel_dvo), GFP_KERNEL);
465
	if (!intel_dvo)
424
	if (!intel_dvo)
Line 466... Line 425...
466
		return;
425
		return;
467
 
426
 
468
	intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
427
	intel_connector = intel_connector_alloc();
469
	if (!intel_connector) {
428
	if (!intel_connector) {
470
		kfree(intel_dvo);
429
		kfree(intel_dvo);
Line -... Line 430...
-
 
430
		return;
-
 
431
	}
471
		return;
432
 
472
	}
433
	intel_dvo->attached_connector = intel_connector;
473
 
434
 
Line 474... Line 435...
474
	intel_encoder = &intel_dvo->base;
435
	intel_encoder = &intel_dvo->base;
Line 489... Line 450...
489
		struct drm_connector *connector = &intel_connector->base;
450
		struct drm_connector *connector = &intel_connector->base;
490
		const struct intel_dvo_device *dvo = &intel_dvo_devices[i];
451
		const struct intel_dvo_device *dvo = &intel_dvo_devices[i];
491
		struct i2c_adapter *i2c;
452
		struct i2c_adapter *i2c;
492
		int gpio;
453
		int gpio;
493
		bool dvoinit;
454
		bool dvoinit;
-
 
455
		enum pipe pipe;
-
 
456
		uint32_t dpll[I915_MAX_PIPES];
Line 494... Line 457...
494
 
457
 
495
		/* Allow the I2C driver info to specify the GPIO to be used in
458
		/* Allow the I2C driver info to specify the GPIO to be used in
496
		 * special cases, but otherwise default to what's defined
459
		 * special cases, but otherwise default to what's defined
497
		 * in the spec.
460
		 * in the spec.
498
		 */
461
		 */
499
		if (intel_gmbus_is_port_valid(dvo->gpio))
462
		if (intel_gmbus_is_valid_pin(dev_priv, dvo->gpio))
500
			gpio = dvo->gpio;
463
			gpio = dvo->gpio;
501
		else if (dvo->type == INTEL_DVO_CHIP_LVDS)
464
		else if (dvo->type == INTEL_DVO_CHIP_LVDS)
502
			gpio = GMBUS_PORT_SSC;
465
			gpio = GMBUS_PIN_SSC;
503
		else
466
		else
Line 504... Line 467...
504
			gpio = GMBUS_PORT_DPB;
467
			gpio = GMBUS_PIN_DPB;
505
 
468
 
506
		/* Set up the I2C bus necessary for the chip we're probing.
469
		/* Set up the I2C bus necessary for the chip we're probing.
507
		 * It appears that everything is on GPIOE except for panels
470
		 * It appears that everything is on GPIOE except for panels
Line 514... Line 477...
514
		/* GMBUS NAK handling seems to be unstable, hence let the
477
		/* GMBUS NAK handling seems to be unstable, hence let the
515
		 * transmitter detection run in bit banging mode for now.
478
		 * transmitter detection run in bit banging mode for now.
516
		 */
479
		 */
517
		intel_gmbus_force_bit(i2c, true);
480
		intel_gmbus_force_bit(i2c, true);
Line -... Line 481...
-
 
481
 
-
 
482
		/* ns2501 requires the DVO 2x clock before it will
-
 
483
		 * respond to i2c accesses, so make sure we have
-
 
484
		 * have the clock enabled before we attempt to
-
 
485
		 * initialize the device.
-
 
486
		 */
-
 
487
		for_each_pipe(dev_priv, pipe) {
-
 
488
			dpll[pipe] = I915_READ(DPLL(pipe));
-
 
489
			I915_WRITE(DPLL(pipe), dpll[pipe] | DPLL_DVO_2X_MODE);
-
 
490
		}
518
 
491
 
Line -... Line 492...
-
 
492
		dvoinit = dvo->dev_ops->init(&intel_dvo->dev, i2c);
-
 
493
 
-
 
494
		/* restore the DVO 2x clock state to original */
-
 
495
		for_each_pipe(dev_priv, pipe) {
-
 
496
			I915_WRITE(DPLL(pipe), dpll[pipe]);
519
		dvoinit = dvo->dev_ops->init(&intel_dvo->dev, i2c);
497
		}
Line 520... Line 498...
520
 
498
 
521
		intel_gmbus_force_bit(i2c, false);
499
		intel_gmbus_force_bit(i2c, false);
Line 556... Line 534...
556
			 * However, it's in a different format from the BIOS
534
			 * However, it's in a different format from the BIOS
557
			 * data on chipsets with integrated LVDS (stored in AIM
535
			 * data on chipsets with integrated LVDS (stored in AIM
558
			 * headers, likely), so for now, just get the current
536
			 * headers, likely), so for now, just get the current
559
			 * mode being output through DVO.
537
			 * mode being output through DVO.
560
			 */
538
			 */
561
			intel_dvo->panel_fixed_mode =
539
			intel_panel_init(&intel_connector->panel,
562
				intel_dvo_get_current_mode(connector);
540
					 intel_dvo_get_current_mode(connector),
-
 
541
					 NULL);
563
			intel_dvo->panel_wants_dither = true;
542
			intel_dvo->panel_wants_dither = true;
564
		}
543
		}
Line 565... Line 544...
565
 
544
 
566
		drm_connector_register(connector);
545
		drm_connector_register(connector);