aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/emgd/display/pd/cmn/pd.c
blob: aa8e3b1233dba170265584e81975bd24fe3f4c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: pd.c
 * $Revision: 1.7 $
 *-----------------------------------------------------------------------------
 * Copyright © 2002-2010, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *-----------------------------------------------------------------------------
 * Description:
 *  This file contains all the necessary common functions for port driver
 *  module. These functions are called only from hardware specific port
 *  drivers. These are exported via pd.h.
 *-----------------------------------------------------------------------------
 */

#define MODULE_NAME hal.dpd

#include <io.h>

#include <memory.h>
#include <sched.h>

#include <mode.h>
#include <pd.h>
#include <pi.h>
/*!
 * @addtogroup display_group
 * @{
 */

/*!
 *
 * @param size
 *
 * @return void
 */
void *pd_malloc(unsigned long size)
{
	return OS_ALLOC(size);
} /* end pd_malloc */

/*!
 *
 * @param address
 * @param c
 * @size
 *
 * @return void
 */
void *pd_memset(void *address, int c, unsigned long size)
{
	return OS_MEMSET(address, c, size);
} /* end pd_memset */

/*!
 *
 * @param dst
 * @param src
 * @param size
 *
 * @return void
 */
void *pd_memcpy(void *dst, void *src, unsigned long size)
{
	return OS_MEMCPY(dst, src, size);
} /* end pd_memcpy */

/*!
 *
 * @param size
 *
 * @return void
 */
void pd_free(void *ptr)
{
	OS_FREE(ptr);
} /* end pd_free */

/*!
 *
 * @param usec
 *
 * @return void
 */
void pd_usleep(unsigned long usec)
{
	
	if (usec <= 1000) {
		OS_SLEEP(usec);
	} else {
		os_alarm_t alarm = OS_SET_ALARM((usec+999)/1000);
		do {
			OS_SCHEDULE();
		} while (!OS_TEST_ALARM(alarm));
	}

}

/*!
 *
 * @param usec
 *
 * @return void
 */
void pd_ui_usleep(unsigned long usec)
{
	OS_UISLEEP(usec);

}

/*!
 *
 * @param dest
 * @param src
 *
 * @return dest
 */
char *pd_strcpy(char *dest, const char *src)
{
	int i = 0;
	/* This can be optimized by assigning 32 bit quantities instead
	 * of 8 bit quantities. This requires knowing the length first then
	 * move the quantities. For now, this is OK. */
	while (src[i] != '\0') {
		dest[i] = src[i];
		i++;
	}
	dest[i] = '\0';
	return (dest);
}

/*!
 *
 * @param handle
 * @param driver
 *
 * @return pi_pd_register()
 */
int pd_register(void *handle, pd_driver_t *driver)
{
	return (pi_pd_register(driver));
} /* end pd_register */

/*!
 *
 * @param curr
 * @param in
 *
 * @return PD_SUCCESS on success
 * @return PD_ERR_INVALID_ATTR or PD_ERR_INCORR_ATTR_VALUE on failure
 */
int pd_check_attr(pd_attr_t *curr, pd_attr_t *in)
{
	if (!curr || !in) {
		return PD_ERR_NULL_PTR;
	}

	if (curr->id != in->id) {
		return PD_ERR_INVALID_ATTR;
	}

	switch (curr->type) {
		case PD_ATTR_TYPE_RANGE:
			if ((in->current_value < RATTR(curr)->min) ||
				(in->current_value > RATTR(curr)->max)) {
				return PD_ERR_INCORR_ATTR_VALUE;
			}
			break;
		case PD_ATTR_TYPE_LIST:
			if ((in->current_value < 1) ||
				(in->current_value > LHATTR(curr)->num_entries)) {
				return PD_ERR_INCORR_ATTR_VALUE;
			}
			break;
		case PD_ATTR_TYPE_BOOL:
			if ((in->current_value != TRUE) &&
				(in->current_value != FALSE)) {
				return PD_ERR_INCORR_ATTR_VALUE;
			}
			break;
		default:
			return PD_ERR_INVALID_ATTR;
	}
	return PD_SUCCESS;
}

