Subversion Repositories Kolibri OS

Rev

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

Rev 1430 Rev 1963
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2006 Luc Verhaegen (quirks list)
2
 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3
 * Copyright (c) 2007-2008 Intel Corporation
3
 * Copyright (c) 2007-2008 Intel Corporation
4
 *   Jesse Barnes 
4
 *   Jesse Barnes 
-
 
5
 * Copyright 2010 Red Hat, Inc.
5
 *
6
 *
6
 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
7
 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
7
 * FB layer.
8
 * FB layer.
8
 *   Copyright (C) 2006 Dennis Munsie 
9
 *   Copyright (C) 2006 Dennis Munsie 
9
 *
10
 *
Line 25... Line 26...
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
 * DEALINGS IN THE SOFTWARE.
28
 * DEALINGS IN THE SOFTWARE.
28
 */
29
 */
29
#include 
30
#include 
-
 
31
#include 
30
#include 
32
#include 
31
#include 
-
 
32
#include "drmP.h"
33
#include "drmP.h"
33
#include "drm_edid.h"
34
#include "drm_edid.h"
-
 
35
#include "drm_edid_modes.h"
Line -... Line 36...
-
 
36
 
-
 
37
#define version_greater(edid, maj, min) \
-
 
38
	(((edid)->version > (maj)) || \
34
 
39
	 ((edid)->version == (maj) && (edid)->revision > (min)))
-
 
40
 
35
/*
41
#define EDID_EST_TIMINGS 16
36
 * TODO:
42
#define EDID_STD_TIMINGS 8
37
 *   - support EDID 1.4 (incl. CE blocks)
-
 
Line 38... Line 43...
38
 */
43
#define EDID_DETAILED_TIMINGS 4
39
 
44
 
40
/*
45
/*
41
 * EDID blocks out in the wild have a variety of bugs, try to collect
46
 * EDID blocks out in the wild have a variety of bugs, try to collect
Line 59... Line 64...
59
/* Monitor forgot to set the first detailed is preferred bit. */
64
/* Monitor forgot to set the first detailed is preferred bit. */
60
#define EDID_QUIRK_FIRST_DETAILED_PREFERRED	(1 << 5)
65
#define EDID_QUIRK_FIRST_DETAILED_PREFERRED	(1 << 5)
61
/* use +hsync +vsync for detailed mode */
66
/* use +hsync +vsync for detailed mode */
62
#define EDID_QUIRK_DETAILED_SYNC_PP		(1 << 6)
67
#define EDID_QUIRK_DETAILED_SYNC_PP		(1 << 6)
Line -... Line 68...
-
 
68
 
-
 
69
struct detailed_mode_closure {
-
 
70
	struct drm_connector *connector;
-
 
71
	struct edid *edid;
-
 
72
	bool preferred;
-
 
73
	u32 quirks;
-
 
74
	int modes;
Line 63... Line 75...
63
 
75
};
64
 
76
 
-
 
77
#define LEVEL_DMT	0
65
#define LEVEL_DMT	0
78
#define LEVEL_GTF	1
Line 66... Line 79...
66
#define LEVEL_GTF	1
79
#define LEVEL_GTF2	2
67
#define LEVEL_CVT	2
80
#define LEVEL_CVT	3
68
 
81
 
