Subversion Repositories Kolibri OS

Rev

Rev 5060 | Rev 6088 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5060 serge 1
/*
2
 * Copyright (c) 2006-2008 Intel Corporation
3
 * Copyright (c) 2007 Dave Airlie 
4
 *
5
 * DRM core CRTC related functions
6
 *
7
 * Permission to use, copy, modify, distribute, and sell this software and its
8
 * documentation for any purpose is hereby granted without fee, provided that
9
 * the above copyright notice appear in all copies and that both that copyright
10
 * notice and this permission notice appear in supporting documentation, and
11
 * that the name of the copyright holders not be used in advertising or
12
 * publicity pertaining to distribution of the software without specific,
13
 * written prior permission.  The copyright holders make no representations
14
 * about the suitability of this software for any purpose.  It is provided "as
15
 * is" without express or implied warranty.
16
 *
17
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23
 * OF THIS SOFTWARE.
24
 *
25
 * Authors:
26
 *      Keith Packard
27
 *	Eric Anholt 
28
 *      Dave Airlie 
29
 *      Jesse Barnes 
30
 */
31
 
32
#include 
33
#include 
34
 
35
#include 
36
#include 
37
#include 
38
#include 
39
#include 
40
#include 
41
 
42
/**
43
 * DOC: output probing helper overview
44
 *
45
 * This library provides some helper code for output probing. It provides an
46
 * implementation of the core connector->fill_modes interface with
47
 * drm_helper_probe_single_connector_modes.
48
 *
49
 * It also provides support for polling connectors with a work item and for
50
 * generic hotplug interrupt handling where the driver doesn't or cannot keep
51
 * track of a per-connector hpd interrupt.
52
 *
53
 * This helper library can be used independently of the modeset helper library.
54
 * Drivers can also overwrite different parts e.g. use their own hotplug
55
 * handling code to avoid probing unrelated outputs.
56
 */
57
 
58
static bool drm_kms_helper_poll = true;
59
module_param_named(poll, drm_kms_helper_poll, bool, 0600);
60
 
61
static void drm_mode_validate_flag(struct drm_connector *connector,
62
				   int flags)
63
{
64
	struct drm_display_mode *mode;
65
 
66
	if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE |
67
		      DRM_MODE_FLAG_3D_MASK))
68
		return;
69
 
70
	list_for_each_entry(mode, &connector->modes, head) {
71
		if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
72
				!(flags & DRM_MODE_FLAG_INTERLACE))
73
			mode->status = MODE_NO_INTERLACE;
74
		if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
75
				!(flags & DRM_MODE_FLAG_DBLSCAN))
76
			mode->status = MODE_NO_DBLESCAN;
77
		if ((mode->flags & DRM_MODE_FLAG_3D_MASK) &&
78
				!(flags & DRM_MODE_FLAG_3D_MASK))
79
			mode->status = MODE_NO_STEREO;
80
	}
81
 
82
	return;
83
}
84
 
85
static int drm_helper_probe_single_connector_modes_merge_bits(struct drm_connector *connector,
86
							      uint32_t maxX, uint32_t maxY, bool merge_type_bits)
87
{
88
	struct drm_device *dev = connector->dev;
89
	struct drm_display_mode *mode;
90
	struct drm_connector_helper_funcs *connector_funcs =
91
		connector->helper_private;
92
	int count = 0;
93
	int mode_flags = 0;
94
	bool verbose_prune = true;
95
 
96
	WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
97
 
98
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
99
			connector->name);
100
	/* set all modes to the unverified state */
101
	list_for_each_entry(mode, &connector->modes, head)
102
		mode->status = MODE_UNVERIFIED;
103
 
104
	if (connector->force) {
5271 serge 105
		if (connector->force == DRM_FORCE_ON ||
106
		    connector->force == DRM_FORCE_ON_DIGITAL)
5060 serge 107
			connector->status = connector_status_connected;
108
		else
109
			connector->status = connector_status_disconnected;
110
		if (connector->funcs->force)
111
			connector->funcs->force(connector);
112
	} else {
113
		connector->status = connector->funcs->detect(connector, true);
114
	}
115
 