/*!
 * This function searches for the requested attr_id in the attribute list
 * and returns the pointer.
 *
 * In case of LIST attribute, it will return the proper list entry.
 *
 * @param attr_list
 * @param num_attr
 * @param attr_id
 * @param flag
 *
 * @return pd_attr_t on success
 * @return NULL on failure
 */
pd_attr_t *pd_get_attr(pd_attr_t *attr_list, unsigned long num_attrs,
		unsigned long attr_id, unsigned long flag)
{
	unsigned long i;

	if (!attr_list) {
		return NULL;
	}

	for (i = 0; i < num_attrs; i++) {
		if (attr_list[i].id == attr_id) {
			if (attr_list[i].type == PD_ATTR_TYPE_LIST) {
				if (flag == PD_GET_ATTR_LIST_ENTRY) {
					return (&(attr_list[i+attr_list[i].current_value]));
				} else {
					return (&(attr_list[i]));
				}
			}
			return (&(attr_list[i]));
		}
	}
	return NULL;
} /* end pd_get_attr() */

/*!
 * Common mode filter algorithm for all port drivers
 *
 * @param call_back
 * @param in_list
 * @param out_list
 * @param dvo_info
 * @param display_info
 *
 * @return PD_SUCCESS on success
 * @return PD_ERR_NULL_PTR or PD_ERR_NOMEM on failure
 */