69
static struct edid_quirk {
82
static struct edid_quirk {
Line 82... Line 95...
82
	{ "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
95
	{ "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
83
	{ "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
96
	{ "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
Line 84... Line 97...
84
 
97
 
85
	/* Envision Peripherals, Inc. EN-7100e */
98
	/* Envision Peripherals, Inc. EN-7100e */
-
 
99
	{ "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
-
 
100
	/* Envision EN2028 */
Line 86... Line 101...
86
	{ "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
101
	{ "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
87
 
102
 
88
	/* Funai Electronics PM36B */
103
	/* Funai Electronics PM36B */
Line 104... Line 119...
104
	/* Samsung SyncMaster 22[5-6]BW */
119
	/* Samsung SyncMaster 22[5-6]BW */
105
	{ "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
120
	{ "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
106
	{ "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
121
	{ "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
107
};
122
};
Line -... Line 123...
-
 
123
 
Line 108... Line -...
108
 
-
 
109
 
124
/*** DDC fetch and block validation ***/
110
/* Valid EDID header has these bytes */
125
 
111
static const u8 edid_header[] = {
126
static const u8 edid_header[] = {
Line 112... Line 127...
112
	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
127
	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
113
};
-
 
114
 
-
 
115
/**
-
 
116
 * drm_edid_is_valid - sanity check EDID data
128
};
117
 * @edid: EDID data
129
 
118
 *
-
 
119
 * Sanity check the EDID block by looking at the header, the version number
130
/*
-
 
131
 * Sanity check the EDID block (base or extension).  Return 0 if the block
120
 * and the checksum.  Return 0 if the EDID doesn't check out, or 1 if it's
132
 * doesn't check out, or 1 if it's valid.
121
 * valid.
133
 */
122
 */
134
static bool
123
bool drm_edid_is_valid(struct edid *edid)
135
drm_edid_block_valid(u8 *raw_edid)
-
 
136
{
-
 
137
	int i;
124
{
138
	u8 csum = 0;
-
 
139
	struct edid *edid = (struct edid *)raw_edid;
Line 125... Line 140...
125
	int i, score = 0;
140
 
126
	u8 csum = 0;
141
	if (raw_edid[0] == 0x00) {
127
	u8 *raw_edid = (u8 *)edid;
142
		int score = 0;
Line 128... Line 143...
128
 
143
 
129
	for (i = 0; i < sizeof(edid_header); i++)
144
	for (i = 0; i < sizeof(edid_header); i++)
130
		if (raw_edid[i] == edid_header[i])
145
		if (raw_edid[i] == edid_header[i])
131
			score++;
146
			score++;
132
 
147
 
133
	if (score == 8) ;
148
	if (score == 8) ;
-
 
149
	else if (score >= 6) {
-
 
150
		DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
Line 134... Line 151...
134
	else if (score >= 6) {
151
		memcpy(raw_edid, edid_header, sizeof(edid_header));
135
		DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
152
		} else {
136
		memcpy(raw_edid, edid_header, sizeof(edid_header));
153
		goto bad;
137
	} else
154
		}
-
 
155
	}
-
 
156
 
-
 
157
	for (i = 0; i < EDID_LENGTH; i++)
138
		goto bad;
158
		csum += raw_edid[i];
139
 
159
	if (csum) {
Line -... Line 160...
-
 
160
		DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
-
 
161
 
-
 
162
		/* allow CEA to slide through, switches mangle this */
140
	for (i = 0; i < EDID_LENGTH; i++)
163
		if (raw_edid[0] != 0x02)
141
		csum += raw_edid[i];
164
		goto bad;
142
	if (csum) {
165
	}
143
		DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
166
 
Line 144... Line 167...
144
		goto bad;
167
	/* per-block-type checks */
145
	}
168
	switch (raw_edid[0]) {
-
 
169
	case 0: /* base */
-
 
170
	if (edid->version != 1) {
-
 
171
		DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
-
 
172
		goto bad;
-
 
173
	}
Line 146... Line 174...
146
 
174
 
Line 147... Line 175...
147
	if (edid->version != 1) {
175
	if (edid->revision > 4)
148
		DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
176
		DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
Line 160... Line 188...
160
//       print_hex_dump_bytes(KERN_ERR, DUMP_PREFIX_NONE, raw_edid, EDID_LENGTH);
188
//       print_hex_dump_bytes(KERN_ERR, DUMP_PREFIX_NONE, raw_edid, EDID_LENGTH);
161
//       printk("\n");
189
//       printk("\n");
162
	}
190
	}
163
	return 0;
191
	return 0;
164
}
192
}
-
 
193
 
-
 
194
/**
-
 
195
 * drm_edid_is_valid - sanity check EDID data
-
 
196
 * @edid: EDID data
-
 
197
 *
-
 
198
 * Sanity-check an entire EDID record (including extensions)
-
 
199
 */
-
 
200
bool drm_edid_is_valid(struct edid *edid)
-
 
201
{
-
 
202
	int i;
-
 
203
	u8 *raw = (u8 *)edid;
-
 
204
 
-
 
205
	if (!edid)
-
 
206
		return false;
-
 
207
 
-
 
208
	for (i = 0; i <= edid->extensions; i++)
-
 
209
		if (!drm_edid_block_valid(raw + i * EDID_LENGTH))
-
 
210
			return false;
-
 
211
 
-
 
212
	return true;
-
 
213
}
165
EXPORT_SYMBOL(drm_edid_is_valid);
214
EXPORT_SYMBOL(drm_edid_is_valid);
Line -... Line 215...
-
 
215
 
-
 
216
#define DDC_ADDR 0x50
-
 
217
#define DDC_SEGMENT_ADDR 0x30
-
 
218
/**
-
 
219
 * Get EDID information via I2C.
-
 
220
 *
-
 
221
 * \param adapter : i2c device adaptor
-
 
222
 * \param buf     : EDID data buffer to be filled
-
 
223
 * \param len     : EDID data buffer length
-
 
224
 * \return 0 on success or -1 on failure.
-
 
225
 *
-
 
226
 * Try to fetch EDID information by calling i2c driver function.
-
 
227
 */
-
 
228
static int
-
 
229
drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
-
 
230
		      int block, int len)
-
 
231
{
-
 
232
	unsigned char start = block * EDID_LENGTH;
-
 
233
	int ret, retries = 5;
-
 
234
 
-
 
235
	/* The core i2c driver will automatically retry the transfer if the
-
 
236
	 * adapter reports EAGAIN. However, we find that bit-banging transfers
-
 
237
	 * are susceptible to errors under a heavily loaded machine and
-
 
238
	 * generate spurious NAKs and timeouts. Retrying the transfer
-
 
239
	 * of the individual block a few times seems to overcome this.
-
 
240
	 */
-
 
241
	do {
-
 
242
	struct i2c_msg msgs[] = {
-
 
243
		{
-
 
244
			.addr	= DDC_ADDR,
-
 
245
			.flags	= 0,
-
 
246
			.len	= 1,
-
 
247
			.buf	= &start,
-
 
248
		}, {
-
 
249
			.addr	= DDC_ADDR,
-
 
250
			.flags	= I2C_M_RD,
-
 
251
			.len	= len,
-
 
252
			.buf	= buf,
-
 
253
		}
-
 
254
	};
-
 
255
		ret = i2c_transfer(adapter, msgs, 2);
-
 
256
	} while (ret != 2 && --retries);
-
 
257
 
-
 
258
	return ret == 2 ? 0 : -1;
-
 
259
}
-
 
260
 
-
 
261
static u8 *
-
 
262
drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
-
 
263
{
-
 
264
	int i, j = 0, valid_extensions = 0;
-
 
265
	u8 *block, *new;
-
 
266
    size_t alloc_size;
-
 
267
 
-
 
268
	if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
-
 
269
		return NULL;
-
 
270
 
-
 
271
	/* base block fetch */
-
 
272
	for (i = 0; i < 4; i++) {
-
 
273
		if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH))
-
 
274
			goto out;
-
 
275
		if (drm_edid_block_valid(block))
-
 
276
			break;
-
 
277
	}
-
 
278
	if (i == 4)
-
 
279
		goto carp;
-
 
280
 
-
 
281
	/* if there's no extensions, we're done */
-
 
282
	if (block[0x7e] == 0)
-
 
283
		return block;
-
 
284
 
-
 
285
    alloc_size = (block[0x7e] + 1) * EDID_LENGTH ;
-
 
286
 
-
 
287
    new = kmalloc(alloc_size, GFP_KERNEL);
-
 
288
 
-
 
289
	if (!new)
-
 
290
		goto out;
-
 
291
 
-
 
292
    memcpy(new, block, EDID_LENGTH);
-
 
293
    kfree(block);
-
 
294
 
-
 
295
	block = new;
-
 
296
 
-
 
297
	for (j = 1; j <= block[0x7e]; j++) {
-
 
298
		for (i = 0; i < 4; i++) {
-
 
299
			if (drm_do_probe_ddc_edid(adapter,
-
 
300
				  block + (valid_extensions + 1) * EDID_LENGTH,
-
 
301
				  j, EDID_LENGTH))
-
 
302
				goto out;
-
 
303
			if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH)) {
-
 
304
				valid_extensions++;
-
 
305
				break;
-
 
306
		}
-
 
307
		}
-
 
308
		if (i == 4)
-
 
309
			dev_warn(connector->dev->dev,
-
 
310
			 "%s: Ignoring invalid EDID block %d.\n",
-
 
311
			 drm_get_connector_name(connector), j);
-
 
312
	}
-
 
313
 
-
 
314
	if (valid_extensions != block[0x7e]) {
-
 
315
		block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
-
 
316
		block[0x7e] = valid_extensions;
-
 
317
        new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
-
 
318
        if (!new)
-
 
319
			goto out;
-
 
320
        memcpy(new, block, alloc_size);
-
 
321
        kfree(block);
-
 
322
		block = new;
-
 
323
	}
-
 
324
 
-
 
325
	return block;
-
 
326
 
-
 
327
carp:
-
 
328
	dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
-
 
329
		 drm_get_connector_name(connector), j);
-
 
330
 
-
 
331
out:
-
 
332
	kfree(block);
-
 
333
	return NULL;
-
 
334
}
-
 
335
 
-
 
336
/**
-
 
337
 * Probe DDC presence.
-
 
338
 *
-
 
339
 * \param adapter : i2c device adaptor
-
 
340
 * \return 1 on success
-
 
341
 */
-
 
342
static bool
-
 
343
drm_probe_ddc(struct i2c_adapter *adapter)
-
 
344
{
-
 
345
	unsigned char out;
-
 
346
 
-
 
347
	return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
-
 
348
}
-
 
349
 
-
 
350
/**
-
 
351
 * drm_get_edid - get EDID data, if available
-
 
352
 * @connector: connector we're probing
-
 
353
 * @adapter: i2c adapter to use for DDC
-
 
354
 *
-
 
355
 * Poke the given i2c channel to grab EDID data if possible.  If found,
-
 
356
 * attach it to the connector.
-
 
357
 *
-
 
358
 * Return edid data or NULL if we couldn't find any.
-
 
359
 */
-
 
360
struct edid *drm_get_edid(struct drm_connector *connector,
-
 
361
			  struct i2c_adapter *adapter)
-
 
362
{
-
 
363
	struct edid *edid = NULL;
-
 
364
 
-
 
365
	if (drm_probe_ddc(adapter))
-
 
366
		edid = (struct edid *)drm_do_get_edid(connector, adapter);
-
 
367
 
-
 
368
	connector->display_info.raw_edid = (char *)edid;
-
 
369
 
-
 
370
	return edid;
-
 
371
 
-
 
372
}
-
 
373
EXPORT_SYMBOL(drm_get_edid);
-
 
374
 
-
 
375
/*** EDID parsing ***/
166
 
376
 
167
/**
377
/**
168
 * edid_vendor - match a string against EDID's obfuscated vendor field
378
 * edid_vendor - match a string against EDID's obfuscated vendor field
169
 * @edid: EDID to match
379
 * @edid: EDID to match
170
 * @vendor: vendor string
380
 * @vendor: vendor string
Line 206... Line 416...
206
}
416
}
Line 207... Line 417...
207
 
417
 
208
#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
418
#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Line 209... Line -...
209
#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh))
-
 
210
 
419
#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh))
211
 
420
 
212
/**
421
/**
213
 * edid_fixup_preferred - set preferred modes based on quirk list
422
 * edid_fixup_preferred - set preferred modes based on quirk list
214
 * @connector: has mode list to fix up
423
 * @connector: has mode list to fix up
Line 253... Line 462...
253
	}
462
	}
Line 254... Line 463...
254
 
463
 
255
	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
464
	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
Line 256... Line -...
256
}
-
 
257
 
-
 
258
/*
-
 
259
 * Add the Autogenerated from the DMT spec.
-
 
260
 * This table is copied from xfree86/modes/xf86EdidModes.c.
-
 
261
 * But the mode with Reduced blank feature is deleted.
-
 
262
 */
-
 
263
static struct drm_display_mode drm_dmt_modes[] = {
-
 
264
	/* 640x350@85Hz */
-
 
265
	{ DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
-
 
266
		   736, 832, 0, 350, 382, 385, 445, 0,
-
 
267
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
268
	/* 640x400@85Hz */
-
 
269
	{ DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
-
 
270
		   736, 832, 0, 400, 401, 404, 445, 0,
-
 
271
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
272
	/* 720x400@85Hz */
-
 
273
	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
-
 
274
		   828, 936, 0, 400, 401, 404, 446, 0,
-
 
275
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
276
	/* 640x480@60Hz */
-
 
277
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
-
 
278
		   752, 800, 0, 480, 489, 492, 525, 0,
-
 
279
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
280
	/* 640x480@72Hz */
-
 
281
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
-
 
282
		   704, 832, 0, 480, 489, 492, 520, 0,
-
 
283
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
284
	/* 640x480@75Hz */
-
 
285
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
-
 
286
		   720, 840, 0, 480, 481, 484, 500, 0,
-
 
287
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
288
	/* 640x480@85Hz */
-
 
289
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
-
 
290
		   752, 832, 0, 480, 481, 484, 509, 0,
-
 
291
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
292
	/* 800x600@56Hz */
-
 
293
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
-
 
294
		   896, 1024, 0, 600, 601, 603, 625, 0,
-
 
295
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
296
	/* 800x600@60Hz */
-
 
297
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
-
 
298
		   968, 1056, 0, 600, 601, 605, 628, 0,
-
 
299
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
300
	/* 800x600@72Hz */
-
 
301
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
-
 
302
		   976, 1040, 0, 600, 637, 643, 666, 0,
-
 
303
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
304
	/* 800x600@75Hz */
-
 
305
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
-
 
306
		   896, 1056, 0, 600, 601, 604, 625, 0,
-
 
307
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
308
	/* 800x600@85Hz */
-
 
309
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
-
 
310
		   896, 1048, 0, 600, 601, 604, 631, 0,
-
 
311
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
312
	/* 848x480@60Hz */
-
 
313
	{ DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
-
 
314
		   976, 1088, 0, 480, 486, 494, 517, 0,
-
 
315
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
316
	/* 1024x768@43Hz, interlace */
-
 
317
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
-
 
318
		   1208, 1264, 0, 768, 768, 772, 817, 0,
-
 
319
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
-
 
320
			DRM_MODE_FLAG_INTERLACE) },
-
 
321
	/* 1024x768@60Hz */
-
 
322
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
-
 
323
		   1184, 1344, 0, 768, 771, 777, 806, 0,
-
 
324
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
325
	/* 1024x768@70Hz */
-
 
326
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
-
 
327
		   1184, 1328, 0, 768, 771, 777, 806, 0,
-
 
328
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
329
	/* 1024x768@75Hz */
-
 
330
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
-
 
331
		   1136, 1312, 0, 768, 769, 772, 800, 0,
-
 
332
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
333
	/* 1024x768@85Hz */
-
 
334
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
-
 
335
		   1072, 1376, 0, 768, 769, 772, 808, 0,
-
 
336
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
337
	/* 1152x864@75Hz */
-
 
338
	{ DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
-
 
339
		   1344, 1600, 0, 864, 865, 868, 900, 0,
-
 
340
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
341
	/* 1280x768@60Hz */
-
 
342
	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
-
 
343
		   1472, 1664, 0, 768, 771, 778, 798, 0,
-
 
344
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
345
	/* 1280x768@75Hz */
-
 
346
	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
-
 
347
		   1488, 1696, 0, 768, 771, 778, 805, 0,
-
 
348
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
349
	/* 1280x768@85Hz */
-
 
350
	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
-
 
351
		   1496, 1712, 0, 768, 771, 778, 809, 0,
-
 
352
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
353
	/* 1280x800@60Hz */
-
 
354
	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
-
 
355
		   1480, 1680, 0, 800, 803, 809, 831, 0,
-
 
356
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
-
 
357
	/* 1280x800@75Hz */
-
 
358
	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
-
 
359
		   1488, 1696, 0, 800, 803, 809, 838, 0,
-
 
360
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
361
	/* 1280x800@85Hz */
-
 
362
	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
-
 
363
		   1496, 1712, 0, 800, 803, 809, 843, 0,
-
 
364
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
365
	/* 1280x960@60Hz */
-
 
366
	{ DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
-
 
367
		   1488, 1800, 0, 960, 961, 964, 1000, 0,
-
 
368
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
369
	/* 1280x960@85Hz */
-
 
370
	{ DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
-
 
371
		   1504, 1728, 0, 960, 961, 964, 1011, 0,
-
 
372
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
373
	/* 1280x1024@60Hz */
-
 
374
	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
-
 
375
		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
-
 
376
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
377
	/* 1280x1024@75Hz */
-
 
378
	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
-
 
379
		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
-
 
380
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
381
	/* 1280x1024@85Hz */
-
 
382
	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
-
 
383
		   1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
-
 
384
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
385
	/* 1360x768@60Hz */
-
 
386
	{ DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
-
 
387
		   1536, 1792, 0, 768, 771, 777, 795, 0,
-
 
388
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
389
	/* 1440x1050@60Hz */
-
 
390
	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
-
 
391
		   1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
-
 
392
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
393
	/* 1440x1050@75Hz */
-
 
394
	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
-
 
395
		   1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
-
 
396
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
397
	/* 1440x1050@85Hz */
-
 
398
	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
-
 
399
		   1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
-
 
400
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
401
	/* 1440x900@60Hz */
-
 
402
	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
-
 
403
		   1672, 1904, 0, 900, 903, 909, 934, 0,
-
 
404
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
405
	/* 1440x900@75Hz */
-
 
406
	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
-
 
407
		   1688, 1936, 0, 900, 903, 909, 942, 0,
-
 
408
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
409
	/* 1440x900@85Hz */
-
 
410
	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
-
 
411
		   1696, 1952, 0, 900, 903, 909, 948, 0,
-
 
412
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
413
	/* 1600x1200@60Hz */
-
 
414
	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
-
 
415
		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
-
 
416
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
417
	/* 1600x1200@65Hz */
-
 
418
	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
-
 
419
		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
-
 
420
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
421
	/* 1600x1200@70Hz */
-
 
422
	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
-
 
423
		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
-
 
424
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
425
	/* 1600x1200@75Hz */
-
 
426
	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 2025000, 1600, 1664,
-
 
427
		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
-
 
428
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
429
	/* 1600x1200@85Hz */
-
 
430
	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
-
 
431
		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
-
 
432
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
433
	/* 1680x1050@60Hz */
-
 
434
	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
-
 
435
		   1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
-
 
436
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
437
	/* 1680x1050@75Hz */
-
 
438
	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
-
 
439
		   1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
-
 
440
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
441
	/* 1680x1050@85Hz */
-
 
442
	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
-
 
443
		   1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
-
 
444
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
445
	/* 1792x1344@60Hz */
-
 
446
	{ DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
-
 
447
		   2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
-
 
448
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
449
	/* 1729x1344@75Hz */
-
 
450
	{ DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
-
 
451
		   2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
-
 
452
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
453
	/* 1853x1392@60Hz */
-
 
454
	{ DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
-
 
455
		   2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
-
 
456
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
457
	/* 1856x1392@75Hz */
-
 
458
	{ DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
-
 
459
		   2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
-
 
460
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
461
	/* 1920x1200@60Hz */
-
 
462
	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
-
 
463
		   2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
-
 
464
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
465
	/* 1920x1200@75Hz */
-
 
466
	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
-
 
467
		   2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
-
 
468
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
469
	/* 1920x1200@85Hz */
-
 
470
	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
-
 
471
		   2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
-
 
472
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
473
	/* 1920x1440@60Hz */
-
 
474
	{ DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
-
 
475
		   2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
-
 
476
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
477
	/* 1920x1440@75Hz */
-
 
478
	{ DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
-
 
479
		   2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
-
 
480
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
481
	/* 2560x1600@60Hz */
-
 
482
	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
-
 
483
		   3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
-
 
484
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
485
	/* 2560x1600@75HZ */
-
 
486
	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
-
 
487
		   3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
-
 
488
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
489
	/* 2560x1600@85HZ */
-
 
490
	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
-
 
491
		   3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
-
 
492
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
-
 
493
};
-
 
494
static const int drm_num_dmt_modes =
-
 
495
	sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
465
}
496
 
466
 
497
static struct drm_display_mode *drm_find_dmt(struct drm_device *dev,
467
struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
-
 
468
			int hsize, int vsize, int fresh)
498
			int hsize, int vsize, int fresh)
469
{
499
{
-
 
Line 500... Line -...
500
	int i;
-
 
501
	struct drm_display_mode *ptr, *mode;
470
	struct drm_display_mode *mode = NULL;
502
 
471
	int i;
503
	mode = NULL;
472
 
504
	for (i = 0; i < drm_num_dmt_modes; i++) {
473
	for (i = 0; i < drm_num_dmt_modes; i++) {
505
		ptr = &drm_dmt_modes[i];
474
		const struct drm_display_mode *ptr = &drm_dmt_modes[i];
506
		if (hsize == ptr->hdisplay &&
475
		if (hsize == ptr->hdisplay &&
507
			vsize == ptr->vdisplay &&
476
			vsize == ptr->vdisplay &&
508
			fresh == drm_mode_vrefresh(ptr)) {
477
			fresh == drm_mode_vrefresh(ptr)) {
509
			/* get the expected default mode */
478
			/* get the expected default mode */
510
			mode = drm_mode_duplicate(dev, ptr);
479
			mode = drm_mode_duplicate(dev, ptr);
511
			break;
480
			break;
512
		}
481
		}
-
 
482
	}
-
 
483
	return mode;
-
 
484
}
-
 
485
EXPORT_SYMBOL(drm_mode_find_dmt);
-
 
486
 
-
 
487
typedef void detailed_cb(struct detailed_timing *timing, void *closure);
-
 
488
 
-
 
489
static void
-
 
490
cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
-
 
491
{
-
 
492
	int i, n = 0;
-
 
493
	u8 rev = ext[0x01], d = ext[0x02];
-
 
494
	u8 *det_base = ext + d;
-
 
495
 
-
 
496
	switch (rev) {
-
 
497
	case 0:
-
 
498
		/* can't happen */
-
 
499
		return;
-
 
500
	case 1:
-
 
501
		/* have to infer how many blocks we have, check pixel clock */
-
 
502
		for (i = 0; i < 6; i++)
-
 
503
			if (det_base[18*i] || det_base[18*i+1])
-
 
504
				n++;
-
 
505
		break;
-
 
506
	default:
-
 
507
		/* explicit count */
-
 
508
		n = min(ext[0x03] & 0x0f, 6);
-
 
509
		break;
-
 
510
	}
-
 
511
 
-
 
512
	for (i = 0; i < n; i++)
-
 
513
		cb((struct detailed_timing *)(det_base + 18 * i), closure);
-
 
514
}
-
 
515
 
-
 
516
static void
-
 
517
vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
-
 
518
{
-
 
519
	unsigned int i, n = min((int)ext[0x02], 6);
-
 
520
	u8 *det_base = ext + 5;
-
 
521
 
-
 
522
	if (ext[0x01] != 1)
-
 
523
		return; /* unknown version */
-
 
524
 
-
 
525
	for (i = 0; i < n; i++)
-
 
526
		cb((struct detailed_timing *)(det_base + 18 * i), closure);
-
 
527
}
-
 
528
 
-
 
529
static void
-
 
530
drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
-
 
531
{
-
 
532
	int i;
-
 
533
	struct edid *edid = (struct edid *)raw_edid;
-
 
534
 
-
 
535
	if (edid == NULL)
-
 
536
		return;
-
 
537
 
-
 
538
	for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
-
 
539
		cb(&(edid->detailed_timings[i]), closure);
-
 
540
 
-
 
541
	for (i = 1; i <= raw_edid[0x7e]; i++) {
-
 
542
		u8 *ext = raw_edid + (i * EDID_LENGTH);
-
 
543
		switch (*ext) {
-
 
544
		case CEA_EXT:
-
 
545
			cea_for_each_detailed_block(ext, cb, closure);
-
 
546
			break;
-
 
547
		case VTB_EXT:
-
 
548
			vtb_for_each_detailed_block(ext, cb, closure);
-
 
549
			break;
-
 
550
		default:
-
 
551
			break;
-
 
552
		}
-
 
553
	}
-
 
554
}
-
 
555
 
-
 
556
static void
-
 
557
is_rb(struct detailed_timing *t, void *data)
-
 
558
{
-
 
559
	u8 *r = (u8 *)t;
-
 
560
	if (r[3] == EDID_DETAIL_MONITOR_RANGE)
-
 
561
		if (r[15] & 0x10)
-
 
562
			*(bool *)data = true;
-
 
563
}
-
 
564
 
-
 
565
/* EDID 1.4 defines this explicitly.  For EDID 1.3, we guess, badly. */
-
 
566
static bool
-
 
567
drm_monitor_supports_rb(struct edid *edid)
-
 
568
{
-
 
569
	if (edid->revision >= 4) {
-
 
570
		bool ret;
-
 
571
		drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
-
 
572
		return ret;
-
 
573
	}
-
 
574
 
-
 
575
	return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
-
 
576
}
-
 
577
 
-
 
578
static void
-
 
579
find_gtf2(struct detailed_timing *t, void *data)
-
 
580
{
-
 
581
	u8 *r = (u8 *)t;
-
 
582
	if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
-
 
583
		*(u8 **)data = r;
-
 
584
}
-
 
585
 
-
 
586
/* Secondary GTF curve kicks in above some break frequency */
-
 
587
static int
-
 
588
drm_gtf2_hbreak(struct edid *edid)
-
 
589
{
-
 
590
	u8 *r = NULL;
-
 
591
	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-
 
592
	return r ? (r[12] * 2) : 0;
-
 
593
}
-
 
594
 
-
 
595
static int
-
 
596
drm_gtf2_2c(struct edid *edid)
-
 
597
{
-
 
598
	u8 *r = NULL;
-
 
599
	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-
 
600
	return r ? r[13] : 0;
-
 
601
}
-
 
602
 
-
 
603
static int
-
 
604
drm_gtf2_m(struct edid *edid)
-
 
605
{
-
 
606
	u8 *r = NULL;
-
 
607
	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-
 
608
	return r ? (r[15] << 8) + r[14] : 0;
-
 
609
}
-
 
610
 
-
 
611
static int
-
 
612
drm_gtf2_k(struct edid *edid)
-
 
613
{
-
 
614
	u8 *r = NULL;
-
 
615
	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-
 
616
	return r ? r[16] : 0;
-
 
617
}
-
 
618
 
-
 
619
static int
-
 
620
drm_gtf2_2j(struct edid *edid)
-
 
621
{
-
 
622
	u8 *r = NULL;
-
 
623
	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-
 
624
	return r ? r[17] : 0;
-
 
625
}
-
 
626
 
-
 
627
/**
-
 
628
 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
-
 
629
 * @edid: EDID block to scan
-
 
630
 */
-
 
631
static int standard_timing_level(struct edid *edid)
-
 
632
{
-
 
633
	if (edid->revision >= 2) {
-
 
634
		if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
-
 
635
			return LEVEL_CVT;
-
 
636
		if (drm_gtf2_hbreak(edid))
-
 
637
			return LEVEL_GTF2;
-
 
638
		return LEVEL_GTF;
Line 513... Line 639...
513
	}
639
	}
514
	return mode;
640
	return LEVEL_DMT;
515
}
641
}
516
 
642
 
Line 531... Line 657...
531
 * @t: standard timing params
657
 * @t: standard timing params
532
 * @timing_level: standard timing level
658
 * @timing_level: standard timing level
533
 *
659
 *
534
 * Take the standard timing params (in this case width, aspect, and refresh)
660
 * Take the standard timing params (in this case width, aspect, and refresh)
535
 * and convert them into a real mode using CVT/GTF/DMT.
661
 * and convert them into a real mode using CVT/GTF/DMT.
536
 *
-
 
537
 * Punts for now, but should eventually use the FB layer's CVT based mode
-
 
538
 * generation code.
-
 
539
 */
662
 */
540
struct drm_display_mode *drm_mode_std(struct drm_device *dev,
663
static struct drm_display_mode *
541
				      struct std_timing *t,
664
drm_mode_std(struct drm_connector *connector, struct edid *edid,
542
				      int revision,
665
	     struct std_timing *t, int revision)
543
				      int timing_level)
-
 
544
{
666
{
-
 
667
	struct drm_device *dev = connector->dev;
545
	struct drm_display_mode *mode;
668
	struct drm_display_mode *m, *mode = NULL;
546
	int hsize, vsize;
669
	int hsize, vsize;
547
	int vrefresh_rate;
670
	int vrefresh_rate;
548
	unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
671
	unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
549
		>> EDID_TIMING_ASPECT_SHIFT;
672
		>> EDID_TIMING_ASPECT_SHIFT;
550
	unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
673
	unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
551
		>> EDID_TIMING_VFREQ_SHIFT;
674
		>> EDID_TIMING_VFREQ_SHIFT;
-
 
675
	int timing_level = standard_timing_level(edid);
Line 552... Line 676...
552
 
676
 
553
	if (bad_std_timing(t->hsize, t->vfreq_aspect))
677
	if (bad_std_timing(t->hsize, t->vfreq_aspect))
Line 554... Line 678...
554
		return NULL;
678
		return NULL;
Line 567... Line 691...
567
		vsize = (hsize * 3) / 4;
691
		vsize = (hsize * 3) / 4;
568
	else if (aspect_ratio == 2)
692
	else if (aspect_ratio == 2)
569
		vsize = (hsize * 4) / 5;
693
		vsize = (hsize * 4) / 5;
570
	else
694
	else
571
		vsize = (hsize * 9) / 16;
695
		vsize = (hsize * 9) / 16;
-
 
696
 
572
	/* HDTV hack */
697
	/* HDTV hack, part 1 */
-
 
698
	if (vrefresh_rate == 60 &&
-
 
699
	    ((hsize == 1360 && vsize == 765) ||
-
 
700
	     (hsize == 1368 && vsize == 769))) {
-
 
701
		hsize = 1366;
-
 
702
		vsize = 768;
-
 
703
	}
-
 
704
 
-
 
705
	/*
-
 
706
	 * If this connector already has a mode for this size and refresh
-
 
707
	 * rate (because it came from detailed or CVT info), use that
-
 
708
	 * instead.  This way we don't have to guess at interlace or
-
 
709
	 * reduced blanking.
-
 
710
	 */
-
 
711
	list_for_each_entry(m, &connector->probed_modes, head)
-
 
712
		if (m->hdisplay == hsize && m->vdisplay == vsize &&
-
 
713
		    drm_mode_vrefresh(m) == vrefresh_rate)
-
 
714
			return NULL;
-
 
715
 
-
 
716
	/* HDTV hack, part 2 */
573
	if (hsize == 1360 && vsize == 765 && vrefresh_rate == 60) {
717
	if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
574
		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
718
		mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
575
				    false);
719
				    false);
576
		mode->hdisplay = 1366;
720
		mode->hdisplay = 1366;
577
		mode->vsync_start = mode->vsync_start - 1;
721
		mode->hsync_start = mode->hsync_start - 1;
578
		mode->vsync_end = mode->vsync_end - 1;
722
		mode->hsync_end = mode->hsync_end - 1;
579
		return mode;
723
		return mode;
580
	}
724
	}
581
	mode = NULL;
725
 
582
	/* check whether it can be found in default mode table */
726
	/* check whether it can be found in default mode table */
583
	mode = drm_find_dmt(dev, hsize, vsize, vrefresh_rate);
727
	mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate);
584
	if (mode)
728
	if (mode)
585
		return mode;
729
		return mode;
Line 586... Line 730...
586
 
730
 
587
	switch (timing_level) {
731
	switch (timing_level) {
588
	case LEVEL_DMT:
732
	case LEVEL_DMT:
589
		break;
733
		break;
590
	case LEVEL_GTF:
734
	case LEVEL_GTF:
591
		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
735
		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
-
 
736
		break;
-
 
737
	case LEVEL_GTF2:
-
 
738
		/*
-
 
739
		 * This is potentially wrong if there's ever a monitor with
-
 
740
		 * more than one ranges section, each claiming a different
-
 
741
		 * secondary GTF curve.  Please don't do that.
-
 
742
		 */
-
 
743
		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
-
 
744
		if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
-
 
745
			kfree(mode);
-
 
746
			mode = drm_gtf_mode_complex(dev, hsize, vsize,
-
 
747
						    vrefresh_rate, 0, 0,
-
 
748
						    drm_gtf2_m(edid),
-
 
749
						    drm_gtf2_2c(edid),
-
 
750
						    drm_gtf2_k(edid),
-
 
751
						    drm_gtf2_2j(edid));
-
 
752
		}
592
		break;
753
		break;
593
	case LEVEL_CVT:
754
	case LEVEL_CVT:
594
		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
755
		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
595
				    false);
756
				    false);
596
		break;
757
		break;
Line 620... Line 781...
620
		{ 2880,  480 },
781
		{ 2880,  480 },
621
		{  720,  576 },
782
		{  720,  576 },
622
		{ 1440,  576 },
783
		{ 1440,  576 },
623
		{ 2880,  576 },
784
		{ 2880,  576 },
624
	};
785
	};
625
	static const int n_sizes =
-
 
626
		sizeof(cea_interlaced)/sizeof(cea_interlaced[0]);
-
 
Line 627... Line 786...
627
 
786
 
628
	if (!(pt->misc & DRM_EDID_PT_INTERLACED))
787
	if (!(pt->misc & DRM_EDID_PT_INTERLACED))
Line 629... Line 788...
629
		return;
788
		return;
630
 
789
 
631
	for (i = 0; i < n_sizes; i++) {
790
	for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
632
		if ((mode->hdisplay == cea_interlaced[i].w) &&
791
		if ((mode->hdisplay == cea_interlaced[i].w) &&
633
		    (mode->vdisplay == cea_interlaced[i].h / 2)) {
792
		    (mode->vdisplay == cea_interlaced[i].h / 2)) {
634
			mode->vdisplay *= 2;
793
			mode->vdisplay *= 2;
Line 705... Line 864...
705
	mode->vdisplay = vactive;
864
	mode->vdisplay = vactive;
706
	mode->vsync_start = mode->vdisplay + vsync_offset;
865
	mode->vsync_start = mode->vdisplay + vsync_offset;
707
	mode->vsync_end = mode->vsync_start + vsync_pulse_width;
866
	mode->vsync_end = mode->vsync_start + vsync_pulse_width;
708
	mode->vtotal = mode->vdisplay + vblank;
867
	mode->vtotal = mode->vdisplay + vblank;
Line 709... Line -...
709
 
-
 
710
	/* perform the basic check for the detailed timing */
-
 
711
	if (mode->hsync_end > mode->htotal ||
-
 
712
		mode->vsync_end > mode->vtotal) {
-
 
713
		drm_mode_destroy(dev, mode);
-
 
714
		DRM_DEBUG_KMS("Incorrect detailed timing. "
-
 
715
				"Sync is beyond the blank.\n");
-
 
716
		return NULL;
-
 
717
	}
-
 
718
 
868
 
719
	/* Some EDIDs have bogus h/vtotal values */
869
	/* Some EDIDs have bogus h/vtotal values */
720
	if (mode->hsync_end > mode->htotal)
870
	if (mode->hsync_end > mode->htotal)
721
		mode->htotal = mode->hsync_end + 1;
871
		mode->htotal = mode->hsync_end + 1;
722
	if (mode->vsync_end > mode->vtotal)
872
	if (mode->vsync_end > mode->vtotal)
Line 723... Line -...
723
		mode->vtotal = mode->vsync_end + 1;
-
 
724
 
-
 
725
	drm_mode_set_name(mode);
873
		mode->vtotal = mode->vsync_end + 1;
Line -... Line 874...
-
 
874
 
-
 
875
	drm_mode_do_interlace_quirk(mode, pt);
726
 
876
 
727
	drm_mode_do_interlace_quirk(mode, pt);
877
	drm_mode_set_name(mode);
728
 
878
 
Line 729... Line 879...
729
	if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
879
	if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Line 749... Line 899...
749
	}
899
	}
Line 750... Line 900...
750
 
900
 
751
	return mode;
901
	return mode;
Line 752... Line 902...
752
}
902
}
753
 
903
 
754
/*
904
static bool
755
 * Detailed mode info for the EDID "established modes" data to use.
905
mode_is_rb(const struct drm_display_mode *mode)
756
 */
-
 
757
static struct drm_display_mode edid_est_modes[] = {
-
 
758
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
-
 
759
		   968, 1056, 0, 600, 601, 605, 628, 0,
-
 
760
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
-
 
761
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
-
 
762
		   896, 1024, 0, 600, 601, 603,  625, 0,
-
 
763
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
-
 
764
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
-
 
765
		   720, 840, 0, 480, 481, 484, 500, 0,
-
 
766
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
-
 
767
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
-
 
768
		   704,  832, 0, 480, 489, 491, 520, 0,
-
 
769
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
-
 
770
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
-
 
771
		   768,  864, 0, 480, 483, 486, 525, 0,
-
 
772
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
-
 
773
	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
-
 
774
		   752, 800, 0, 480, 490, 492, 525, 0,
-
 
775
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
-
 
776
	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
-
 
777
		   846, 900, 0, 400, 421, 423,  449, 0,
-
 
778
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
-
 
779
	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
-
 
780
		   846,  900, 0, 400, 412, 414, 449, 0,
-
 
781
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
-
 
782
	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
-
 
783
		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
-
 
784
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
-
 
785
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
-
 
786
		   1136, 1312, 0,  768, 769, 772, 800, 0,
-
 
787
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
-
 
788
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
-
 
789
		   1184, 1328, 0,  768, 771, 777, 806, 0,
-
 
790
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
906
{
791
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
-
 
792
		   1184, 1344, 0,  768, 771, 777, 806, 0,
-
 
793
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
-
 
794
	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
-
 
795
		   1208, 1264, 0, 768, 768, 776, 817, 0,
907
	return (mode->htotal - mode->hdisplay == 160) &&
796
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
-
 
797
	{ DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
-
 
798
		   928, 1152, 0, 624, 625, 628, 667, 0,
-
 
799
		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
-
 
800
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
-
 
801
		   896, 1056, 0, 600, 601, 604,  625, 0,
-
 
802
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
-
 
803
	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
-
 
804
		   976, 1040, 0, 600, 637, 643, 666, 0,
-
 
805
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
908
	       (mode->hsync_end - mode->hdisplay == 80) &&
806
	{ DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
-
 
807
		   1344, 1600, 0,  864, 865, 868, 900, 0,
909
	       (mode->hsync_end - mode->hsync_start == 32) &&
Line -... Line 910...
-
 
910
	       (mode->vsync_start - mode->vdisplay == 3);
808
		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
911
}
809
};
912
 
-
 
913
static bool
810
 
914
mode_in_hsync_range(const struct drm_display_mode *mode,
Line -... Line 915...
-
 
915
		    struct edid *edid, u8 *t)
-
 
916
{
-
 
917
	int hsync, hmin, hmax;
-
 
918
 
-
 
919
	hmin = t[7];
-
 
920
	if (edid->revision >= 4)
-
 
921
	    hmin += ((t[4] & 0x04) ? 255 : 0);
-
 
922
	hmax = t[8];
-
 
923
	if (edid->revision >= 4)
811
#define EDID_EST_TIMINGS 16
924
	    hmax += ((t[4] & 0x08) ? 255 : 0);
-
 
925
	hsync = drm_mode_hsync(mode);
-
 
926
 
812
#define EDID_STD_TIMINGS 8
927
	return (hsync <= hmax && hsync >= hmin);
-
 
928
}
-
 
929
 
-
 
930
static bool
-
 
931
mode_in_vsync_range(const struct drm_display_mode *mode,
-
 
932
		    struct edid *edid, u8 *t)
-
 
933
{
-
 
934
	int vsync, vmin, vmax;
-
 
935
 
813
#define EDID_DETAILED_TIMINGS 4
936
	vmin = t[5];
-
 
937
	if (edid->revision >= 4)
-
 
938
	    vmin += ((t[4] & 0x01) ? 255 : 0);
-
 
939
	vmax = t[6];
-
 
940
	if (edid->revision >= 4)
-
 
941
	    vmax += ((t[4] & 0x02) ? 255 : 0);
-
 
942
	vsync = drm_mode_vrefresh(mode);
-
 
943
 
-
 
944
	return (vsync <= vmax && vsync >= vmin);
-
 
945
}
-
 
946
 
-
 
947
static u32
-
 
948
range_pixel_clock(struct edid *edid, u8 *t)
-
 
949
{
-
 
950
	/* unspecified */
-
 
951
	if (t[9] == 0 || t[9] == 255)
-
 
952
		return 0;
-
 
953
 
-
 
954
	/* 1.4 with CVT support gives us real precision, yay */
-
 
955
	if (edid->revision >= 4 && t[10] == 0x04)
-
 
956
		return (t[9] * 10000) - ((t[12] >> 2) * 250);
-
 
957
 
-
 
958
	/* 1.3 is pathetic, so fuzz up a bit */
-
 
959
	return t[9] * 10000 + 5001;
-
 
960
}
-
 
961
 
-
 
962
static bool
-
 
963
mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
-
 
964
	      struct detailed_timing *timing)
-
 
965
{
-
 
966
	u32 max_clock;
-
 
967
	u8 *t = (u8 *)timing;
-
 
968
 
-
 
969
	if (!mode_in_hsync_range(mode, edid, t))
-
 
970
		return false;
-
 
971
 
-
 
972
	if (!mode_in_vsync_range(mode, edid, t))
-
 
973
		return false;
-
 
974
 
-
 
975
	if ((max_clock = range_pixel_clock(edid, t)))
-
 
976
		if (mode->clock > max_clock)
-
 
977
			return false;
-
 
978
 
-
 
979
	/* 1.4 max horizontal check */
-
 
980
	if (edid->revision >= 4 && t[10] == 0x04)
-
 
981
		if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
-
 
982
			return false;
-
 
983
 
-
 
984
	if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
-
 
985
		return false;
814
 
986
 
815
/**
987
	return true;
816
 * add_established_modes - get est. modes from EDID and add them
988
}
817
 * @edid: EDID block to scan
989
 
-
 
990
/*
818
 *
991
 * XXX If drm_dmt_modes ever regrows the CVT-R modes (and it will) this will
-
 
992
 * need to account for them.
819
 * Each EDID block contains a bitmap of the supported "established modes" list
993
 */
820
 * (defined above).  Tease them out and add them to the global modes list.
-
 
821
 */
-
 
822
static int add_established_modes(struct drm_connector *connector, struct edid *edid)
-
 
823
{
-
 
824
	struct drm_device *dev = connector->dev;
994
static int
825
	unsigned long est_bits = edid->established_timings.t1 |
-
 
826
		(edid->established_timings.t2 << 8) |
-
 
827
		((edid->established_timings.mfg_rsvd & 0x80) << 9);
-
 
828
	int i, modes = 0;
995
drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
-
 
996
				   struct detailed_timing *timing)
-
 
997
{
-
 
998
	int i, modes = 0;
-
 
999
	struct drm_display_mode *newmode;
829
 
1000
	struct drm_device *dev = connector->dev;
830
	for (i = 0; i <= EDID_EST_TIMINGS; i++)
1001
 
831
		if (est_bits & (1<
1002
	for (i = 0; i < drm_num_dmt_modes; i++) {
832
			struct drm_display_mode *newmode;
1003
		if (mode_in_range(drm_dmt_modes + i, edid, timing)) {
833
			newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1004
			newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
834
			if (newmode) {
1005
			if (newmode) {
-
 
1006
				drm_mode_probed_add(connector, newmode);
Line 835... Line 1007...
835
				drm_mode_probed_add(connector, newmode);
1007
				modes++;
836
				modes++;
1008
			}
837
			}
1009
		}
838
		}
-
 
839
 
-
 
840
	return modes;
1010
	}
841
}
1011
 
842
/**
1012
	return modes;
843
 * stanard_timing_level - get std. timing level(CVT/GTF/DMT)
1013
}
-
 
1014
 
844
 * @edid: EDID block to scan
1015
static void
-
 
1016
do_inferred_modes(struct detailed_timing *timing, void *c)
-
 
1017
{
-
 
1018
	struct detailed_mode_closure *closure = c;
845
 */
1019
	struct detailed_non_pixel *data = &timing->data.other_data;
846
static int standard_timing_level(struct edid *edid)
1020
	int gtf = (closure->edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
847
{
1021
 
-
 
1022
	if (gtf && data->type == EDID_DETAIL_MONITOR_RANGE)
-
 
1023
		closure->modes += drm_gtf_modes_for_range(closure->connector,
-
 
1024
							  closure->edid,
-
 
1025
							  timing);
-
 
1026
}
-
 
1027
 
-
 
1028
static int
-
 
1029
add_inferred_modes(struct drm_connector *connector, struct edid *edid)
-
 
1030
{
-
 
1031
	struct detailed_mode_closure closure = {
-
 
1032
		connector, edid, 0, 0, 0
-
 
1033
	};
-
 
1034
 
-
 
1035
	if (version_greater(edid, 1, 0))
-
 
1036
		drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
-
 
1037
					    &closure);
-
 
1038
 
-
 
1039
	return closure.modes;
-
 
1040
}
-
 
1041
 
-
 
1042
static int
-
 
1043
drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
-
 
1044
{
-
 
1045
	int i, j, m, modes = 0;
-
 
1046
	struct drm_display_mode *mode;
-
 
1047
	u8 *est = ((u8 *)timing) + 5;
-
 
1048
 
-
 
1049
	for (i = 0; i < 6; i++) {
-
 
1050
		for (j = 7; j > 0; j--) {
-
 
1051
			m = (i * 8) + (7 - j);
-
 
1052
			if (m >= ARRAY_SIZE(est3_modes))
-
 
1053
				break;
-
 
1054
			if (est[i] & (1 << j)) {
-
 
1055
				mode = drm_mode_find_dmt(connector->dev,
-
 
1056
							 est3_modes[m].w,
-
 
1057
							 est3_modes[m].h,
-
 
1058
							 est3_modes[m].r
-
 
1059
							 /*, est3_modes[m].rb */);
-
 
1060
				if (mode) {
-
 
1061
					drm_mode_probed_add(connector, mode);
-
 
1062
					modes++;
848
	if (edid->revision >= 2) {
1063
				}
-
 
1064
			}
-
 
1065
		}
-
 
1066
	}
-
 
1067
 
-
 
1068
	return modes;
-
 
1069
}
-
 
1070
 
-
 
1071
static void
-
 
1072
do_established_modes(struct detailed_timing *timing, void *c)
-
 
1073
{
849
		if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1074
	struct detailed_mode_closure *closure = c;
Line 850... Line 1075...
850
			return LEVEL_CVT;
1075
		struct detailed_non_pixel *data = &timing->data.other_data;
851
		return LEVEL_GTF;
1076
 
852
	}
1077
	if (data->type == EDID_DETAIL_EST_TIMINGS)
853
	return LEVEL_DMT;
1078
		closure->modes += drm_est3_modes(closure->connector, timing);
854
}
1079
}
855
 
1080
 
856
/**
1081
/**
-
 
1082
 * add_established_modes - get est. modes from EDID and add them
857
 * add_standard_modes - get std. modes from EDID and add them
1083
 * @edid: EDID block to scan
858
 * @edid: EDID block to scan
1084
 *
859
 *
1085
 * Each EDID block contains a bitmap of the supported "established modes" list
-
 
1086
 * (defined above).  Tease them out and add them to the global modes list.
-
 
1087
 */
-
 
1088
static int
860
 * Standard modes can be calculated using the CVT standard.  Grab them from
1089
add_established_modes(struct drm_connector *connector, struct edid *edid)
-
 
1090
{
861
 * @edid, calculate them, and add them to the list.
1091
	struct drm_device *dev = connector->dev;
862
 */
1092
	unsigned long est_bits = edid->established_timings.t1 |
863
static int add_standard_modes(struct drm_connector *connector, struct edid *edid)
-
 
Line 864... Line 1093...
864
{
1093
		(edid->established_timings.t2 << 8) |
865
	struct drm_device *dev = connector->dev;
1094
		((edid->established_timings.mfg_rsvd & 0x80) << 9);
866
	int i, modes = 0;
1095
	int i, modes = 0;
867
	int timing_level;
-
 
868
 
-
 
869
	timing_level = standard_timing_level(edid);
-
 
870
 
-
 
871
	for (i = 0; i < EDID_STD_TIMINGS; i++) {
-
 
872
		struct std_timing *t = &edid->standard_timings[i];
1096
	struct detailed_mode_closure closure = {
873
		struct drm_display_mode *newmode;
-
 
874
 
1097
		connector, edid, 0, 0, 0
875
		/* If std timings bytes are 1, 1 it's empty */
1098
	};
876
		if (t->hsize == 1 && t->vfreq_aspect == 1)
1099
 
877
			continue;
1100
	for (i = 0; i <= EDID_EST_TIMINGS; i++) {
878
 
1101
		if (est_bits & (1<
879
		newmode = drm_mode_std(dev, &edid->standard_timings[i],
-
 
880
				       edid->revision, timing_level);
-
 
881
		if (newmode) {
1102
			struct drm_display_mode *newmode;
Line 882... Line -...
882
			drm_mode_probed_add(connector, newmode);
-
 
883
			modes++;
-
 
884
		}
1103
			newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
885
	}
-
 
886
 
-
 
887
	return modes;
-
 
888
}
-
 
889
 
1104
			if (newmode) {
890
/*
-
 
891
 * XXX fix this for:
1105
		drm_mode_probed_add(connector, newmode);
892
 * - GTF secondary curve formula
-
 
Line 893... Line 1106...
893
 * - EDID 1.4 range offsets
1106
				modes++;
894
 * - CVT extended bits
1107
			}
895
 */
-
 
896
static bool
-
 
Line -... Line 1108...
-
 
1108
		}
-
 
1109
	}
-
 
1110
 
-
 
1111
	if (version_greater(edid, 1, 0))
897
mode_in_range(struct drm_display_mode *mode, struct detailed_timing *timing)
1112
		    drm_for_each_detailed_block((u8 *)edid,
-
 
1113
						do_established_modes, &closure);
898
{
1114
 
Line 899... Line 1115...
899
	struct detailed_data_monitor_range *range;
1115
	return modes + closure.modes;
900
	int hsync, vrefresh;
1116
}
-
 
1117
 
-
 
1118
static void
-
 
1119
do_standard_modes(struct detailed_timing *timing, void *c)
Line 901... Line 1120...
901
 
1120
{
902
	range = &timing->data.other_data.data.range;
1121
	struct detailed_mode_closure *closure = c;
903
 
1122
	struct detailed_non_pixel *data = &timing->data.other_data;
904
	hsync = drm_mode_hsync(mode);
1123
	struct drm_connector *connector = closure->connector;
905
	vrefresh = drm_mode_vrefresh(mode);
1124
	struct edid *edid = closure->edid;
906
 
1125
 
-
 
1126
	if (data->type == EDID_DETAIL_STD_MODES) {
-
 
1127
		int i;
907
	if (hsync < range->min_hfreq_khz || hsync > range->max_hfreq_khz)
1128
		for (i = 0; i < 6; i++) {
908
		return false;
-
 
909
 
-
 
910
	if (vrefresh < range->min_vfreq || vrefresh > range->max_vfreq)
1129
				struct std_timing *std;
Line 911... Line 1130...
911
		return false;
1130
				struct drm_display_mode *newmode;
912
 
1131
 
913
	if (range->pixel_clock_mhz && range->pixel_clock_mhz != 0xff) {
1132
			std = &data->data.timings[i];
-
 
1133
			newmode = drm_mode_std(connector, edid, std,
-
 
1134
					       edid->revision);
-
 
1135
				if (newmode) {
914
		/* be forgiving since it's in units of 10MHz */
1136
					drm_mode_probed_add(connector, newmode);
-
 
1137
				closure->modes++;
915
		int max_clock = range->pixel_clock_mhz * 10 + 9;
1138
				}
916
		max_clock *= 1000;
-
 
917
		if (mode->clock > max_clock)
1139
			}
918
			return false;
1140
		}
-
 
1141
}
-
 
1142
 
-
 
1143
/**
-
 
1144
 * add_standard_modes - get std. modes from EDID and add them
-
 
1145
 * @edid: EDID block to scan
919
	}
1146
 *
920
 
-
 
Line 921... Line 1147...
921
	return true;
1147
 * Standard modes can be calculated using the appropriate standard (DMT,
922
}
1148
 * GTF or CVT. Grab them from @edid and add them to the list.
923
 
1149
 */
924
/*
1150
static int
925
 * XXX If drm_dmt_modes ever regrows the CVT-R modes (and it will) this will
1151
add_standard_modes(struct drm_connector *connector, struct edid *edid)
926
 * need to account for them.
1152
{
927
 */
1153
	int i, modes = 0;
928
static int drm_gtf_modes_for_range(struct drm_connector *connector,
1154
	struct detailed_mode_closure closure = {
929
				   struct detailed_timing *timing)
-
 
Line -... Line 1155...
-
 
1155
		connector, edid, 0, 0, 0
-
 
1156
	};
-
 
1157
 
-
 
1158
	for (i = 0; i < EDID_STD_TIMINGS; i++) {
-
 
1159
		struct drm_display_mode *newmode;
-
 
1160
 
930
{
1161
		newmode = drm_mode_std(connector, edid,
931
	int i, modes = 0;
1162
				       &edid->standard_timings[i],
Line 932... Line 1163...
932
	struct drm_display_mode *newmode;
1163
				       edid->revision);
933
	struct drm_device *dev = connector->dev;
1164
		if (newmode) {
934
 
1165
			drm_mode_probed_add(connector, newmode);
Line 992... Line 1223...
992
	}
1223
		}
Line 993... Line 1224...
993
 
1224
 
994
	return modes;
1225
	return modes;
Line 995... Line 1226...
995
}
1226
}
996
 
1227
 
997
static int add_detailed_modes(struct drm_connector *connector,
-
 
998
			      struct detailed_timing *timing,
1228
static void
999
			      struct edid *edid, u32 quirks, int preferred)
1229
do_cvt_mode(struct detailed_timing *timing, void *c)
1000
{
1230
{
1001
	int i, modes = 0;
-
 
1002
		struct detailed_non_pixel *data = &timing->data.other_data;
-
 
1003
	int timing_level = standard_timing_level(edid);
-
 
1004
	int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
-
 
1005
		struct drm_display_mode *newmode;
-
 
1006
	struct drm_device *dev = connector->dev;
-
 
1007
 
-
 
1008
	if (timing->pixel_clock) {
-
 
1009
		newmode = drm_mode_detailed(dev, edid, timing, quirks);
-
 
1010
		if (!newmode)
-
 
1011
			return 0;
-
 
1012
 
-
 
1013
		if (preferred)
-
 
1014
			newmode->type |= DRM_MODE_TYPE_PREFERRED;
-
 
1015
 
-
 
1016
		drm_mode_probed_add(connector, newmode);
-
 
1017
		return 1;
-
 
1018
	}
-
 
1019
 
-
 
1020
	/* other timing types */
-
 
1021
		switch (data->type) {
-
 
1022
		case EDID_DETAIL_MONITOR_RANGE:
-
 
1023
		if (gtf)
-
 
1024
			modes += drm_gtf_modes_for_range(connector, timing);
-
 
1025
			break;
-
 
1026
		case EDID_DETAIL_STD_MODES:
-
 
1027
		/* Six modes per detailed section */
-
 
1028
		for (i = 0; i < 6; i++) {
-
 
Line 1029... Line -...
1029
				struct std_timing *std;
-
 
1030
				struct drm_display_mode *newmode;
-
 
1031
 
-
 
1032
			std = &data->data.timings[i];
-
 
1033
			newmode = drm_mode_std(dev, std, edid->revision,
-
 
1034
							       timing_level);
-
 
1035
				if (newmode) {
-
 
1036
					drm_mode_probed_add(connector, newmode);
-
 
1037
					modes++;
-
 
1038
				}
1231
	struct detailed_mode_closure *closure = c;
1039
			}
1232
	struct detailed_non_pixel *data = &timing->data.other_data;
1040
			break;
-
 
1041
	case EDID_DETAIL_CVT_3BYTE:
-
 
1042
		modes += drm_cvt_modes(connector, timing);
-
 
1043
		break;
-
 
1044
		default:
-
 
1045
			break;
-
 
1046
		}
1233
 
Line 1047... Line -...
1047
 
-
 
1048
	return modes;
-
 
1049
}
-
 
1050
 
-
 
1051
/**
-
 
1052
 * add_detailed_info - get detailed mode info from EDID data
-
 
1053
 * @connector: attached connector
-
 
1054
 * @edid: EDID block to scan
-
 
1055
 * @quirks: quirks to apply
1234
	if (data->type == EDID_DETAIL_CVT_3BYTE)
1056
 *
1235
		closure->modes += drm_cvt_modes(closure->connector, timing);
1057
 * Some of the detailed timing sections may contain mode information.  Grab
-
 
1058
 * it and add it to the list.
1236
}
-
 
1237
 
1059
 */
1238
static int
-
 
1239
add_cvt_modes(struct drm_connector *connector, struct edid *edid)
Line 1060... Line 1240...
1060
static int add_detailed_info(struct drm_connector *connector,
1240
{	
1061
			     struct edid *edid, u32 quirks)
1241
	struct detailed_mode_closure closure = {
1062
{
-
 
1063
	int i, modes = 0;
-
 
1064
 
-
 
1065
	for (i = 0; i < EDID_DETAILED_TIMINGS; i++) {
-
 
1066
		struct detailed_timing *timing = &edid->detailed_timings[i];
-
 
1067
		int preferred = (i == 0) && (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
-
 
Line 1068... Line 1242...
1068
 
1242
		connector, edid, 0, 0, 0
1069
		/* In 1.0, only timings are allowed */
-
 
1070
		if (!timing->pixel_clock && edid->version == 1 &&
-
 
Line 1071... Line 1243...
1071
			edid->revision == 0)
1243
	};
1072
				continue;
1244
 
Line 1073... Line -...
1073
 
-
 
1074
		modes += add_detailed_modes(connector, timing, edid, quirks,
-
 
1075
					    preferred);
1245
	if (version_greater(edid, 1, 2))
1076
		}
-
 
1077
 
-
 
1078
	return modes;
-
 
1079
}
-
 
1080
 
-
 
1081
/**
-
 
1082
 * add_detailed_mode_eedid - get detailed mode info from addtional timing
-
 
1083
 * 			EDID block
1246
		drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
1084
 * @connector: attached connector
-
 
1085
 * @edid: EDID block to scan(It is only to get addtional timing EDID block)
1247
 
1086
 * @quirks: quirks to apply
-
 
1087
 *
-
 
1088
 * Some of the detailed timing sections may contain mode information.  Grab
1248
	/* XXX should also look for CVT codes in VTB blocks */
1089
 * it and add it to the list.
-
 
1090
 */
1249
 
1091
static int add_detailed_info_eedid(struct drm_connector *connector,
-
 
1092
			     struct edid *edid, u32 quirks)
-
 
1093
{
-
 
1094
	int i, modes = 0;
-
 
1095
	char *edid_ext = NULL;
-
 
1096
	struct detailed_timing *timing;
-
 
1097
	int edid_ext_num;
-
 
1098
	int start_offset, end_offset;
-
 
1099
	int timing_level;
-
 
1100
 
-
 
1101
	if (edid->version == 1 && edid->revision < 3) {
-
 
1102
		/* If the EDID version is less than 1.3, there is no
-
 
1103
		 * extension EDID.
-
 
1104
		 */
-
 
1105
		return 0;
-
 
1106
	}
-
 
1107
	if (!edid->extensions) {
-
 
1108
		/* if there is no extension EDID, it is unnecessary to
-
 
Line 1109... Line 1250...
1109
		 * parse the E-EDID to get detailed info
1250
	return closure.modes;
1110
		 */
1251
}
1111
		return 0;
1252
 
1112
	}
1253
static void
1113
 
1254
do_detailed_mode(struct detailed_timing *timing, void *c)
1114
	/* Chose real EDID extension number */
1255
{
1115
	edid_ext_num = edid->extensions > DRM_MAX_EDID_EXT_NUM ?
-
 
Line 1116... Line 1256...
1116
		DRM_MAX_EDID_EXT_NUM : edid->extensions;
1256
	struct detailed_mode_closure *closure = c;
1117
 
1257
	struct drm_display_mode *newmode;
1118
	/* Find CEA extension */
-
 
1119
	for (i = 0; i < edid_ext_num; i++) {
-
 
Line 1120... Line 1258...
1120
		edid_ext = (char *)edid + EDID_LENGTH * (i + 1);
1258
 
1121
		/* This block is CEA extension */
1259
	if (timing->pixel_clock) {
1122
		if (edid_ext[0] == 0x02)
1260
		newmode = drm_mode_detailed(closure->connector->dev,
1123
			break;
-
 
1124
	}
-
 
1125
 
-
 
1126
	if (i == edid_ext_num) {
-
 
1127
		/* if there is no additional timing EDID block, return */
-
 
1128
		return 0;
1261
					    closure->edid, timing,
1129
	}
-
 
1130
 
-
 
1131
	/* Get the start offset of detailed timing block */
-
 
1132
	start_offset = edid_ext[2];
-
 
1133
	if (start_offset == 0) {
-
 
1134
		/* If the start_offset is zero, it means that neither detailed
-
 
1135
		 * info nor data block exist. In such case it is also
-
 
1136
		 * unnecessary to parse the detailed timing info.
-
 
1137
		 */
1262
					    closure->quirks);
Line 1138... Line -...
1138
		return 0;
-
 
1139
	}
-
 
1140
 
-
 
1141
	timing_level = standard_timing_level(edid);
-
 
1142
	end_offset = EDID_LENGTH;
1263
		if (!newmode)
1143
	end_offset -= sizeof(struct detailed_timing);
1264
			return;
1144
	for (i = start_offset; i < end_offset;
-
 
1145
			i += sizeof(struct detailed_timing)) {
1265
 
1146
		timing = (struct detailed_timing *)(edid_ext + i);
-
 
1147
		modes += add_detailed_modes(connector, timing, edid, quirks, 0);
1266
		if (closure->preferred)
1148
	}
1267
			newmode->type |= DRM_MODE_TYPE_PREFERRED;
1149
 
-
 
1150
	return modes;
-
 
1151
}
1268
 
1152
 
-
 
1153
#define DDC_ADDR 0x50
1269
		drm_mode_probed_add(closure->connector, newmode);
1154
/**
-
 
1155
 * Get EDID information via I2C.
1270
		closure->modes++;
1156
 *
1271
		closure->preferred = 0;
1157
 * \param adapter : i2c device adaptor
1272
	}
1158
 * \param buf     : EDID data buffer to be filled
1273
}
1159
 * \param len     : EDID data buffer length
1274
 
1160
 * \return 0 on success or -1 on failure.
1275
/*
1161
 *
-
 
1162
 * Try to fetch EDID information by calling i2c driver function.
1276
 * add_detailed_modes - Add modes from detailed timings
1163
 */
-
 
1164
int drm_do_probe_ddc_edid(struct i2c_adapter *adapter,
-
 
1165
			  unsigned char *buf, int len)
-
 
1166
{
1277
 * @connector: attached connector
1167
	unsigned char start = 0x0;
1278
 * @edid: EDID block to scan
1168
	struct i2c_msg msgs[] = {
1279
 * @quirks: quirks to apply
Line 1169... Line 1280...
1169
		{
1280
 */
1170
			.addr	= DDC_ADDR,
1281
static int
-
 
1282
add_detailed_modes(struct drm_connector *connector, struct edid *edid,
Line 1171... Line -...
1171
			.flags	= 0,
-
 
1172
			.len	= 1,
-
 
1173
			.buf	= &start,
1283
		   u32 quirks)
Line 1174... Line -...
1174
		}, {
-
 
1175
			.addr	= DDC_ADDR,
-
 
1176
			.flags	= I2C_M_RD,
-
 
1177
			.len	= len,
-
 
1178
			.buf	= buf,
-
 
1179
		}
-
 
1180
	};
-
 
1181
 
-
 
1182
	if (i2c_transfer(adapter, msgs, 2) == 2)
1284
{
1183
		return 0;
-
 
1184
 
-
 
1185
	return -1;
1285
	struct detailed_mode_closure closure = {
Line 1186... Line 1286...
1186
}
1286
		connector,
1187
EXPORT_SYMBOL(drm_do_probe_ddc_edid);
1287
		edid,
1188
 
1288
		1,
1189
static int drm_ddc_read_edid(struct drm_connector *connector,
1289
		quirks,
1190
			     struct i2c_adapter *adapter,
-
 
Line 1191... Line 1290...
1191
			     char *buf, int len)
1290
		0
1192
{
-
 
1193
	int i;
1291
	};
1194
 
-
 
1195
	for (i = 0; i < 4; i++) {
-
 
1196
		if (drm_do_probe_ddc_edid(adapter, buf, len))
-
 
1197
			return -1;
-
 
1198
		if (drm_edid_is_valid((struct edid *)buf))
-
 
1199
			return 0;
1292
 
1200
	}
1293
	if (closure.preferred && !version_greater(edid, 1, 3))
1201
 
-
 
1202
	/* repeated checksum failures; warn, but carry on */
1294
		closure.preferred =
1203
		dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n",
-
 
1204
			 drm_get_connector_name(connector));
-
 
1205
	return -1;
-
 
1206
}
-
 
1207
 
-
 
1208
/**
1295
		    (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
1209
 * drm_get_edid - get EDID data, if available
-
 
1210
 * @connector: connector we're probing
-
 
1211
 * @adapter: i2c adapter to use for DDC
1296
 
1212
 *
-
 
Line 1213... Line -...
1213
 * Poke the given connector's i2c channel to grab EDID data if possible.
-
 
1214
 *
-
 
1215
 * Return edid data or NULL if we couldn't find any.
-
 
1216
 */
-
 
1217
struct edid *drm_get_edid(struct drm_connector *connector,
-
 
1218
			  struct i2c_adapter *adapter)
-
 
1219
{
1297
	drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
1220
	int ret;
-
 
1221
	struct edid *edid;
1298
 
1222
 
-
 
1223
	edid = kmalloc(EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1),
-
 
1224
		       GFP_KERNEL);
-
 
1225
	if (edid == NULL) {
-
 
1226
		dev_warn(&connector->dev->pdev->dev,
-
 
1227
			 "Failed to allocate EDID\n");
-
 
1228
		goto end;
-
 
1229
	}
-
 
1230
 
-
 
1231
	/* Read first EDID block */
-
 
1232
	ret = drm_ddc_read_edid(connector, adapter,
-
 
1233
				(unsigned char *)edid, EDID_LENGTH);
-
 
1234
	if (ret != 0)
-
 
1235
		goto clean_up;
1299
	return closure.modes;
1236
 
-
 
Line -... Line 1300...
-
 
1300
}
-
 
1301
 
-
 
1302
#define HDMI_IDENTIFIER 0x000C03
-
 
1303
#define AUDIO_BLOCK	0x01
-
 
1304
#define VENDOR_BLOCK    0x03
1237
	/* There are EDID extensions to be read */
1305
#define EDID_BASIC_AUDIO	(1 << 6)
Line 1238... Line -...
1238
	if (edid->extensions != 0) {
-
 
1239
		int edid_ext_num = edid->extensions;
-
 
1240
 
-
 
1241
		if (edid_ext_num > DRM_MAX_EDID_EXT_NUM) {
-
 
1242
			dev_warn(&connector->dev->pdev->dev,
1306
 
1243
				 "The number of extension(%d) is "
-
 
1244
				 "over max (%d), actually read number (%d)\n",
-
 
1245
				 edid_ext_num, DRM_MAX_EDID_EXT_NUM,
1307
/**
Line -... Line 1308...
-
 
1308
 * Search EDID for CEA extension block.
1246
				 DRM_MAX_EDID_EXT_NUM);
1309
 */
1247
			/* Reset EDID extension number to be read */
1310
u8 *drm_find_cea_extension(struct edid *edid)
Line 1248... Line -...
1248
			edid_ext_num = DRM_MAX_EDID_EXT_NUM;
-
 
1249
		}
-
 
1250
		/* Read EDID including extensions too */
1311
{
1251
		ret = drm_ddc_read_edid(connector, adapter, (char *)edid,
1312
	u8 *edid_ext = NULL;
1252
					EDID_LENGTH * (edid_ext_num + 1));
1313
	int i;
1253
		if (ret != 0)
1314
 
1254
			goto clean_up;
1315
	/* No EDID or EDID extensions */
1255
 
1316
	if (edid == NULL || edid->extensions == 0)
1256
	}
1317
		return NULL;
1257
 
1318
 
1258
	connector->display_info.raw_edid = (char *)edid;
1319
	/* Find CEA extension */
1259
	goto end;
1320
	for (i = 0; i < edid->extensions; i++) {
1260
 
1321
		edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
1261
clean_up:
1322
		if (edid_ext[0] == CEA_EXT)
1262
	kfree(edid);
1323
			break;
Line 1263... Line -...
1263
	edid = NULL;
-
 
1264
end:
1324
	}
1265
	return edid;
-
 
1266
 
-
 
1267
}
-
 
1268
EXPORT_SYMBOL(drm_get_edid);
-
 
1269
 
-
 
1270
#define HDMI_IDENTIFIER 0x000C03
-
 
1271
#define VENDOR_BLOCK    0x03
-
 
1272
/**
-
 
1273
 * drm_detect_hdmi_monitor - detect whether monitor is hdmi.
-
 
1274
 * @edid: monitor EDID information
-
 
1275
 *
-
 
1276
 * Parse the CEA extension according to CEA-861-B.
-
 
1277
 * Return true if HDMI, false if not or unknown.
-
 
1278
 */
-
 
1279
bool drm_detect_hdmi_monitor(struct edid *edid)
1325
 
1280
{
1326
	if (i == edid->extensions)
Line 1281... Line 1327...
1281
	char *edid_ext = NULL;
1327
		return NULL;
1282
	int i, hdmi_id, edid_ext_num;
1328
 
1283
	int start_offset, end_offset;
1329
	return edid_ext;
Line 1328... Line 1374...
1328
	return is_hdmi;
1374
	return is_hdmi;
1329
}
1375
}
1330
EXPORT_SYMBOL(drm_detect_hdmi_monitor);
1376
EXPORT_SYMBOL(drm_detect_hdmi_monitor);
Line 1331... Line 1377...
1331
 
1377
 
-
 
1378
/**
-
 
1379
 * drm_detect_monitor_audio - check monitor audio capability
-
 
1380
 *
-
 
1381
 * Monitor should have CEA extension block.
-
 
1382
 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
-
 
1383
 * audio' only. If there is any audio extension block and supported
-
 
1384
 * audio format, assume at least 'basic audio' support, even if 'basic
-
 
1385
 * audio' is not defined in EDID.
-
 
1386
 *
-
 
1387
 */
-
 
1388
bool drm_detect_monitor_audio(struct edid *edid)
-
 
1389
{
-
 
1390
	u8 *edid_ext;
-
 
1391
	int i, j;
-
 
1392
	bool has_audio = false;
-
 
1393
	int start_offset, end_offset;
-
 
1394
 
-
 
1395
	edid_ext = drm_find_cea_extension(edid);
-
 
1396
	if (!edid_ext)
-
 
1397
		goto end;
-
 
1398
 
-
 
1399
	has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
-
 
1400
 
-
 
1401
	if (has_audio) {
-
 
1402
		DRM_DEBUG_KMS("Monitor has basic audio support\n");
-
 
1403
		goto end;
-
 
1404
	}
-
 
1405
 
-
 
1406
	/* Data block offset in CEA extension block */
-
 
1407
	start_offset = 4;
-
 
1408
	end_offset = edid_ext[2];
-
 
1409
 
-
 
1410
	for (i = start_offset; i < end_offset;
-
 
1411
			i += ((edid_ext[i] & 0x1f) + 1)) {
-
 
1412
		if ((edid_ext[i] >> 5) == AUDIO_BLOCK) {
-
 
1413
			has_audio = true;
-
 
1414
			for (j = 1; j < (edid_ext[i] & 0x1f); j += 3)
-
 
1415
				DRM_DEBUG_KMS("CEA audio format %d\n",
-
 
1416
					      (edid_ext[i + j] >> 3) & 0xf);
-
 
1417
			goto end;
-
 
1418
		}
-
 
1419
	}
-
 
1420
end:
-
 
1421
	return has_audio;
-
 
1422
}
-
 
1423
EXPORT_SYMBOL(drm_detect_monitor_audio);
-
 
1424
 
-
 
1425
/**
-
 
1426
 * drm_add_display_info - pull display info out if present
-
 
1427
 * @edid: EDID data
-
 
1428
 * @info: display info (attached to connector)
-
 
1429
 *
-
 
1430
 * Grab any available display info and stuff it into the drm_display_info
-
 
1431
 * structure that's part of the connector.  Useful for tracking bpp and
-
 
1432
 * color spaces.
-
 
1433
 */
-
 
1434
static void drm_add_display_info(struct edid *edid,
-
 
1435
				 struct drm_display_info *info)
-
 
1436
{
-
 
1437
	info->width_mm = edid->width_cm * 10;
-
 
1438
	info->height_mm = edid->height_cm * 10;
-
 
1439
 
-
 
1440
	/* driver figures it out in this case */
-
 
1441
	info->bpc = 0;
-
 
1442
	info->color_formats = 0;
-
 
1443
 
-
 
1444
	/* Only defined for 1.4 with digital displays */
-
 
1445
	if (edid->revision < 4)
-
 
1446
		return;
-
 
1447
 
-
 
1448
	if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
-
 
1449
		return;
-
 
1450
 
-
 
1451
	switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
-
 
1452
	case DRM_EDID_DIGITAL_DEPTH_6:
-
 
1453
		info->bpc = 6;
-
 
1454
		break;
-
 
1455
	case DRM_EDID_DIGITAL_DEPTH_8:
-
 
1456
		info->bpc = 8;
-
 
1457
		break;
-
 
1458
	case DRM_EDID_DIGITAL_DEPTH_10:
-
 
1459
		info->bpc = 10;
-
 
1460
		break;
-
 
1461
	case DRM_EDID_DIGITAL_DEPTH_12:
-
 
1462
		info->bpc = 12;
-
 
1463
		break;
-
 
1464
	case DRM_EDID_DIGITAL_DEPTH_14:
-
 
1465
		info->bpc = 14;
-
 
1466
		break;
-
 
1467
	case DRM_EDID_DIGITAL_DEPTH_16:
-
 
1468
		info->bpc = 16;
-
 
1469
		break;
-
 
1470
	case DRM_EDID_DIGITAL_DEPTH_UNDEF:
-
 
1471
	default:
-
 
1472
		info->bpc = 0;
-
 
1473
		break;
-
 
1474
	}
-
 
1475
 
-
 
1476
	info->color_formats = DRM_COLOR_FORMAT_RGB444;
-
 
1477
	if (info->color_formats & DRM_EDID_FEATURE_RGB_YCRCB444)
-
 
1478
		info->color_formats = DRM_COLOR_FORMAT_YCRCB444;
-
 
1479
	if (info->color_formats & DRM_EDID_FEATURE_RGB_YCRCB422)
-
 
1480
		info->color_formats = DRM_COLOR_FORMAT_YCRCB422;
-
 
1481
}
-
 
1482
 
1332
/**
1483
/**
1333
 * drm_add_edid_modes - add modes from EDID data, if available
1484
 * drm_add_edid_modes - add modes from EDID data, if available
1334
 * @connector: connector we're probing
1485
 * @connector: connector we're probing
1335
 * @edid: edid data
1486
 * @edid: edid data
1336
 *
1487
 *
Line 1345... Line 1496...
1345
 
1496
 
1346
	if (edid == NULL) {
1497
	if (edid == NULL) {
1347
		return 0;
1498
		return 0;
1348
	}
1499
	}
1349
	if (!drm_edid_is_valid(edid)) {
1500
	if (!drm_edid_is_valid(edid)) {
1350
		dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n",
1501
		dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
1351
			 drm_get_connector_name(connector));
1502
			 drm_get_connector_name(connector));
1352
		return 0;
1503
		return 0;
Line 1353... Line 1504...
1353
	}
1504
	}
Line -... Line 1505...
-
 
1505
 
-
 
1506
	quirks = edid_get_quirks(edid);
-
 
1507
 
-
 
1508
	/*
-
 
1509
	 * EDID spec says modes should be preferred in this order:
-
 
1510
	 * - preferred detailed mode
-
 
1511
	 * - other detailed modes from base block
-
 
1512
	 * - detailed modes from extension blocks
-
 
1513
	 * - CVT 3-byte code modes
-
 
1514
	 * - standard timing codes
-
 
1515
	 * - established timing codes
-
 
1516
	 * - modes inferred from GTF or CVT range information
-
 
1517
	 *
-
 
1518
	 * We get this pretty much right.
-
 
1519
	 *
1354
 
1520
	 * XXX order for additional mode types in extension blocks?
1355
	quirks = edid_get_quirks(edid);
1521
	 */
1356
 
1522
	num_modes += add_detailed_modes(connector, edid, quirks);
1357
	num_modes += add_established_modes(connector, edid);
1523
	num_modes += add_cvt_modes(connector, edid);
Line 1358... Line 1524...
1358
	num_modes += add_standard_modes(connector, edid);
1524
	num_modes += add_standard_modes(connector, edid);
1359
	num_modes += add_detailed_info(connector, edid, quirks);
1525
	num_modes += add_established_modes(connector, edid);
Line 1360... Line -...
1360
	num_modes += add_detailed_info_eedid(connector, edid, quirks);
-
 
1361
 
-
 
1362
	if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
-
 
1363
		edid_fixup_preferred(connector, quirks);
-
 
1364
 
-
 
1365
	connector->display_info.serration_vsync = (edid->input & DRM_EDID_INPUT_SERRATION_VSYNC) ? 1 : 0;
-
 
1366
	connector->display_info.sync_on_green = (edid->input & DRM_EDID_INPUT_SYNC_ON_GREEN) ? 1 : 0;
-
 
1367
	connector->display_info.composite_sync = (edid->input & DRM_EDID_INPUT_COMPOSITE_SYNC) ? 1 : 0;
1526
	num_modes += add_inferred_modes(connector, edid);
1368
	connector->display_info.separate_syncs = (edid->input & DRM_EDID_INPUT_SEPARATE_SYNCS) ? 1 : 0;
-
 
1369
	connector->display_info.blank_to_black = (edid->input & DRM_EDID_INPUT_BLANK_TO_BLACK) ? 1 : 0;
-
 
1370
	connector->display_info.video_level = (edid->input & DRM_EDID_INPUT_VIDEO_LEVEL) >> 5;
-
 
1371
	connector->display_info.digital = (edid->input & DRM_EDID_INPUT_DIGITAL) ? 1 : 0;
-
 
1372
	connector->display_info.width_mm = edid->width_cm * 10;
-
 
1373
	connector->display_info.height_mm = edid->height_cm * 10;
-
 
1374
	connector->display_info.gamma = edid->gamma;
-
 
1375
	connector->display_info.gtf_supported = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF) ? 1 : 0;
-
 
1376
	connector->display_info.standard_color = (edid->features & DRM_EDID_FEATURE_STANDARD_COLOR) ? 1 : 0;
-
 
Line 1377... Line 1527...
1377
	connector->display_info.display_type = (edid->features & DRM_EDID_FEATURE_DISPLAY_TYPE) >> 3;
1527
 
1378
	connector->display_info.active_off_supported = (edid->features & DRM_EDID_FEATURE_PM_ACTIVE_OFF) ? 1 : 0;
1528
	if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
1379
	connector->display_info.suspend_supported = (edid->features & DRM_EDID_FEATURE_PM_SUSPEND) ? 1 : 0;
1529
		edid_fixup_preferred(connector, quirks);
Line 1397... Line 1547...
1397
 */
1547
 */
1398
int drm_add_modes_noedid(struct drm_connector *connector,
1548
int drm_add_modes_noedid(struct drm_connector *connector,
1399
			int hdisplay, int vdisplay)
1549
			int hdisplay, int vdisplay)
1400
{
1550
{
1401
	int i, count, num_modes = 0;
1551
	int i, count, num_modes = 0;
1402
	struct drm_display_mode *mode, *ptr;
1552
	struct drm_display_mode *mode;
1403
	struct drm_device *dev = connector->dev;
1553
	struct drm_device *dev = connector->dev;
Line 1404... Line 1554...
1404
 
1554
 
1405
	count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
1555
	count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
1406
	if (hdisplay < 0)
1556
	if (hdisplay < 0)
1407
		hdisplay = 0;
1557
		hdisplay = 0;
1408
	if (vdisplay < 0)
1558
	if (vdisplay < 0)
Line 1409... Line 1559...
1409
		vdisplay = 0;
1559
		vdisplay = 0;
1410
 
1560
 
1411
	for (i = 0; i < count; i++) {
1561
	for (i = 0; i < count; i++) {
1412
		ptr = &drm_dmt_modes[i];
1562
		const struct drm_display_mode *ptr = &drm_dmt_modes[i];
1413
		if (hdisplay && vdisplay) {
1563
		if (hdisplay && vdisplay) {
1414
			/*
1564
			/*
1415
			 * Only when two are valid, they will be used to check
1565
			 * Only when two are valid, they will be used to check