wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /************************************************************************/ |
| 25 | /* ** DEBUG SETTINGS */ |
| 26 | /************************************************************************/ |
| 27 | |
| 28 | /* #define DEBUG */ |
| 29 | |
| 30 | /************************************************************************/ |
| 31 | /* ** HEADER FILES */ |
| 32 | /************************************************************************/ |
| 33 | |
| 34 | #include <config.h> |
| 35 | #include <common.h> |
| 36 | #include <version.h> |
| 37 | #include <stdarg.h> |
| 38 | #include <linux/types.h> |
| 39 | #include <devices.h> |
| 40 | #include <s3c2400.h> |
| 41 | |
| 42 | #ifdef CONFIG_VFD |
| 43 | |
| 44 | /************************************************************************/ |
| 45 | /* ** CONFIG STUFF -- should be moved to board config file */ |
| 46 | /************************************************************************/ |
| 47 | |
| 48 | /************************************************************************/ |
| 49 | |
| 50 | #ifndef PAGE_SIZE |
| 51 | #define PAGE_SIZE 4096 |
| 52 | #endif |
| 53 | |
| 54 | #define ROT 0x09 |
| 55 | #define BLAU 0x0C |
| 56 | #define VIOLETT 0X0D |
| 57 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 58 | /* MAGIC */ |
| 59 | #define FRAME_BUF_SIZE ((256*4*56)/8) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 60 | #define frame_buf_offs 4 |
| 61 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 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) |
| 67 | |
| 68 | /* CPLD-Register for controlling vfd-blank-signal */ |
| 69 | #define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000) |
| 70 | #define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001) |
| 71 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 72 | /* Supported VFD Types */ |
| 73 | #define VFD_TYPE_T119C 1 /* Noritake T119C VFD */ |
| 74 | #define VFD_TYPE_MN11236 2 |
| 75 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 76 | /*#define NEW_CPLD_CLK*/ |
| 77 | |
| 78 | int vfd_board_id; |
| 79 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | /* taken from armboot/common/vfd.c */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 81 | unsigned long adr_vfd_table[112][18][2][4][2]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 82 | unsigned char bit_vfd_table[112][18][2][4][2]; |
| 83 | |
| 84 | /* |
| 85 | * initialize the values for the VFD-grid-control in the framebuffer |
| 86 | */ |
| 87 | void init_grid_ctrl(void) |
| 88 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 89 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | ulong adr, grid_cycle; |
| 91 | unsigned int bit, display; |
| 92 | unsigned char temp, bit_nr; |
| 93 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 94 | /* |
| 95 | * clear frame buffer (logical clear => set to "black") |
| 96 | */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 97 | memset ((void *)(gd->fb_base), 0, FRAME_BUF_SIZE); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 98 | |
| 99 | switch (gd->vfd_type) { |
| 100 | case VFD_TYPE_T119C: |
| 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; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 107 | if (bit>=FRAME_BUF_SIZE*8) |
| 108 | bit = bit - (FRAME_BUF_SIZE * 8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 109 | adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 110 | bit_nr = bit % 8; |
| 111 | bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 113 | temp |= (1<<bit_nr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 114 | (*(volatile unsigned char*)(adr))=temp; |
| 115 | |
| 116 | if(grid_cycle<55) |
| 117 | bit = grid_cycle*256*4+(grid_cycle+201)*4+frame_buf_offs+display; |
| 118 | else |
| 119 | bit = grid_cycle*256*4+200*4+frame_buf_offs+display-4; /* grid nr. 0 */ |
| 120 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 121 | if (bit>=FRAME_BUF_SIZE*8) |
| 122 | bit = bit-(FRAME_BUF_SIZE*8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 123 | adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | bit_nr = bit%8; |
| 125 | bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; |
| 126 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 127 | temp |= (1<<bit_nr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | (*(volatile unsigned char*)(adr))=temp; |
| 129 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 130 | } |
| 131 | break; |
| 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) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 139 | if (bit>=FRAME_BUF_SIZE*8) |
| 140 | bit = bit - (FRAME_BUF_SIZE * 8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 141 | adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 142 | bit_nr = bit % 8; |
| 143 | bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; |
| 144 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 145 | temp |= (1<<bit_nr); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 146 | (*(volatile unsigned char*)(adr))=temp; |
| 147 | |
| 148 | if(grid_cycle<37) |
| 149 | bit = grid_cycle*256*4+(252-grid_cycle)*4+frame_buf_offs+display; |
| 150 | |
| 151 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 152 | if (bit>=FRAME_BUF_SIZE*8) |
| 153 | bit = bit-(FRAME_BUF_SIZE*8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 154 | adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 155 | bit_nr = bit%8; |
| 156 | bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; |
| 157 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 158 | temp |= (1<<bit_nr); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 159 | (*(volatile unsigned char*)(adr))=temp; |
| 160 | } |
| 161 | } |
| 162 | break; |
| 163 | default: |
| 164 | printf ("Warning: unknown display type\n"); |
| 165 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | *create translation table for getting easy the right position in the |
| 171 | *physical framebuffer for some x/y-coordinates of the VFDs |
| 172 | */ |
| 173 | void create_vfd_table(void) |
| 174 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 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; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 179 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 180 | switch (gd->vfd_type) { |
| 181 | case VFD_TYPE_T119C: |
| 182 | for(y=0; y<=17; y++) { /* Line */ |
| 183 | for(x=0; x<=111; x++) { /* Column */ |
| 184 | for(display=0; display <=3; display++) { |
| 185 | |
| 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; |
| 194 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 195 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 196 | } |
| 197 | break; |
| 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++) { |
| 202 | |
| 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; |
| 207 | |
| 208 | switch (x%6) { |
| 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 */ |
| 215 | } |
| 216 | |
| 217 | /* blue pixels */ |
| 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; |
| 221 | /* blue pixels */ |
| 222 | if (x>1 && (x-1)%3) |
| 223 | vfd_table[x][y][0][display][1] = x_abcdef*4+((x-1)/3+1)*1024+y*48+display; |
| 224 | |
| 225 | /* red pixels */ |
| 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; |
| 229 | /* red pixels */ |
| 230 | if (x>1 && (x-1)%3) |
| 231 | vfd_table[x][y][1][display][1] = x_abcdef*4+24+((x-1)/3+1)*1024+y*48+display; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | break; |
| 236 | default: |
| 237 | /* do nothing */ |
| 238 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 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 |
| 245 | */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 246 | for(y=0;y<18;y++) { |
| 247 | for(x=0;x<112;x++) { |
| 248 | for(color=0;color<2;color++) { |
| 249 | for(display=0;display<4;display++) { |
| 250 | for(entry=0;entry<2;entry++) { |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 251 | unsigned long adr = gd->fb_base; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 252 | unsigned int bit_nr = 0; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 253 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 254 | if (vfd_table[x][y][color][display][entry]) { |
| 255 | |
| 256 | pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs; |
| 257 | /* |
| 258 | * wrap arround if offset |
| 259 | * (see manual S3C2400) |
| 260 | */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 261 | if (pixel>=FRAME_BUF_SIZE*8) |
| 262 | pixel = pixel-(FRAME_BUF_SIZE*8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 263 | adr = gd->fb_base+(pixel/32)*4+(3-(pixel%32)/8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 264 | bit_nr = pixel%8; |
| 265 | bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; |
| 266 | } |
| 267 | adr_vfd_table[x][y][color][display][entry] = adr; |
| 268 | bit_vfd_table[x][y][color][display][entry] = bit_nr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 270 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 271 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 272 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Set/clear pixel of the VFDs |
| 278 | */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 279 | void set_vfd_pixel(unsigned char x, unsigned char y, |
| 280 | unsigned char color, unsigned char display, |
| 281 | unsigned char value) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 282 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 283 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 284 | ulong adr; |
| 285 | unsigned char bit_nr, temp; |
| 286 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 287 | if (! gd->vfd_type) { |
| 288 | /* Unknown type. */ |
| 289 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 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)); |
| 297 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 298 | if (value) |
| 299 | temp |= (1<<bit_nr); |
| 300 | else |
| 301 | temp &= ~(1<<bit_nr); |
| 302 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 303 | (*(volatile unsigned char*)(adr))=temp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* |
| 307 | * transfer image from BMP-File |
| 308 | */ |
| 309 | void transfer_pic(int display, unsigned char *adr, int height, int width) |
| 310 | { |
| 311 | int x, y; |
| 312 | unsigned char temp; |
| 313 | |
| 314 | for (; height > 0; height -= 18) |
| 315 | { |
| 316 | if (height > 18) |
| 317 | y = 18; |
| 318 | else |
| 319 | y = height; |
| 320 | for (; y > 0; y--) |
| 321 | { |
| 322 | for (x = 0; x < width; x += 2) |
| 323 | { |
| 324 | temp = *adr++; |
| 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) |
| 332 | { |
| 333 | set_vfd_pixel(x, y-1, 0, display, 1); |
| 334 | set_vfd_pixel(x, y-1, 1, display, 1); |
| 335 | } |
| 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) |
| 343 | { |
| 344 | set_vfd_pixel(x+1, y-1, 0, display, 1); |
| 345 | set_vfd_pixel(x+1, y-1, 1, display, 1); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | display++; |
| 350 | if (display > 3) |
| 351 | display = 0; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /* |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 356 | * This function initializes VFD clock that is needed for the CPLD that |
| 357 | * manages the keyboard. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 358 | */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 359 | int vfd_init_clocks (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 360 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 361 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 362 | /* try to determine display type from the value |
| 363 | * defined by pull-ups |
| 364 | */ |
| 365 | rPCUP = (rPCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */ |
| 366 | rPCCON = (rPCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */ |
| 367 | udelay (10); /* allow signals to settle */ |
| 368 | vfd_board_id = (~rPCDAT) & 0x000F; /* read GPC0...GPC3 port pins */ |
| 369 | |
| 370 | VFD_DISABLE; /* activate blank for the vfd */ |
| 371 | |
| 372 | #define NEW_CPLD_CLK |
| 373 | |
| 374 | #ifdef NEW_CPLD_CLK |
| 375 | if (vfd_board_id) { |
| 376 | /* If new board revision, then use PWM 3 as cpld-clock */ |
| 377 | /* Enable 500 Hz timer for fill level sensor to operate properly */ |
| 378 | /* Configure TOUT3 as functional pin, disable pull-up */ |
| 379 | rPDCON &= ~0x30000; |
| 380 | rPDCON |= 0x20000; |
| 381 | rPDUP |= (1 << 8); |
| 382 | |
| 383 | /* Configure the prescaler */ |
| 384 | rTCFG0 &= ~0xff00; |
| 385 | rTCFG0 |= 0x0f00; |
| 386 | |
| 387 | /* Select MUX input (divider) for timer3 (1/16) */ |
| 388 | rTCFG1 &= ~0xf000; |
| 389 | rTCFG1 |= 0x3000; |
| 390 | |
| 391 | /* Enable autoreload and set the counter and compare |
| 392 | * registers to values for the 500 Hz clock |
| 393 | * (for a given prescaler (15) and divider (16)): |
| 394 | * counter = (66000000 / 500) >> 9; |
| 395 | */ |
| 396 | rTCNTB3 = 0x101; |
| 397 | rTCMPB3 = 0x101 / 2; |
| 398 | |
| 399 | /* Start timer */ |
| 400 | rTCON = (rTCON | UPDATE3 | RELOAD3) & ~INVERT3; |
| 401 | rTCON = (rTCON | START3) & ~UPDATE3; |
| 402 | } |
| 403 | #endif |
| 404 | /* If old board revision, then use vm-signal as cpld-clock */ |
| 405 | rLCDCON2 = 0x00FFC000; |
| 406 | rLCDCON3 = 0x0007FF00; |
| 407 | rLCDCON4 = 0x00000000; |
| 408 | rLCDCON5 = 0x00000400; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 409 | rLCDCON1 = 0x00000B75; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 410 | /* VM (GPD1) is used as clock for the CPLD */ |
| 411 | rPDCON = (rPDCON & 0xFFFFFFF3) | 0x00000008; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 412 | |
| 413 | return 0; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* |
| 417 | * initialize LCD-Controller of the S3C2400 for using VFDs |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 418 | * |
| 419 | * VFD detection depends on the board revision: |
| 420 | * starting from Rev. 200 a type code can be read from the data pins, |
| 421 | * driven by some pull-up resistors; all earlier systems must be |
| 422 | * manually configured. The type is set in the "vfd_type" environment |
| 423 | * variable. |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 424 | */ |
| 425 | int drv_vfd_init(void) |
| 426 | { |
| 427 | char *tmp; |
| 428 | ulong palette; |
| 429 | static int vfd_init_done = 0; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 430 | int vfd_inv_data = 0; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 431 | |
| 432 | DECLARE_GLOBAL_DATA_PTR; |
| 433 | |
| 434 | if (vfd_init_done != 0) |
| 435 | return (0); |
| 436 | vfd_init_done = 1; |
| 437 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 438 | debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 439 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 440 | switch (vfd_board_id) { |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 441 | case 0: /* board revision < Rev.200 */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 442 | if ((tmp = getenv ("vfd_type")) == NULL) { |
| 443 | break; |
| 444 | } |
| 445 | if (strcmp(tmp, "T119C") == 0) { |
| 446 | gd->vfd_type = VFD_TYPE_T119C; |
| 447 | } else if (strcmp(tmp, "MN11236") == 0) { |
| 448 | gd->vfd_type = VFD_TYPE_MN11236; |
| 449 | } else { |
| 450 | /* cannot use printf for a warning here */ |
| 451 | gd->vfd_type = 0; /* unknown */ |
| 452 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 453 | |
| 454 | break; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 455 | default: /* default to MN11236, data inverted */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 456 | gd->vfd_type = VFD_TYPE_MN11236; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 457 | vfd_inv_data = 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 458 | setenv ("vfd_type", "MN11236"); |
| 459 | } |
| 460 | debug ("VFD type: %s%s\n", |
| 461 | (gd->vfd_type == VFD_TYPE_T119C) ? "T119C" : |
| 462 | (gd->vfd_type == VFD_TYPE_MN11236) ? "MN11236" : |
| 463 | "unknown", |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 464 | vfd_inv_data ? ", inverted data" : ""); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 465 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 466 | gd->fb_base = gd->fb_base; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 467 | create_vfd_table(); |
| 468 | init_grid_ctrl(); |
| 469 | |
| 470 | for (palette=0; palette < 16; palette++) |
| 471 | (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette; |
| 472 | for (palette=16; palette < 256; palette++) |
| 473 | (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00; |
| 474 | |
| 475 | /* |
| 476 | * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben |
| 477 | * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt |
| 478 | * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt |
| 479 | * (wrap around) |
| 480 | * see manual S3C2400 |
| 481 | */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 482 | /* Stopp LCD-Controller */ |
| 483 | rLCDCON1 = 0x00000000; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 484 | /* frame buffer startadr */ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 485 | rLCDSADDR1 = gd->fb_base >> 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 486 | /* frame buffer endadr */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 487 | rLCDSADDR2 = (gd->fb_base + FRAME_BUF_SIZE) >> 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 488 | rLCDSADDR3 = ((256/4)); |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame^] | 489 | rLCDCON2 = 0x000DC000; |
| 490 | if(gd->vfd_type == VFD_TYPE_MN11236) |
| 491 | rLCDCON2 = 37 << 14; /* MN11236: 38 lines */ |
| 492 | else |
| 493 | rLCDCON2 = 55 << 14; /* T119C: 56 lines */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 494 | rLCDCON3 = 0x0051000A; |
| 495 | rLCDCON4 = 0x00000001; |
| 496 | if (gd->vfd_type && vfd_inv_data) |
| 497 | rLCDCON5 = 0x000004C0; |
| 498 | else |
| 499 | rLCDCON5 = 0x00000440; |
| 500 | |
| 501 | /* Port pins as LCD output */ |
| 502 | rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA; |
| 503 | rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8; |
| 504 | |
| 505 | /* Synchronize VFD enable with LCD controller to avoid flicker */ |
| 506 | rLCDCON1 = 0x00000B75; /* Start LCD-Controller */ |
| 507 | while((rLCDCON5 & 0x180000)!=0x100000); /* Wait for end of VSYNC */ |
| 508 | while((rLCDCON5 & 0x060000)!=0x040000); /* Wait for next HSYNC */ |
| 509 | while((rLCDCON5 & 0x060000)==0x040000); |
| 510 | while((rLCDCON5 & 0x060000)!=0x000000); |
| 511 | if(gd->vfd_type) |
| 512 | VFD_ENABLE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 513 | |
| 514 | debug ("LCDSADDR1: %lX\n", rLCDSADDR1); |
| 515 | debug ("LCDSADDR2: %lX\n", rLCDSADDR2); |
| 516 | debug ("LCDSADDR3: %lX\n", rLCDSADDR3); |
| 517 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 518 | return 0; |
| 519 | } |
| 520 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 521 | /* |
| 522 | * Disable VFD: should be run before resetting the system: |
| 523 | * disable VM, enable pull-up |
| 524 | */ |
| 525 | void disable_vfd (void) |
| 526 | { |
| 527 | VFD_DISABLE; |
| 528 | rPDCON &= ~0xC; |
| 529 | rPDUP &= ~0x2; |
| 530 | } |
| 531 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 532 | /************************************************************************/ |
| 533 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 534 | /************************************************************************/ |
| 535 | |
| 536 | /* |
| 537 | * This is called early in the system initialization to grab memory |
| 538 | * for the VFD controller. |
| 539 | * |
| 540 | * Note that this is running from ROM, so no write access to global data. |
| 541 | */ |
| 542 | ulong vfd_setmem (ulong addr) |
| 543 | { |
| 544 | ulong size; |
| 545 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 546 | /* Round up to nearest full page */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 547 | size = (FRAME_BUF_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 548 | |
| 549 | debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr); |
| 550 | |
| 551 | return (size); |
| 552 | } |
| 553 | |
| 554 | #endif /* CONFIG_VFD */ |