]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/trab/vfd.c
f510ee55b07d169acfef2d68e370a2cc7513c376
3 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /************************************************************************/
25 /* ** DEBUG SETTINGS */
26 /************************************************************************/
30 /************************************************************************/
32 /************************************************************************/
38 #include <linux/types.h>
44 /************************************************************************/
45 /* ** CONFIG STUFF -- should be moved to board config file */
46 /************************************************************************/
48 /************************************************************************/
51 #define PAGE_SIZE 4096
59 #define FRAME_BUF_SIZE ((256*4*56)/8)
60 #define frame_buf_offs 4
62 /* defines for starting Timer3 as CPLD-Clk */
63 #define START3 (1 << 16)
64 #define UPDATE3 (1 << 17)
65 #define INVERT3 (1 << 18)
66 #define RELOAD3 (1 << 19)
68 /* CPLD-Register for controlling vfd-blank-signal */
69 #define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000)
70 #define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001)
72 /* Supported VFD Types */
73 #define VFD_TYPE_T119C 1 /* Noritake T119C VFD */
74 #define VFD_TYPE_MN11236 2
76 /*#define NEW_CPLD_CLK*/
80 /* taken from armboot/common/vfd.c */
81 unsigned long adr_vfd_table
[112][18][2][4][2];
82 unsigned char bit_vfd_table
[112][18][2][4][2];
85 * initialize the values for the VFD-grid-control in the framebuffer
87 void init_grid_ctrl(void)
89 DECLARE_GLOBAL_DATA_PTR
;
90 ulong adr
, grid_cycle
;
91 unsigned int bit
, display
;
92 unsigned char temp
, bit_nr
;
95 * clear frame buffer (logical clear => set to "black")
97 memset ((void *)(gd
->fb_base
), 0, FRAME_BUF_SIZE
);
99 switch (gd
->vfd_type
) {
101 for (display
=0; display
<4; display
++) {
102 for(grid_cycle
=0; grid_cycle
<56; grid_cycle
++) {
103 bit
= grid_cycle
* 256 * 4 +
104 (grid_cycle
+ 200) * 4 +
105 frame_buf_offs
+ display
;
106 /* wrap arround if offset (see manual S3C2400) */
107 if (bit
>=FRAME_BUF_SIZE
*8)
108 bit
= bit
- (FRAME_BUF_SIZE
* 8);
109 adr
= gd
->fb_base
+ (bit
/32) * 4 + (3 - (bit
%32) / 8);
111 bit_nr
= (bit_nr
> 3) ? bit_nr
-4 : bit_nr
+4;
112 temp
=(*(volatile unsigned char*)(adr
));
114 (*(volatile unsigned char*)(adr
))=temp
;
117 bit
= grid_cycle
*256*4+(grid_cycle
+201)*4+frame_buf_offs
+display
;
119 bit
= grid_cycle
*256*4+200*4+frame_buf_offs
+display
-4; /* grid nr. 0 */
120 /* wrap arround if offset (see manual S3C2400) */
121 if (bit
>=FRAME_BUF_SIZE
*8)
122 bit
= bit
-(FRAME_BUF_SIZE
*8);
123 adr
= gd
->fb_base
+(bit
/32)*4+(3-(bit
%32)/8);
125 bit_nr
= (bit_nr
>3)?bit_nr
-4:bit_nr
+4;
126 temp
=(*(volatile unsigned char*)(adr
));
128 (*(volatile unsigned char*)(adr
))=temp
;
132 case VFD_TYPE_MN11236
:
133 for (display
=0; display
<4; display
++) {
134 for (grid_cycle
=0; grid_cycle
<38; grid_cycle
++) {
135 bit
= grid_cycle
* 256 * 4 +
136 (253 - grid_cycle
) * 4 +
137 frame_buf_offs
+ display
;
138 /* wrap arround if offset (see manual S3C2400) */
139 if (bit
>=FRAME_BUF_SIZE
*8)
140 bit
= bit
- (FRAME_BUF_SIZE
* 8);
141 adr
= gd
->fb_base
+ (bit
/32) * 4 + (3 - (bit
%32) / 8);
143 bit_nr
= (bit_nr
> 3) ? bit_nr
-4 : bit_nr
+4;
144 temp
=(*(volatile unsigned char*)(adr
));
146 (*(volatile unsigned char*)(adr
))=temp
;
149 bit
= grid_cycle
*256*4+(252-grid_cycle
)*4+frame_buf_offs
+display
;
151 /* wrap arround if offset (see manual S3C2400) */
152 if (bit
>=FRAME_BUF_SIZE
*8)
153 bit
= bit
-(FRAME_BUF_SIZE
*8);
154 adr
= gd
->fb_base
+(bit
/32)*4+(3-(bit
%32)/8);
156 bit_nr
= (bit_nr
>3)?bit_nr
-4:bit_nr
+4;
157 temp
=(*(volatile unsigned char*)(adr
));
159 (*(volatile unsigned char*)(adr
))=temp
;
164 printf ("Warning: unknown display type\n");
170 *create translation table for getting easy the right position in the
171 *physical framebuffer for some x/y-coordinates of the VFDs
173 void create_vfd_table(void)
175 DECLARE_GLOBAL_DATA_PTR
;
176 unsigned long vfd_table
[112][18][2][4][2];
177 unsigned int x
, y
, color
, display
, entry
, pixel
;
178 unsigned int x_abcdef
= 0;
180 switch (gd
->vfd_type
) {
182 for(y
=0; y
<=17; y
++) { /* Line */
183 for(x
=0; x
<=111; x
++) { /* Column */
184 for(display
=0; display
<=3; display
++) {
186 /* Display 0 blue pixels */
187 vfd_table
[x
][y
][0][display
][0] =
188 (x
==0) ? y
*16+display
189 : (x
%4)*4+y
*16+((x
-1)/2)*1024+display
;
190 /* Display 0 red pixels */
191 vfd_table
[x
][y
][1][display
][0] =
192 (x
==0) ? y
*16+512+display
193 : (x
%4)*4+y
*16+((x
-1)/2)*1024+512+display
;
198 case VFD_TYPE_MN11236
:
199 for(y
=0; y
<=17; y
++) { /* Line */
200 for(x
=0; x
<=111; x
++) { /* Column */
201 for(display
=0; display
<=3; display
++) {
203 vfd_table
[x
][y
][0][display
][0]=0;
204 vfd_table
[x
][y
][0][display
][1]=0;
205 vfd_table
[x
][y
][1][display
][0]=0;
206 vfd_table
[x
][y
][1][display
][1]=0;
209 case 0: x_abcdef
=0; break; /* a -> a */
210 case 1: x_abcdef
=2; break; /* b -> c */
211 case 2: x_abcdef
=4; break; /* c -> e */
212 case 3: x_abcdef
=5; break; /* d -> f */
213 case 4: x_abcdef
=3; break; /* e -> d */
214 case 5: x_abcdef
=1; break; /* f -> b */
218 vfd_table
[x
][y
][0][display
][0] =
219 (x
>1) ? x_abcdef
*4+((x
-1)/3)*1024+y
*48+display
220 : x_abcdef
*4+ 0+y
*48+display
;
223 vfd_table
[x
][y
][0][display
][1] = x_abcdef
*4+((x
-1)/3+1)*1024+y
*48+display
;
226 vfd_table
[x
][y
][1][display
][0] =
227 (x
>1) ? x_abcdef
*4+24+((x
-1)/3)*1024+y
*48+display
228 : x_abcdef
*4+24+ 0+y
*48+display
;
231 vfd_table
[x
][y
][1][display
][1] = x_abcdef
*4+24+((x
-1)/3+1)*1024+y
*48+display
;
242 * Create table with entries for physical byte adresses and
243 * bit-number within the byte
244 * from table with bit-numbers within the total framebuffer
248 for(color
=0;color
<2;color
++) {
249 for(display
=0;display
<4;display
++) {
250 for(entry
=0;entry
<2;entry
++) {
251 unsigned long adr
= gd
->fb_base
;
252 unsigned int bit_nr
= 0;
254 if (vfd_table
[x
][y
][color
][display
][entry
]) {
256 pixel
= vfd_table
[x
][y
][color
][display
][entry
] + frame_buf_offs
;
258 * wrap arround if offset
259 * (see manual S3C2400)
261 if (pixel
>=FRAME_BUF_SIZE
*8)
262 pixel
= pixel
-(FRAME_BUF_SIZE
*8);
263 adr
= gd
->fb_base
+(pixel
/32)*4+(3-(pixel
%32)/8);
265 bit_nr
= (bit_nr
>3)?bit_nr
-4:bit_nr
+4;
267 adr_vfd_table
[x
][y
][color
][display
][entry
] = adr
;
268 bit_vfd_table
[x
][y
][color
][display
][entry
] = bit_nr
;
277 * Set/clear pixel of the VFDs
279 void set_vfd_pixel(unsigned char x
, unsigned char y
,
280 unsigned char color
, unsigned char display
,
283 DECLARE_GLOBAL_DATA_PTR
;
285 unsigned char bit_nr
, temp
;
287 if (! gd
->vfd_type
) {
292 /* Pixel-Eintrag Nr. 1 */
293 adr
= adr_vfd_table
[x
][y
][color
][display
][0];
294 /* Pixel-Eintrag Nr. 1 */
295 bit_nr
= bit_vfd_table
[x
][y
][color
][display
][0];
296 temp
=(*(volatile unsigned char*)(adr
));
301 temp
&= ~(1<<bit_nr
);
303 (*(volatile unsigned char*)(adr
))=temp
;
307 * transfer image from BMP-File
309 void transfer_pic(int display
, unsigned char *adr
, int height
, int width
)
314 for (; height
> 0; height
-= 18)
322 for (x
= 0; x
< width
; x
+= 2)
325 set_vfd_pixel(x
, y
-1, 0, display
, 0);
326 set_vfd_pixel(x
, y
-1, 1, display
, 0);
327 if ((temp
>> 4) == BLAU
)
328 set_vfd_pixel(x
, y
-1, 0, display
, 1);
329 else if ((temp
>> 4) == ROT
)
330 set_vfd_pixel(x
, y
-1, 1, display
, 1);
331 else if ((temp
>> 4) == VIOLETT
)
333 set_vfd_pixel(x
, y
-1, 0, display
, 1);
334 set_vfd_pixel(x
, y
-1, 1, display
, 1);
336 set_vfd_pixel(x
+1, y
-1, 0, display
, 0);
337 set_vfd_pixel(x
+1, y
-1, 1, display
, 0);
338 if ((temp
& 0x0F) == BLAU
)
339 set_vfd_pixel(x
+1, y
-1, 0, display
, 1);
340 else if ((temp
& 0x0F) == ROT
)
341 set_vfd_pixel(x
+1, y
-1, 1, display
, 1);
342 else if ((temp
& 0x0F) == VIOLETT
)
344 set_vfd_pixel(x
+1, y
-1, 0, display
, 1);
345 set_vfd_pixel(x
+1, y
-1, 1, display
, 1);
357 * This function initializes VFD clock that is needed for the CPLD that
358 * manages the keyboard.
360 int vfd_init_clocks (void)
362 S3C24X0_GPIO
* const gpio
= S3C24X0_GetBase_GPIO();
363 S3C24X0_TIMERS
* const timers
= S3C24X0_GetBase_TIMERS();
364 S3C24X0_LCD
* const lcd
= S3C24X0_GetBase_LCD();
366 /* try to determine display type from the value
367 * defined by pull-ups
369 gpio
->PCUP
= (gpio
->PCUP
& 0xFFF0); /* activate GPC0...GPC3 pullups */
370 gpio
->PCCON
= (gpio
->PCCON
& 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */
371 udelay (10); /* allow signals to settle */
372 vfd_board_id
= (~gpio
->PCDAT
) & 0x000F; /* read GPC0...GPC3 port pins */
374 VFD_DISABLE
; /* activate blank for the vfd */
380 /* If new board revision, then use PWM 3 as cpld-clock */
381 /* Enable 500 Hz timer for fill level sensor to operate properly */
382 /* Configure TOUT3 as functional pin, disable pull-up */
383 gpio
->PDCON
&= ~0x30000;
384 gpio
->PDCON
|= 0x20000;
385 gpio
->PDUP
|= (1 << 8);
387 /* Configure the prescaler */
388 timers
->TCFG0
&= ~0xff00;
389 timers
->TCFG0
|= 0x0f00;
391 /* Select MUX input (divider) for timer3 (1/16) */
392 timers
->TCFG1
&= ~0xf000;
393 timers
->TCFG1
|= 0x3000;
395 /* Enable autoreload and set the counter and compare
396 * registers to values for the 500 Hz clock
397 * (for a given prescaler (15) and divider (16)):
398 * counter = (66000000 / 500) >> 9;
400 timers
->ch
[3].TCNTB
= 0x101;
401 timers
->ch
[3].TCMPB
= 0x101 / 2;
404 timers
->TCON
= (timers
->TCON
| UPDATE3
| RELOAD3
) & ~INVERT3
;
405 timers
->TCON
= (timers
->TCON
| START3
) & ~UPDATE3
;
408 /* If old board revision, then use vm-signal as cpld-clock */
409 lcd
->LCDCON2
= 0x00FFC000;
410 lcd
->LCDCON3
= 0x0007FF00;
411 lcd
->LCDCON4
= 0x00000000;
412 lcd
->LCDCON5
= 0x00000400;
413 lcd
->LCDCON1
= 0x00000B75;
414 /* VM (GPD1) is used as clock for the CPLD */
415 gpio
->PDCON
= (gpio
->PDCON
& 0xFFFFFFF3) | 0x00000008;
421 * initialize LCD-Controller of the S3C2400 for using VFDs
423 * VFD detection depends on the board revision:
424 * starting from Rev. 200 a type code can be read from the data pins,
425 * driven by some pull-up resistors; all earlier systems must be
426 * manually configured. The type is set in the "vfd_type" environment
429 int drv_vfd_init(void)
431 S3C24X0_LCD
* const lcd
= S3C24X0_GetBase_LCD();
432 S3C24X0_GPIO
* const gpio
= S3C24X0_GetBase_GPIO();
435 static int vfd_init_done
= 0;
436 int vfd_inv_data
= 0;
438 DECLARE_GLOBAL_DATA_PTR
;
440 if (vfd_init_done
!= 0)
444 debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id
);
446 switch (vfd_board_id
) {
447 case 0: /* board revision < Rev.200 */
448 if ((tmp
= getenv ("vfd_type")) == NULL
) {
451 if (strcmp(tmp
, "T119C") == 0) {
452 gd
->vfd_type
= VFD_TYPE_T119C
;
453 } else if (strcmp(tmp
, "MN11236") == 0) {
454 gd
->vfd_type
= VFD_TYPE_MN11236
;
456 /* cannot use printf for a warning here */
457 gd
->vfd_type
= 0; /* unknown */
461 default: /* default to MN11236, data inverted */
462 gd
->vfd_type
= VFD_TYPE_MN11236
;
464 setenv ("vfd_type", "MN11236");
466 debug ("VFD type: %s%s\n",
467 (gd
->vfd_type
== VFD_TYPE_T119C
) ? "T119C" :
468 (gd
->vfd_type
== VFD_TYPE_MN11236
) ? "MN11236" :
470 vfd_inv_data
? ", inverted data" : "");
472 gd
->fb_base
= gd
->fb_base
;
476 for (palette
=0; palette
< 16; palette
++)
477 (*(volatile unsigned int*)(PALETTE
+(palette
*4)))=palette
;
478 for (palette
=16; palette
< 256; palette
++)
479 (*(volatile unsigned int*)(PALETTE
+(palette
*4)))=0x00;
482 * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben
483 * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt
484 * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt
488 /* Stopp LCD-Controller */
489 lcd
->LCDCON1
= 0x00000000;
490 /* frame buffer startadr */
491 lcd
->LCDSADDR1
= gd
->fb_base
>> 1;
492 /* frame buffer endadr */
493 lcd
->LCDSADDR2
= (gd
->fb_base
+ FRAME_BUF_SIZE
) >> 1;
494 lcd
->LCDSADDR3
= ((256/4));
495 lcd
->LCDCON2
= 0x000DC000;
496 if(gd
->vfd_type
== VFD_TYPE_MN11236
)
497 lcd
->LCDCON2
= 37 << 14; /* MN11236: 38 lines */
499 lcd
->LCDCON2
= 55 << 14; /* T119C: 56 lines */
500 lcd
->LCDCON3
= 0x0051000A;
501 lcd
->LCDCON4
= 0x00000001;
502 if (gd
->vfd_type
&& vfd_inv_data
)
503 lcd
->LCDCON5
= 0x000004C0;
505 lcd
->LCDCON5
= 0x00000440;
507 /* Port pins as LCD output */
508 gpio
->PCCON
= (gpio
->PCCON
& 0xFFFFFF00)| 0x000000AA;
509 gpio
->PDCON
= (gpio
->PDCON
& 0xFFFFFF03)| 0x000000A8;
511 /* Synchronize VFD enable with LCD controller to avoid flicker */
512 lcd
->LCDCON1
= 0x00000B75; /* Start LCD-Controller */
513 while((lcd
->LCDCON5
& 0x180000)!=0x100000); /* Wait for end of VSYNC */
514 while((lcd
->LCDCON5
& 0x060000)!=0x040000); /* Wait for next HSYNC */
515 while((lcd
->LCDCON5
& 0x060000)==0x040000);
516 while((lcd
->LCDCON5
& 0x060000)!=0x000000);
520 debug ("LCDSADDR1: %lX\n", lcd
->LCDSADDR1
);
521 debug ("LCDSADDR2: %lX\n", lcd
->LCDSADDR2
);
522 debug ("LCDSADDR3: %lX\n", lcd
->LCDSADDR3
);
528 * Disable VFD: should be run before resetting the system:
529 * disable VM, enable pull-up
531 void disable_vfd (void)
533 S3C24X0_GPIO
* const gpio
= S3C24X0_GetBase_GPIO();
540 /************************************************************************/
541 /* ** ROM capable initialization part - needed to reserve FB memory */
542 /************************************************************************/
545 * This is called early in the system initialization to grab memory
546 * for the VFD controller.
548 * Note that this is running from ROM, so no write access to global data.
550 ulong
vfd_setmem (ulong addr
)
554 /* Round up to nearest full page */
555 size
= (FRAME_BUF_SIZE
+ (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
557 debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size
>>10, addr
);
563 * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
564 * descriptors and palette areas.
566 ulong
calc_fbsize (void)
568 return FRAME_BUF_SIZE
;
571 #endif /* CONFIG_VFD */