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
60 #define frame_buf_offs 4
62 /* taken from armboot/common/vfd.c */
63 ulong adr_vfd_table[112][18][2][4][2];
64 unsigned char bit_vfd_table[112][18][2][4][2];
67 * initialize the values for the VFD-grid-control in the framebuffer
69 void init_grid_ctrl(void)
71 ulong adr, grid_cycle;
72 unsigned int bit, display;
73 unsigned char temp, bit_nr;
75 for (adr=vfdbase; adr<=(vfdbase+7168); adr+=4) /*clear frame buffer */
76 (*(volatile ulong*)(adr))=0;
78 for(display=0;display<=3;display++)
80 for(grid_cycle=0;grid_cycle<=55;grid_cycle++)
82 bit = grid_cycle*256*4+(grid_cycle+200)*4+frame_buf_offs+display;
83 /* wrap arround if offset (see manual S3C2400) */
84 if (bit>=frame_buf_size*8)
85 bit = bit-(frame_buf_size*8);
86 adr = vfdbase+(bit/32)*4+(3-(bit%32)/8);
88 bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
89 temp=(*(volatile unsigned char*)(adr));
91 (*(volatile unsigned char*)(adr))=temp;
94 bit = grid_cycle*256*4+(grid_cycle+201)*4+frame_buf_offs+display;
96 bit = grid_cycle*256*4+200*4+frame_buf_offs+display-4; /* grid nr. 0 */
97 /* wrap arround if offset (see manual S3C2400) */
98 if (bit>=frame_buf_size*8)
99 bit = bit-(frame_buf_size*8);
100 adr = vfdbase+(bit/32)*4+(3-(bit%32)/8);
102 bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
103 temp=(*(volatile unsigned char*)(adr));
105 (*(volatile unsigned char*)(adr))=temp;
111 *create translation table for getting easy the right position in the
112 *physical framebuffer for some x/y-coordinates of the VFDs
114 void create_vfd_table(void)
116 unsigned int vfd_table[112][18][2][4][2];
118 unsigned int x, y, color, display, entry, pixel, bit_nr;
121 * Create translation table for Noritake-T119C-VFD-specific
122 * organized frame-buffer.
123 * Created is the number of the bit in the framebuffer (the
124 * first transferred pixel of each frame is bit 0).
126 for(y=0;y<=17;y++) /* Zeile */
128 for(x=0;x<=111;x++) /* Spalten */
130 /*Display 0 blaue Pixel Eintrag 1 */
131 vfd_table[x][y][0][0][0]=((x%4)*4+y*16+(x/4)*2048);
132 /*Display 0 rote Pixel Eintrag 1 */
133 vfd_table[x][y][1][0][0]=((x%4)*4+y*16+(x/4)*2048+512);
136 /*Display 0 blaue Pixel Eintrag 2 */
137 vfd_table[x][y][0][0][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+1024);
138 /*Display 0 rote Pixel Eintrag 2 */
139 vfd_table[x][y][1][0][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+512+1024);
143 /*Display 0 blaue Pixel Eintrag 2 */
144 vfd_table[x][y][0][0][1]=((x%4)*4+y*16+((x-2)/4)*2048+1024);
145 /*Display 0 rote Pixel Eintrag 2 */
146 vfd_table[x][y][1][0][1]=((x%4)*4+y*16+((x-2)/4)*2048+512+1024);
148 /*Display 1 blaue Pixel Eintrag 1 */
149 vfd_table[x][y][0][1][0]=((x%4)*4+y*16+(x/4)*2048+1);
150 /*Display 1 rote Pixel Eintrag 1 */
151 vfd_table[x][y][1][1][0]=((x%4)*4+y*16+(x/4)*2048+512+1);
154 /*Display 1 blaue Pixel Eintrag 2 */
155 vfd_table[x][y][0][1][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+1+1024);
156 /*Display 1 rote Pixel Eintrag 2 */
157 vfd_table[x][y][1][1][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+512+1+1024);
161 /*Display 1 blaue Pixel Eintrag 2 */
162 vfd_table[x][y][0][1][1]=((x%4)*4+y*16+((x-2)/4)*2048+1+1024);
163 /*Display 1 rote Pixel Eintrag 2 */
164 vfd_table[x][y][1][1][1]=((x%4)*4+y*16+((x-2)/4)*2048+512+1+1024);
166 /*Display 2 blaue Pixel Eintrag 1 */
167 vfd_table[x][y][0][2][0]=((x%4)*4+y*16+(x/4)*2048+2);
168 /*Display 2 rote Pixel Eintrag 1 */
169 vfd_table[x][y][1][2][0]=((x%4)*4+y*16+(x/4)*2048+512+2);
172 /*Display 2 blaue Pixel Eintrag 2 */
173 vfd_table[x][y][0][2][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+2+1024);
174 /*Display 2 rote Pixel Eintrag 2 */
175 vfd_table[x][y][1][2][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+512+2+1024);
179 /*Display 2 blaue Pixel Eintrag 2 */
180 vfd_table[x][y][0][2][1]=((x%4)*4+y*16+((x-2)/4)*2048+2+1024);
181 /*Display 2 rote Pixel Eintrag 2 */
182 vfd_table[x][y][1][2][1]=((x%4)*4+y*16+((x-2)/4)*2048+512+2+1024);
184 /*Display 3 blaue Pixel Eintrag 1 */
185 vfd_table[x][y][0][3][0]=((x%4)*4+y*16+(x/4)*2048+3);
186 /*Display 3 rote Pixel Eintrag 1 */
187 vfd_table[x][y][1][3][0]=((x%4)*4+y*16+(x/4)*2048+512+3);
190 /*Display 3 blaue Pixel Eintrag 2 */
191 vfd_table[x][y][0][3][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+3+1024);
192 /*Display 3 rote Pixel Eintrag 2 */
193 vfd_table[x][y][1][3][1]=(((x+112)%4)*4+y*16+((x+110)/4)*2048+512+3+1024);
197 /*Display 3 blaue Pixel Eintrag 2 */
198 vfd_table[x][y][0][3][1]=((x%4)*4+y*16+((x-2)/4)*2048+3+1024);
199 /*Display 3 rote Pixel Eintrag 2 */
200 vfd_table[x][y][1][3][1]=((x%4)*4+y*16+((x-2)/4)*2048+512+3+1024);
206 * Create translation table for Noritake-T119C-VFD-specific
207 * organized frame-buffer
208 * Create table with entries for physical byte adresses and
209 * bit-number within the byte
210 * from table with bit-numbers within the total framebuffer
216 for(color=0;color<=1;color++)
218 for(display=0;display<=3;display++)
220 for(entry=0;entry<=1;entry++)
222 pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs;
224 * wrap arround if offset
225 * (see manual S3C2400)
227 if (pixel>=frame_buf_size*8)
228 pixel = pixel-(frame_buf_size*8);
229 adr = vfdbase+(pixel/32)*4+(3-(pixel%32)/8);
231 bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
232 adr_vfd_table[x][y][color][display][entry] = adr;
233 bit_vfd_table[x][y][color][display][entry] = bit_nr;
242 * Set/clear pixel of the VFDs
244 void set_vfd_pixel(unsigned char x, unsigned char y, unsigned char color, unsigned char display, unsigned char value)
247 unsigned char bit_nr, temp;
251 /* Pixel-Eintrag Nr. 1 */
252 adr = adr_vfd_table[x][y][color][display][0];
253 /* Pixel-Eintrag Nr. 1 */
254 bit_nr = bit_vfd_table[x][y][color][display][0];
255 temp=(*(volatile unsigned char*)(adr));
257 (*(volatile unsigned char*)(adr))=temp;
259 /* Pixel-Eintrag Nr. 2 */
260 adr = adr_vfd_table[x][y][color][display][1];
261 /* Pixel-Eintrag Nr. 2 */
262 bit_nr = bit_vfd_table[x][y][color][display][1];
263 temp=(*(volatile unsigned char*)(adr));
265 (*(volatile unsigned char*)(adr))=temp;
269 /* Pixel-Eintrag Nr. 1 */
270 adr = adr_vfd_table[x][y][color][display][0];
271 /* Pixel-Eintrag Nr. 1 */
272 bit_nr = bit_vfd_table[x][y][color][display][0];
273 temp=(*(volatile unsigned char*)(adr));
275 (*(volatile unsigned char*)(adr))=temp;
277 /* Pixel-Eintrag Nr. 2 */
278 adr = adr_vfd_table[x][y][color][display][1];
279 /* Pixel-Eintrag Nr. 2 */
280 bit_nr = bit_vfd_table[x][y][color][display][1];
281 temp=(*(volatile unsigned char*)(adr));
283 (*(volatile unsigned char*)(adr))=temp;
288 * transfer image from BMP-File
290 void transfer_pic(int display, unsigned char *adr, int height, int width)
295 for (; height > 0; height -= 18)
303 for (x = 0; x < width; x += 2)
306 set_vfd_pixel(x, y-1, 0, display, 0);
307 set_vfd_pixel(x, y-1, 1, display, 0);
308 if ((temp >> 4) == BLAU)
309 set_vfd_pixel(x, y-1, 0, display, 1);
310 else if ((temp >> 4) == ROT)
311 set_vfd_pixel(x, y-1, 1, display, 1);
312 else if ((temp >> 4) == VIOLETT)
314 set_vfd_pixel(x, y-1, 0, display, 1);
315 set_vfd_pixel(x, y-1, 1, display, 1);
317 set_vfd_pixel(x+1, y-1, 0, display, 0);
318 set_vfd_pixel(x+1, y-1, 1, display, 0);
319 if ((temp & 0x0F) == BLAU)
320 set_vfd_pixel(x+1, y-1, 0, display, 1);
321 else if ((temp & 0x0F) == ROT)
322 set_vfd_pixel(x+1, y-1, 1, display, 1);
323 else if ((temp & 0x0F) == VIOLETT)
325 set_vfd_pixel(x+1, y-1, 0, display, 1);
326 set_vfd_pixel(x+1, y-1, 1, display, 1);
337 * initialize LCD-Controller of the S3C2400 for using VFDs
339 int drv_vfd_init(void)
342 static int vfd_init_done = 0;
344 DECLARE_GLOBAL_DATA_PTR;
346 if (vfd_init_done != 0)
350 vfdbase = gd->fb_base;
355 * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben
356 * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt
357 * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt
361 /* frame buffer startadr */
362 rLCDSADDR1 = vfdbase >> 1;
363 /* frame buffer endadr */
364 rLCDSADDR2 = (vfdbase + frame_buf_size) >> 1;
365 rLCDSADDR3 = ((256/4));
367 /* Port-Pins als LCD-Ausgang */
368 rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA;
369 /* Port-Pins als LCD-Ausgang */
370 rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8;
372 /* mit VFRAME zum Messen */
373 rPDCON = (rPDCON & 0xFFFFFF00)| 0x000000AA;
376 rLCDCON2 = 0x000DC000;
377 rLCDCON3 = 0x0051000A;
378 rLCDCON4 = 0x00000001;
379 rLCDCON5 = 0x00000440;
380 rLCDCON1 = 0x00000B75;
382 debug ("LCDSADDR1: %lX\n", rLCDSADDR1);
383 debug ("LCDSADDR2: %lX\n", rLCDSADDR2);
384 debug ("LCDSADDR3: %lX\n", rLCDSADDR3);
386 for(palette=0;palette<=15;palette++)
387 (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette;
388 for(palette=16;palette<=255;palette++)
389 (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00;
394 /************************************************************************/
395 /* ** ROM capable initialization part - needed to reserve FB memory */
396 /************************************************************************/
399 * This is called early in the system initialization to grab memory
400 * for the VFD controller.
402 * Note that this is running from ROM, so no write access to global data.
404 ulong vfd_setmem (ulong addr)
409 frame_buf_size = (256*4*56)/8;
411 /* Round up to nearest full page */
412 size = (frame_buf_size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
414 debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr);
419 #endif /* CONFIG_VFD */