aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/emgd/display/pi/cmn/igd_pi.c
blob: 24086dc23a0092c32964924ef7afa60ec6be2306 (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
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: igd_pi.c
 * $Revision: 1.5 $
 *-----------------------------------------------------------------------------
 * 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:
 *  Callback functions to give to port drivers. All functions are provided
 *  to port driver as callback functions. Only port driver should call
 *  these functions.
 *-----------------------------------------------------------------------------
 */

#include <context.h>

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

/* #include <igd_pi.h> */
#include <igd_debug.h>

#include <pi.h>
#include <pd.h>

/*!
 * @addtogroup display_group
 * @{
 */

/*!
 * Function to register with main driver.
 * 
 * @param handle
 * @param pd_driver
 *
 * @return pi_pd_register()
 */
int igd_pd_register(void *handle, void *pd_driver)
{
	return pi_pd_register(pd_driver);
} /* igd_pd_register */

/*!
 * Function to allocate memory
 * 
 * @param handle
 * @param pd_driver
 *
 * @return void
 */
void *igd_pd_malloc(unsigned long size)
{
	return OS_ALLOC(size);
} /* end igd_pd_malloc */

/*!
 * Function to set the memory
 * 
 * @param address
 * @param c
 * @param size
 *
 * @return void
 */
void *igd_pd_memset(void *address, int c, unsigned long size)
{
	return OS_MEMSET(address, c, size);
} /* end igd_pd_memset */

/*!
 * Function to copy block of memory
 * 
 * @param dst
 * @param src
 * @param size
 *
 * @return void
 */
void *igd_pd_memcpy(void *dst, void *src, unsigned long size)
{
	return OS_MEMCPY(dst, src, size);
} /* end igd_pd_memcpy */

/* Functions to free memory */
void igd_pd_free(void *ptr)
{
	OS_FREE(ptr);
} /* end igd_pd_free */

/*!
 * Function to sleep in micro seconds. This can be called with millisecond
 * ranges.
 * 
 * @param usec
 *
 * @return void
 */
void igd_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));
	}
} /* end igd_pd_usleep() */

/*!
 * Function to do a string copy
 * 
 * @param dest
 * @param src
 *
 * @return dest
 */
char *igd_pd_strcpy(char *dest, char const *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);
} /* end igd_pd_strcpy() */

/*!
 * Function to check value of an attribute
 * 
 * @param curr
 * @param in
 *
 * @return PD_SUCCESS on success
 * @return PD_ERR_NULL_PTR,PD_ERR_INVALID_ATTR, or PD_ERR_INCORR_ATTR_VALUE
 * 	on failure
 */
int igd_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;
} /* end igd_pd_check_attr() */

/*!
 * 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_attrs
 * @param attr_id
 * @param flag
 *
 * @return attr_list on success
 * @return NULL on failure
 */
pd_attr_t *igd_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 igd_pd_get_attr() */

/*!
 * Common mode filter algorithm for all port drivers
 * 
 * @param context
 * @param ilist
 * @param olist
 * @param dvo
 * @param display
 *
 * @return pd_filter_timings()
 */
int igd_pd_filter_timings(
	void *context,
	pd_timing_t *ilist,
	pd_timing_t **olist,
	pd_dvo_info_t *dvo,
	pd_display_info_t *display)
{
	return pd_filter_timings(context, ilist, olist, dvo, display);
}

igd_debug_t *igd_pd_get_igd_debug( void )
{
	return emgd_debug;
}

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