summaryrefslogtreecommitdiff
path: root/drivers/video/bus_vcxk.c
blob: b7875de6f07d34ce2705e197dfb81400bc28e134 (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
/*
 * (C) Copyright 2005-2009
 * Jens Scharsig @ BuS Elektronik GmbH & Co. KG, <esw@bus-elektronik.de>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <bmp_layout.h>
#include <asm/io.h>

vu_char  *vcxk_bws      = ((vu_char *) (CONFIG_SYS_VCXK_BASE));
vu_short *vcxk_bws_word = ((vu_short *)(CONFIG_SYS_VCXK_BASE));
vu_long  *vcxk_bws_long = ((vu_long *) (CONFIG_SYS_VCXK_BASE));

#ifdef CONFIG_AT91RM9200
	#include <asm/arch/hardware.h>
	#ifndef VCBITMASK
		#define VCBITMASK(bitno)	(0x0001 << (bitno % 16))
	#endif
	#define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
		((AT91PS_PIO) PORT)->PIO_PER = PIN; \
		((AT91PS_PIO) PORT)->DDR = PIN; \
		((AT91PS_PIO) PORT)->PIO_MDDR = PIN; \
		if (!I0O1) ((AT91PS_PIO) PORT)->PIO_PPUER = PIN;

	#define VCXK_SET_PIN(PORT, PIN)	((AT91PS_PIO) PORT)->PIO_SODR  = PIN;
	#define VCXK_CLR_PIN(PORT, PIN)	((AT91PS_PIO) PORT)->PIO_CODR  = PIN;

	#define VCXK_ACKNOWLEDGE	\
		(!(((AT91PS_PIO) CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT)->\
			PIO_PDSR & CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))

#elif defined(CONFIG_MCF52x2)
	#include <asm/m5282.h>
	#ifndef VCBITMASK
		#define VCBITMASK(bitno) (0x8000 >> (bitno % 16))
	#endif

	#define VCXK_INIT_PIN(PORT, PIN, DDR, I0O1) \
		if (I0O1) DDR |= PIN; else DDR &= ~PIN;

	#define VCXK_SET_PIN(PORT, PIN)	PORT |= PIN;
	#define VCXK_CLR_PIN(PORT, PIN)	PORT &= ~PIN;

	#define VCXK_ACKNOWLEDGE \
		(!(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT &	\
			CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN))

#else
	#error no vcxk support for selected ARCH
#endif

#define VCXK_DISABLE\
	VCXK_SET_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)
#define VCXK_ENABLE\
	VCXK_CLR_PIN(CONFIG_SYS_VCXK_ENABLE_PORT, CONFIG_SYS_VCXK_ENABLE_PIN)

#ifndef CONFIG_SYS_VCXK_DOUBLEBUFFERED
	#define VCXK_BWS(x, data)		vcxk_bws[x] = data;
	#define VCXK_BWS_WORD_SET(x, mask) 	vcxk_bws_word[x] |= mask;
	#define VCXK_BWS_WORD_CLEAR(x, mask) 	vcxk_bws_word[x] &= ~mask;
	#define VCXK_BWS_LONG(x, data)		vcxk_bws_long[x] = data;
#else
	u_char double_bws[16384];
	u_short *double_bws_word;
	u_long  *double_bws_long;
	#define VCXK_BWS(x,data)	\
		double_bws[x] = data; vcxk_bws[x] = data;
	#define VCXK_BWS_WORD_SET(x,mask)	\
		double_bws_word[x] |= mask;	\
		vcxk_bws_word[x] = double_bws_word[x];
	#define VCXK_BWS_WORD_CLEAR(x,mask)	\
		double_bws_word[x] &= ~mask;	\
		vcxk_bws_word[x] = double_bws_word[x];
	#define VCXK_BWS_LONG(x,data) \
		double_bws_long[x] = data; vcxk_bws_long[x] = data;
#endif

#define VC4K16_Bright1	vcxk_bws_word[0x20004 / 2]
#define VC4K16_Bright2 	vcxk_bws_word[0x20006 / 2]
#define VC2K_Bright	vcxk_bws[0x8000]
#define VC8K_BrightH	vcxk_bws[0xC000]
#define VC8K_BrightL	vcxk_bws[0xC001]

vu_char VC4K16;

u_long display_width;
u_long display_height;
u_long display_bwidth;

ulong search_vcxk_driver(void);
void vcxk_cls(void);
void vcxk_setbrightness(unsigned int side, short brightness);
int vcxk_request(void);
int vcxk_acknowledge_wait(void);
void vcxk_clear(void);

/*
 ****f* bus_vcxk/vcxk_init
 * FUNCTION
 * initialalize Video Controller
 * PARAMETERS
 * width	visible display width in pixel
 * height	visible display height  in pixel
 ***
 */

int vcxk_init(unsigned long width, unsigned long height)
{
#ifdef CONFIG_SYS_VCXK_RESET_PORT
	VCXK_INIT_PIN(CONFIG_SYS_VCXK_RESET_PORT,
		CONFIG_SYS_VCXK_RESET_PIN, CONFIG_SYS_VCXK_RESET_DDR, 1)
	VCXK_SET_PIN(CONFIG_SYS_VCXK_RESET_PORT, CONFIG_SYS_VCXK_RESET_PIN);
#endif

#ifdef CONFIG_SYS_VCXK_DOUBLEBUFFERED
	double_bws_word  = (u_short *) double_bws;
	double_bws_long  = (u_long *)double_bws;
	debug("%lx %lx %lx \n", double_bws, double_bws_word, double_bws_long);
#endif
	display_width  = width;
	display_height = height;
#if (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 4)
	display_bwidth = ((width + 31) / 8) & ~0x3;
#elif (CONFIG_SYS_VCXK_DEFAULT_LINEALIGN == 2)
	display_bwidth = ((width + 15) / 8) & ~0x1;
#else
	#error CONFIG_SYS_VCXK_DEFAULT_LINEALIGN is invalid
#endif
	debug("linesize ((%d + 15) / 8 & ~0x1) = %d\n",
		display_width, display_bwidth);

#ifdef CONFIG_SYS_VCXK_AUTODETECT
	VC4K16 = 0;
	vcxk_bws_long[1] = 0x0;
	vcxk_bws_long[1] = 0x55AAAA55;
	vcxk_bws_long[5] = 0x0;
	if (vcxk_bws_long[1] == 0x55AAAA55)	VC4K16 = 1;
#else
	VC4K16 = 1;
	debug("No autodetect: use vc4k\n");
#endif

	VCXK_INIT_PIN(CONFIG_SYS_VCXK_INVERT_PORT,
		CONFIG_SYS_VCXK_INVERT_PIN, CONFIG_SYS_VCXK_INVERT_DDR, 1)
	VCXK_SET_PIN(CONFIG_SYS_VCXK_INVERT_PORT, CONFIG_SYS_VCXK_INVERT_PIN)

	VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT, CONFIG_SYS_VCXK_REQUEST_PIN);
	VCXK_INIT_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
		CONFIG_SYS_VCXK_REQUEST_PIN, CONFIG_SYS_VCXK_REQUEST_DDR, 1)

	VCXK_INIT_PIN(CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT,
		CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN,
		CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR, 0)

	VCXK_DISABLE;
	VCXK_INIT_PIN(CONFIG_SYS_VCXK_ENABLE_PORT,
		CONFIG_SYS_VCXK_ENABLE_PIN, CONFIG_SYS_VCXK_ENABLE_DDR, 1)

	vcxk_cls();
	vcxk_cls();	/* clear second/hidden page */

	vcxk_setbrightness(3, 1000);
	VCXK_ENABLE;
	return 1;
}