116
	/* Re-enable polling in case the global poll config changed. */
117
	if (drm_kms_helper_poll != dev->mode_config.poll_running)
118
		drm_kms_helper_poll_enable(dev);
119
 
120
	dev->mode_config.poll_running = drm_kms_helper_poll;
121
 
122
	if (connector->status == connector_status_disconnected) {
123
		DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
124
			connector->base.id, connector->name);
125
		drm_mode_connector_update_edid_property(connector, NULL);
126
		verbose_prune = false;
127
		goto prune;
128
	}
129
 
130
#ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
131
	count = drm_load_edid_firmware(connector);
132
	if (count == 0)
133
#endif
134
	{
135
		if (connector->override_edid) {
136
			struct edid *edid = (struct edid *) connector->edid_blob_ptr->data;
137
 
138
			count = drm_add_edid_modes(connector, edid);
139
		} else
140
		count = (*connector_funcs->get_modes)(connector);
141
	}
142
 
143
	if (count == 0 && connector->status == connector_status_connected)
144
		count = drm_add_modes_noedid(connector, 1024, 768);
145
	if (count == 0)
146
		goto prune;
147
 
148
	drm_mode_connector_list_update(connector, merge_type_bits);
149
 
150
	if (maxX && maxY)
151
		drm_mode_validate_size(dev, &connector->modes, maxX, maxY);
152
 
153
	if (connector->interlace_allowed)
154
		mode_flags |= DRM_MODE_FLAG_INTERLACE;
155
	if (connector->doublescan_allowed)
156
		mode_flags |= DRM_MODE_FLAG_DBLSCAN;
157
	if (connector->stereo_allowed)
158
		mode_flags |= DRM_MODE_FLAG_3D_MASK;
159
	drm_mode_validate_flag(connector, mode_flags);
160
 
161
	list_for_each_entry(mode, &connector->modes, head) {
162
		if (mode->status == MODE_OK && connector_funcs->mode_valid)
163
			mode->status = connector_funcs->mode_valid(connector,
164
								   mode);
165
	}
166
 
167
prune:
168
	drm_mode_prune_invalid(dev, &connector->modes, verbose_prune);
169
 
170
	if (list_empty(&connector->modes))
171
		return 0;
172
 
173
	list_for_each_entry(mode, &connector->modes, head)
174
		mode->vrefresh = drm_mode_vrefresh(mode);
175
 
176
	drm_mode_sort(&connector->modes);
177
 
178
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id,
179
			connector->name);
180
	list_for_each_entry(mode, &connector->modes, head) {
181
		drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
182
		drm_mode_debug_printmodeline(mode);
183
	}
184
 
185
	return count;
186
}
187
 
188
/**
189
 * drm_helper_probe_single_connector_modes - get complete set of display modes
190
 * @connector: connector to probe
191
 * @maxX: max width for modes
192
 * @maxY: max height for modes
193
 *
194
 * Based on the helper callbacks implemented by @connector try to detect all
195
 * valid modes.  Modes will first be added to the connector's probed_modes list,
196
 * then culled (based on validity and the @maxX, @maxY parameters) and put into
197
 * the normal modes list.
198
 *
199
 * Intended to be use as a generic implementation of the ->fill_modes()
200
 * @connector vfunc for drivers that use the crtc helpers for output mode
201
 * filtering and detection.
202
 *
203
 * Returns:
204
 * The number of modes found on @connector.
205
 */
206
int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
207
					    uint32_t maxX, uint32_t maxY)
208
{
209
	return drm_helper_probe_single_connector_modes_merge_bits(connector, maxX, maxY, true);
210
}
211
EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
212
 
213
/**
214
 * drm_helper_probe_single_connector_modes_nomerge - get complete set of display modes
215
 * @connector: connector to probe
216
 * @maxX: max width for modes
217
 * @maxY: max height for modes
218
 *
219
 * This operates like drm_hehlper_probe_single_connector_modes except it
220
 * replaces the mode bits instead of merging them for preferred modes.
221
 */
222
int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector *connector,
223
					    uint32_t maxX, uint32_t maxY)