int pd_filter_timings(
	void *callback_context,
	pd_timing_t *in_list,
	pd_timing_t **out_list,
	pd_dvo_info_t *dvo_info,
	pd_display_info_t *display_info)
{
	igd_display_port_t *port = (igd_display_port_t *)callback_context;
	pd_timing_t    *timing   = NULL, *native_dtd = NULL;
	int            j;
	int            count     = 0;
	unsigned short fp_refresh = 60;
	pd_timing_t    *olist = NULL;
	unsigned long  fixed_timing = 0;
	int i, ret;

	if (!port || !in_list || !out_list) {
		return PD_ERR_NULL_PTR;
	}

	/* Start with fixed_res = 0 */
	display_info->fixed_res = 0;

	/* DisplayID FP width are specified */
	if (port->firmware_type == PI_FIRMWARE_DISPLAYID) {
		display_info->width = port->displayid->display_params.horz_pixels;
		display_info->height = port->displayid->display_params.vert_pixels;
		fixed_timing = port->displayid->display_params.fixed_timing;
		display_info->fixed_res = port->displayid->display_params.fixed_res;
	}

	/* Overwrite DisplayID FP values with config fpinfo, later
	 * these will be overwritten by native DTD width, height */
	if (port->fp_info) {
		/* This is done for backward compatibility:
		 * Set width, height from display port fp_info
		 * This also required dropping fp_info width and height attributes
		 * from all port drivers */
		display_info->width = (unsigned short) port->fp_info->fp_width;
		display_info->height = (unsigned short) port->fp_info->fp_height;
		/* Backward compatibility: If width and height are specified,
		 * that means it is a fixed resolution panel */
		if (port->fp_info->fp_width && port->fp_info->fp_height) {
			display_info->fixed_res = 1;
			fp_refresh = 60;
		}
	}

	/* If fixed timing also comes from user attributes then override DisplayID
	 * fixed timing and fpinfo values */
	ret = pi_get_port_init_attr(port, PD_ATTR_ID_FIXED_TIMING, &fixed_timing);
	if (fixed_timing) {
		display_info->fixed_res = 1;
		fp_refresh = 60;
	}

	/* Do gmch filtering:
	 * There is no way to get the mode context inorder to reach the
	 * gmch filtering function */

	/* First find the native resolution */
	get_native_dtd(in_list, PI_SUPPORTED_TIMINGS,
		&display_info->native_dtd, PD_MODE_DTD_FP_NATIVE);

	/* If no FP Native DTD provided, then get the native DTD
	 *   either user DTD or edid DTD */
	if (!display_info->native_dtd) {
		get_native_dtd(in_list, PI_SUPPORTED_TIMINGS,
			&display_info->native_dtd, PD_MODE_DTD_USER);
	}
	if (!display_info->native_dtd) {
		get_native_dtd(in_list, PI_SUPPORTED_TIMINGS,
			&display_info->native_dtd, PD_MODE_DTD);
	}

	/* Set up the fp width, height and refresh for the comparison */
	if (display_info->native_dtd) {
#ifndef CONFIG_MICRO
		/* If fp width, height doesn' match with native width and height,
		 * Configuration isn't correct */
		if ((display_info->width &&
				(display_info->width != display_info->native_dtd->width)) &&
			(display_info->height &&
				(display_info->height != display_info->native_dtd->height))) {
			EMGD_DEBUG("FP Width Height doesn't match with Native DTD.");
		}
#endif
		/* Overwrite native width height as panel width and height */
		display_info->width = display_info->native_dtd->width;
		display_info->height = display_info->native_dtd->height;
		fp_refresh = display_info->native_dtd->refresh;
	} else if (ret &&
		port->firmware_type != PI_FIRMWARE_DISPLAYID &&
		dvo_info->upscale) {
		/* TODO:
		 * For time being this function has to assume all upscaling encoders
		 * are connected to a fixed timing panel if no fixed_timing is
		 * specified.
		 *
		 * Once fixed_timing init-time attribute becomes mandatory, below check
		 * can be removed.
		 *
		 * If customer uses old config system and didn't specified init time
		 * fixed_timing attribute, then driver assumes it is a fixed-resolution
		 * panel. If user do specifies fixed_timing attribute, then above check
		 * will fail, and algorithm continues with whatever value set to
		 * fixed_res attr.
		 *
		 * ret != 0 means no fixed_timing user attribute
		 * firmware_type == DISPLAYID means firmware provided fixed_timing,
		 * so don't change it.
		 */
		display_info->fixed_res = 1;
	}

	/* Check native_dtd for fixed_res display */
	if (display_info->fixed_res && !display_info->native_dtd) {
		/* This happens if user provides fp_width, fp_height and didn't set
		 * fixed res parameter. In this case native_dtd will be set as part
		 * of the while loop while filtering the modes */
		EMGD_DEBUG("pd_filter_timings: No native dtd for fixed_resolution");
	}

	if (!display_info->width && !display_info->height) {
		/* If fp width and height isn't known, then enable all modes as
		 * non-fixed res display */
		display_info->fixed_res = 0;
	}

	EMGD_DEBUG("fixed_res = %u fixed_timing = %lu",
		display_info->fixed_res, fixed_timing);
	EMGD_DEBUG("fp_width = %u, fp_height = %u, fp_refresh = %u",
		display_info->width, display_info->height, fp_refresh);
	EMGD_DEBUG("min_dclk = %lu, max_dclk = %lu",
		dvo_info->min_dclk, dvo_info->max_dclk);

	/* This function can be called with following
	 * ---------------------------------------------------------------
	 *  DVO device PanelFit Display AvailableModes
	 *  DOWN  UP            Fixed?
	 * --------------------------------------------------------
	 *   0     0      0       0     All supported modes
	 *   1     0      0       0     All supported modes
	 *   0     1      0       0     All supported modes
	 *   1     1      0       0     All supported modes
	 *   0     0      1       0     All supported modes
	 *   1     0      1       0     All supported modes
	 *   0     1      1       0     All supported modes
	 *   1     1      1       0     All supported modes
	 *
	 *   0     0      0       Y     Only one mode
	 *   1     0      0       Y     Only one mode
	 *   0     1      0       Y     Only one mode
	 *   1     1      0       Y     Only one mode
	 *   0     0      1       Y     Only one mode
	 *
	 *   0     1      1       Y     All upscalable modes
	 *   1     0      1       Y     All downscalable modes
	 *
	 *   1     1      1       Y     All UP & DOWN scalable modes
	 * -------------------------------------------------------------------------
	 */

	for (i = 0; i < 2; ++i) {
		j = 0;
		timing = in_list;
		while(timing->width != PD_TIMING_LIST_END) {
			/* If mode supported and dclk is within the range */
			if ((timing->mode_info_flags & PD_MODE_SUPPORTED) &&
				((!dvo_info->max_dclk || (timing->dclk <= dvo_info->max_dclk))&&
				(!dvo_info->min_dclk || (timing->dclk >= dvo_info->min_dclk)))){

				if (
					/* fixed_res = 0 */
					!display_info->fixed_res ||

					/* no panel fit */
					(!display_info->panel_fit &&
					timing->refresh == fp_refresh &&
					timing->width   == display_info->width &&
					timing->height  == display_info->height) ||

					/* panel fit and upscale or downscale */
					(display_info->panel_fit &&
					timing->refresh == fp_refresh &&
					((dvo_info->upscale &&
					timing->width  <= display_info->width &&
					timing->height <= display_info->height &&
					(!dvo_info->upscale_min_width ||
						timing->width  >= dvo_info->upscale_min_width) &&
					(!dvo_info->upscale_min_height ||
					timing->height >= dvo_info->upscale_min_height))
#if 0
					||
					(dvo_info->downscale &&
					timing->width  >= display_info->width &&
					timing->height >= display_info->height &&
					(!dvo_info->downscale_max_width ||
						timing->width  <= dvo_info->downscale_max_width) &&
					(!dvo_info->downscale_max_height ||
						timing->height >= dvo_info->downscale_max_height))
#endif
					))) {

					if(!i){
						count++;
					} else {
						/* copy timing */
						olist[j] = *timing;

						/* save the native_dtd timing */
						if ((timing->width   == display_info->width) &&
							(timing->height  == display_info->height) &&
							(timing->refresh == fp_refresh)) {
							native_dtd = &(olist[j]);
						}

						/* The native DTD pointer is pointing in the in_list,
						 * reset this pointer to point in the out_list */
						if (timing == display_info->native_dtd) {
							display_info->native_dtd = &olist[j];
						}

						j++;
					}
				}
			}
			timing++;
			if ((timing->width == PD_TIMING_LIST_END) && timing->extn_ptr) {
				timing = timing->extn_ptr;
			}
		}
		if(!i) {
			count++;
			olist = (pd_timing_t *) pd_malloc(count * sizeof(pd_timing_t));
			if(!olist) {
				return PD_ERR_NOMEM;
			}
		} else {
			/* Copy the END of LIST entry */
			olist[j] = *timing;
		}
	}

	/* If there is no native_dtd, then use the first matching
	 * resolution with fp width and height as native dtd */
	if (!display_info->native_dtd) {
		display_info->native_dtd = native_dtd;
	}
	if (display_info->native_dtd) {
		EMGD_DEBUG("pd_filter_timings: NativeDTD: %ux%u@%u",
			display_info->native_dtd->width,
			display_info->native_dtd->height,
			display_info->native_dtd->refresh);
		display_info->native_dtd->mode_info_flags |= PD_MODE_DTD_FP_NATIVE;
	}

	*out_list = olist;
	return PD_SUCCESS;
}


/*----------------------------------------------------------------------------
 * File Revision History
 * $Id: pd.c,v 1.7 2010/07/23 16:54:49 bpaauwe Exp $
 * $Source: /nfs/fm/proj/eia/cvsroot/koheo/linux/egd_drm/emgd/display/pd/cmn/pd.c,v $
 *----------------------------------------------------------------------------
 */