/*
 ****f* bus_vcxk/vcxk_setpixel
 * FUNCTION
 * set the pixel[x,y] with the given color
 * PARAMETER
 * x		pixel colum
 * y		pixel row
 * color	<0x40 off/black
 *			>0x40 on
 ***
 */

void vcxk_setpixel(int x, int y, unsigned long color)
{
	vu_short dataptr;

	if ((x < display_width) && (y < display_height)) {
		dataptr = ((x / 16)) + (y * (display_bwidth >> 1));

		color = ((color >> 16) & 0xFF) |
			    ((color >> 8) & 0xFF) | (color & 0xFF);

		if (color > 0x40) {
			VCXK_BWS_WORD_SET(dataptr, VCBITMASK(x));
		} else {
			VCXK_BWS_WORD_CLEAR(dataptr, VCBITMASK(x));
		}
	}
}

/*
 ****f* bus_vcxk/vcxk_loadimage
 * FUNCTION
 * copies a binary image to display memory
 ***
 */

void vcxk_loadimage(ulong source)
{
	int cnt;
	vcxk_acknowledge_wait();
	if (VC4K16) {
		for (cnt = 0; cnt < (16384 / 4); cnt++) {
			VCXK_BWS_LONG(cnt, (*(ulong *) source));
			source = source + 4;
		}
	} else {
		for (cnt = 0; cnt < 16384; cnt++) {
			VCXK_BWS_LONG(cnt*2, (*(vu_char *) source));
			source++;
		}
	}
	vcxk_request();
}

/*
 ****f* bus_vcxk/vcxk_cls
 * FUNCTION
 * clear the display
 ***
 */

void vcxk_cls(void)
{
	vcxk_acknowledge_wait();
	vcxk_clear();
	vcxk_request();
}

/*
 ****f* bus_vcxk/vcxk_clear(void)
 * FUNCTION
 * clear the display memory
 ***
 */

void vcxk_clear(void)
{
	int cnt;
	for (cnt = 0; cnt < (16384 / 4); cnt++) {
		VCXK_BWS_LONG(cnt, 0)
	}
}