224
{
225
	return drm_helper_probe_single_connector_modes_merge_bits(connector, maxX, maxY, false);
226
}
227
EXPORT_SYMBOL(drm_helper_probe_single_connector_modes_nomerge);
228
 
229
/**
230
 * drm_kms_helper_hotplug_event - fire off KMS hotplug events
231
 * @dev: drm_device whose connector state changed
232
 *
233
 * This function fires off the uevent for userspace and also calls the
234
 * output_poll_changed function, which is most commonly used to inform the fbdev
235
 * emulation code and allow it to update the fbcon output configuration.
236
 *
237
 * Drivers should call this from their hotplug handling code when a change is
238
 * detected. Note that this function does not do any output detection of its
239
 * own, like drm_helper_hpd_irq_event() does - this is assumed to be done by the
240
 * driver already.
241
 *
242
 * This function must be called from process context with no mode
243
 * setting locks held.
244
 */
245
void drm_kms_helper_hotplug_event(struct drm_device *dev)
246
{
247
	/* send a uevent + call fbdev */
248
//   drm_sysfs_hotplug_event(dev);
249
//   if (dev->mode_config.funcs->output_poll_changed)
250
//       dev->mode_config.funcs->output_poll_changed(dev);
251
}
252
EXPORT_SYMBOL(drm_kms_helper_hotplug_event);
253
 
254
#define DRM_OUTPUT_POLL_PERIOD (10*HZ)
255
static void output_poll_execute(struct work_struct *work)
256
{
257
	struct delayed_work *delayed_work = to_delayed_work(work);
258
	struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work);
259
	struct drm_connector *connector;
260
	enum drm_connector_status old_status;
261
	bool repoll = false, changed = false;
262
 
263
	if (!drm_kms_helper_poll)
264
		return;
265
 
266
	mutex_lock(&dev->mode_config.mutex);
267
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
268
 
269
		/* Ignore forced connectors. */
270
		if (connector->force)
271
			continue;
272
 
273
		/* Ignore HPD capable connectors and connectors where we don't
274
		 * want any hotplug detection at all for polling. */
275
		if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD)
276
			continue;
277
 
278
		repoll = true;
279
 
280
		old_status = connector->status;
281
		/* if we are connected and don't want to poll for disconnect
282
		   skip it */
283
		if (old_status == connector_status_connected &&
284
		    !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT))
285
			continue;
286
 
287
		connector->status = connector->funcs->detect(connector, false);
288
		if (old_status != connector->status) {
289
			const char *old, *new;
290
 
291
			old = drm_get_connector_status_name(old_status);
292
			new = drm_get_connector_status_name(connector->status);
293
 
294
			DRM_DEBUG_KMS("[CONNECTOR:%d:%s] "
295
				      "status updated from %s to %s\n",
296
				      connector->base.id,
297
				      connector->name,
298
				      old, new);
299
 
300
			changed = true;
301
		}
302
	}
303
 
304
	mutex_unlock(&dev->mode_config.mutex);
305
 
306
//   if (changed)
307
//       drm_kms_helper_hotplug_event(dev);
308
 
309
//   if (repoll)
310
//       schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD);
311
}
312
 
313
/**
314
 * drm_kms_helper_poll_disable - disable output polling
315
 * @dev: drm_device
316
 *
317
 * This function disables the output polling work.
318
 *
319
 * Drivers can call this helper from their device suspend implementation. It is
320
 * not an error to call this even when output polling isn't enabled or arlready
321
 * disabled.
322
 */
323
void drm_kms_helper_poll_disable(struct drm_device *dev)
324
{
325
	if (!dev->mode_config.poll_enabled)
326
		return;
327
//   cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
328
}
329
EXPORT_SYMBOL(drm_kms_helper_poll_disable);
330
 
331
/**
332
 * drm_kms_helper_poll_enable - re-enable output polling.
333
 * @dev: drm_device
334
 *
335
 * This function re-enables the output polling work.
336
 *
337
 * Drivers can call this helper from their device resume implementation. It is
338
 * an error to call this when the output polling support has not yet been set
339
 * up.
340
 */
