aboutsummaryrefslogtreecommitdiff
path: root/drivers/gpu/pvr/bufferclass_example_private.c
blob: 360524e23fe65bee4061429077550d922e550101 (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
/**********************************************************************
 *
 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
 *
 * 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, except
 * as otherwise stated in writing, 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.
 *
 * The full GNU General Public License is included in this distribution in
 * the file called "COPYING".
 *
 * Contact Information:
 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
 *
 ******************************************************************************/

#include "bufferclass_example.h"
#include "bufferclass_example_private.h"

#define MIN(a, b) ((a) < (b) ? (a) : (b))

static void FillYUV420Image(void __iomem *pvDest, int width, int height,
			    int bytestride)
{
	static int iPhase;
	int i, j;
	unsigned char u, v, y;
	unsigned char *pui8y = (unsigned char __force *)pvDest;
	unsigned short *pui16uv;
	unsigned int count = 0;

	for (j = 0; j < height; j++)
		for (i = 0; i < width; i++) {
			y = (((i + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;

			pui8y[count++] = y;
		}

	pui16uv = (unsigned short *)
	    ((unsigned char __force *)pvDest + (width * height));
	count = 0;

	for (j = 0; j < height; j += 2)
		for (i = 0; i < width; i += 2) {
			u = (j < (height / 2)) ?
				((i < (width / 2)) ? 0xFF : 0x33) :
				((i < (width / 2)) ?  0x33 : 0xAA);
			v = (j < (height / 2)) ?
				((i < (width / 2)) ?  0xAC : 0x0) :
				((i < (width / 2)) ?  0x03 : 0xEE);

			pui16uv[count++] = (v << 8) | u;

		}

	iPhase++;
}

static void FillYUV422Image(void __iomem *pvDest, int width, int height,
			    int bytestride)
{
	static int iPhase;
	int x, y;
	unsigned char u, v, y0, y1;
	unsigned int *pui32yuv = (unsigned int __force *)pvDest;
	unsigned int count = 0;

	for (y = 0; y < height; y++)
		for (x = 0; x < width; x += 2) {
			u = (y < (height / 2)) ?
			      ((x < (width / 2)) ? 0xFF : 0x33) :
			      ((x < (width / 2)) ? 0x33 : 0xAA);
			v = (y < (height / 2)) ?
			      ((x < (width / 2)) ? 0xAA : 0x0) :
			      ((x < (width / 2)) ? 0x03 : 0xEE);

			y0 = y1 =
			    (((x + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;

			pui32yuv[count++] =
			    (y1 << 24) | (v << 16) | (y0 << 8) | u;

		}

	iPhase++;
}

static void FillRGB565Image(void __iomem *pvDest, int width, int height,
			    int bytestride)
{
	int i, Count;
	unsigned long *pui32Addr = (unsigned long __force *)pvDest;
	unsigned short *pui16Addr = (unsigned short __force *)pvDest;
	unsigned long Colour32;
	unsigned short Colour16;
	static unsigned char Colour8;

	Colour16 = (Colour8 >> 3) | ((Colour8 >> 2) << 5) |
		   ((Colour8 >> 3) << 11);
	Colour32 = Colour16 | Colour16 << 16;

	Count = (height * bytestride) >> 2;

	for (i = 0; i < Count; i++)
		pui32Addr[i] = Colour32;

	Count = height;

	pui16Addr = (unsigned short *)
			((unsigned char __force *)pvDest + (2 * Colour8));

	for (i = 0; i < Count; i++) {
		*pui16Addr = 0xF800;

		pui16Addr =
		    (unsigned short *)((unsigned char *)pui16Addr + bytestride);
	}
	Count = bytestride >> 2;

	pui32Addr = (unsigned long *)((unsigned char __force *)pvDest +
			      (bytestride * (MIN(height - 1, 0xFF) - Colour8)));

	for (i = 0; i < Count; i++)
		pui32Addr[i] = 0x001F001F;

	Colour8 = (Colour8 + 1) % MIN(height - 1, 0xFF);
}

int FillBuffer(unsigned int ui32BufferIndex)
{
	struct BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();
	struct BC_EXAMPLE_BUFFER *psBuffer;
	struct BUFFER_INFO *psBufferInfo;
	struct PVRSRV_SYNC_DATA *psSyncData;

	if (psDevInfo == NULL)
		return -1;

	psBuffer = &psDevInfo->psSystemBuffer[ui32BufferIndex];
	psBufferInfo = &psDevInfo->sBufferInfo;

	psSyncData = psBuffer->psSyncData;

	if (psSyncData) {
		if (psSyncData->ui32ReadOpsPending !=
		    psSyncData->ui32ReadOpsComplete)
			return -1;

		psSyncData->ui32WriteOpsPending++;
	}

	switch (psBufferInfo->pixelformat) {
	case PVRSRV_PIXEL_FORMAT_RGB565:
	default:
		FillRGB565Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
				BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
		break;
	case PVRSRV_PIXEL_FORMAT_FOURCC_ORG_UYVY:
		FillYUV422Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
				BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
		break;
	case PVRSRV_PIXEL_FORMAT_NV12:
		FillYUV420Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
				BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
		break;
	}

	if (psSyncData)
		psSyncData->ui32WriteOpsComplete++;

	return 0;
}

int GetBufferCount(unsigned int *pui32BufferCount)
{
	struct BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();

	if (psDevInfo == NULL)
		return -1;

	*pui32BufferCount = psDevInfo->sBufferInfo.ui32BufferCount;

	return 0;
}