/*
 ****f* bus_vcxk/vcxk_setbrightness
 * FUNCTION
 * set the display brightness
 * PARAMETER
 * side	1	set front side brightness
 * 		2	set back  side brightness
 *		3	set brightness for both sides
 * brightness 0..1000
 ***
 */

void vcxk_setbrightness(unsigned int side, short brightness)
{
	if (VC4K16) {
		if ((side == 0) || (side & 0x1))
			VC4K16_Bright1 = brightness + 23;
		if ((side == 0) || (side & 0x2))
			VC4K16_Bright2 = brightness + 23;
	} else 	{
		VC2K_Bright = (brightness >> 4) + 2;
		VC8K_BrightH = (brightness + 23) >> 8;
		VC8K_BrightL = (brightness + 23) & 0xFF;
	}
}

/*
 ****f* bus_vcxk/vcxk_request
 * FUNCTION
 * requests viewing of display memory
 ***
 */

int vcxk_request(void)
{
	VCXK_CLR_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
		CONFIG_SYS_VCXK_REQUEST_PIN)
	VCXK_SET_PIN(CONFIG_SYS_VCXK_REQUEST_PORT,
		CONFIG_SYS_VCXK_REQUEST_PIN);
	return 1;
}

/*
 ****f* bus_vcxk/vcxk_acknowledge_wait
 * FUNCTION
 * wait for acknowledge viewing requests
 ***
 */

int vcxk_acknowledge_wait(void)
{
	while (VCXK_ACKNOWLEDGE);
	return 1;
}

/*
 ****f* bus_vcxk/vcxk_draw_mono
 * FUNCTION
 * copies a monochrom bitmap (BMP-Format) from given memory
 * PARAMETER
 * dataptr	pointer to bitmap
 * x		output bitmap @ columne
 * y		output bitmap @ row
 ***
 */

void vcxk_draw_mono(unsigned char *dataptr, unsigned long  linewidth,
	unsigned long  cp_width, unsigned long cp_height)
{
	unsigned char *lineptr;
	unsigned long xcnt, ycnt;

	for (ycnt = cp_height; ycnt > 0; ycnt--) {
		lineptr	= dataptr;
		for (xcnt = 0; xcnt < cp_width; xcnt++) {
			if ((*lineptr << (xcnt % 8)) & 0x80)
				vcxk_setpixel(xcnt, ycnt - 1, 0xFFFFFF);
			else
				vcxk_setpixel(xcnt, ycnt-1, 0);

			if ((xcnt % 8) == 7) lineptr++;
		} /* endfor xcnt */
		dataptr = dataptr + linewidth;
	} /* endfor ycnt */
}

/*
 ****f* bus_vcxk/vcxk_display_bitmap
 * FUNCTION
 * copies a bitmap (BMP-Format) to the given position
 * PARAMETER
 * addr		pointer to bitmap
 * x		output bitmap @ columne
 * y		output bitmap @ row
 ***
 */

int vcxk_display_bitmap(ulong addr, int x, int y)
{
	bmp_image_t *bmp;
	unsigned long width;
	unsigned long height;
	unsigned long bpp;
	unsigned long compression;

	unsigned long lw;

	unsigned long c_width;
	unsigned long c_height;
	unsigned char *dataptr;
	unsigned char *lineptr;

	bmp = (bmp_image_t *) addr;
	if ((bmp->header.signature[0] == 'B') &&
	    (bmp->header.signature[1] == 'M')) {
		compression  = le32_to_cpu(bmp->header.compression);
		width        = le32_to_cpu(bmp->header.width);
		height       = le32_to_cpu(bmp->header.height);
		bpp          = le16_to_cpu(bmp->header.bit_count);

		dataptr = (unsigned char *) bmp +
				le32_to_cpu(bmp->header.data_offset);

		if (display_width < (width + x))
			c_width = display_width - x;
		else
			c_width = width;
		if (display_height < (height + y))
			c_height = display_height - y;
		else
			c_height = height;

		lw = (((width + 7) / 8) + 3) & ~0x3;

		if (c_height < height)
			dataptr = dataptr + lw * (height - c_height);
		switch (bpp) {
			case 1:
				vcxk_draw_mono(dataptr, lw, c_width, c_height);
				break;
			default:
				printf("Error: %ld bit per pixel "
					"not supported by VCxK\n", bpp);
			return 0;
		}
	} else	{
		printf("Error: no valid bmp at %lx\n", (ulong) bmp);
		return 0;
	}
	return 1;
}

/*
 ****f* bus_vcxk/video_display_bitmap
 ***
 */

int video_display_bitmap(ulong addr, int x, int y)
{
	vcxk_acknowledge_wait();
	if (vcxk_display_bitmap(addr, x, y)) {
		vcxk_request();
		return 0;
	}
	return 1;
}

/* EOF */