341
void drm_kms_helper_poll_enable(struct drm_device *dev)
342
{
343
	bool poll = false;
344
	struct drm_connector *connector;
345
 
346
	if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
347
		return;
348
 
349
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
350
		if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT |
351
					 DRM_CONNECTOR_POLL_DISCONNECT))
352
			poll = true;
353
	}
354
 
355
//   if (poll)
356
//       schedule_delayed_work(&dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD);
357
}
358
EXPORT_SYMBOL(drm_kms_helper_poll_enable);
359
 
360
/**
361
 * drm_kms_helper_poll_init - initialize and enable output polling
362
 * @dev: drm_device
363
 *
364
 * This function intializes and then also enables output polling support for
365
 * @dev. Drivers which do not have reliable hotplug support in hardware can use
366
 * this helper infrastructure to regularly poll such connectors for changes in
367
 * their connection state.
368
 *
369
 * Drivers can control which connectors are polled by setting the
370
 * DRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags. On
371
 * connectors where probing live outputs can result in visual distortion drivers
372
 * should not set the DRM_CONNECTOR_POLL_DISCONNECT flag to avoid this.
373
 * Connectors which have no flag or only DRM_CONNECTOR_POLL_HPD set are
374
 * completely ignored by the polling logic.
375
 *
376
 * Note that a connector can be both polled and probed from the hotplug handler,
377
 * in case the hotplug interrupt is known to be unreliable.
378
 */
379
void drm_kms_helper_poll_init(struct drm_device *dev)
380
{
381
	INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute);
382
	dev->mode_config.poll_enabled = true;
383
 
384
	drm_kms_helper_poll_enable(dev);
385
}
386
EXPORT_SYMBOL(drm_kms_helper_poll_init);
387
 
388
/**
389
 * drm_kms_helper_poll_fini - disable output polling and clean it up
390
 * @dev: drm_device
391
 */
392
void drm_kms_helper_poll_fini(struct drm_device *dev)
393
{
394
	drm_kms_helper_poll_disable(dev);
395
}
396
EXPORT_SYMBOL(drm_kms_helper_poll_fini);
397
 
398
/**
399
 * drm_helper_hpd_irq_event - hotplug processing
400
 * @dev: drm_device
401
 *
402
 * Drivers can use this helper function to run a detect cycle on all connectors
403
 * which have the DRM_CONNECTOR_POLL_HPD flag set in their &polled member. All
404
 * other connectors are ignored, which is useful to avoid reprobing fixed
405
 * panels.
406
 *
407
 * This helper function is useful for drivers which can't or don't track hotplug
408
 * interrupts for each connector.
409
 *
410
 * Drivers which support hotplug interrupts for each connector individually and
411
 * which have a more fine-grained detect logic should bypass this code and
412
 * directly call drm_kms_helper_hotplug_event() in case the connector state
413
 * changed.
414
 *
415
 * This function must be called from process context with no mode
416
 * setting locks held.
417
 *
418
 * Note that a connector can be both polled and probed from the hotplug handler,
419
 * in case the hotplug interrupt is known to be unreliable.
420
 */
421
bool drm_helper_hpd_irq_event(struct drm_device *dev)
422
{
423
	struct drm_connector *connector;
424
	enum drm_connector_status old_status;
425
	bool changed = false;
426
 
427
	if (!dev->mode_config.poll_enabled)
428
		return false;
429
 
430
	mutex_lock(&dev->mode_config.mutex);
431
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
432
 
433
		/* Only handle HPD capable connectors. */
434
		if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
435
			continue;
436
 
437
		old_status = connector->status;
438
 
439
		connector->status = connector->funcs->detect(connector, false);
440
		DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
441
			      connector->base.id,
442
			      connector->name,
443
			      drm_get_connector_status_name(old_status),
444
			      drm_get_connector_status_name(connector->status));
445
		if (old_status != connector->status)
446
			changed = true;
447
	}
448
 
449
	mutex_unlock(&dev->mode_config.mutex);
450
 
451
	if (changed)
452
		drm_kms_helper_hotplug_event(dev);
453
 
454
	return changed;
455
}
456
EXPORT_SYMBOL(drm_helper_hpd_irq_event);