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 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_VFD |
| 45 | |
| 46 | /************************************************************************/ |
| 47 | /* ** CONFIG STUFF -- should be moved to board config file */ |
| 48 | /************************************************************************/ |
| 49 | |
| 50 | /************************************************************************/ |
| 51 | |
| 52 | #ifndef PAGE_SIZE |
| 53 | #define PAGE_SIZE 4096 |
| 54 | #endif |
| 55 | |
| 56 | #define ROT 0x09 |
| 57 | #define BLAU 0x0C |
| 58 | #define VIOLETT 0X0D |
| 59 | |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 60 | /* MAGIC */ |
| 61 | #define FRAME_BUF_SIZE ((256*4*56)/8) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | #define frame_buf_offs 4 |
| 63 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 64 | /* defines for starting Timer3 as CPLD-Clk */ |
| 65 | #define START3 (1 << 16) |
| 66 | #define UPDATE3 (1 << 17) |
| 67 | #define INVERT3 (1 << 18) |
| 68 | #define RELOAD3 (1 << 19) |
| 69 | |
| 70 | /* CPLD-Register for controlling vfd-blank-signal */ |
| 71 | #define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000) |
| 72 | #define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001) |
| 73 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 74 | /* Supported VFD Types */ |
| 75 | #define VFD_TYPE_T119C 1 /* Noritake T119C VFD */ |
| 76 | #define VFD_TYPE_MN11236 2 |
| 77 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 78 | /*#define NEW_CPLD_CLK*/ |
| 79 | |
| 80 | int vfd_board_id; |
| 81 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 82 | /* taken from armboot/common/vfd.c */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 83 | unsigned long adr_vfd_table[112][18][2][4][2]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | unsigned char bit_vfd_table[112][18][2][4][2]; |
| 85 | |
| 86 | /* |
| 87 | * initialize the values for the VFD-grid-control in the framebuffer |
| 88 | */ |
| 89 | void init_grid_ctrl(void) |
| 90 | { |
| 91 | ulong adr, grid_cycle; |
| 92 | unsigned int bit, display; |
| 93 | unsigned char temp, bit_nr; |
| 94 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 95 | /* |
| 96 | * clear frame buffer (logical clear => set to "black") |
| 97 | */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 98 | memset ((void *)(gd->fb_base), 0, FRAME_BUF_SIZE); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 99 | |
| 100 | switch (gd->vfd_type) { |
| 101 | case VFD_TYPE_T119C: |
| 102 | for (display=0; display<4; display++) { |
| 103 | for(grid_cycle=0; grid_cycle<56; grid_cycle++) { |
| 104 | bit = grid_cycle * 256 * 4 + |
| 105 | (grid_cycle + 200) * 4 + |
| 106 | frame_buf_offs + display; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 108 | if (bit>=FRAME_BUF_SIZE*8) |
| 109 | bit = bit - (FRAME_BUF_SIZE * 8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 110 | adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 111 | bit_nr = bit % 8; |
| 112 | bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 113 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 114 | temp |= (1<<bit_nr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 115 | (*(volatile unsigned char*)(adr))=temp; |
| 116 | |
| 117 | if(grid_cycle<55) |
| 118 | bit = grid_cycle*256*4+(grid_cycle+201)*4+frame_buf_offs+display; |
| 119 | else |
| 120 | bit = grid_cycle*256*4+200*4+frame_buf_offs+display-4; /* grid nr. 0 */ |
| 121 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 122 | if (bit>=FRAME_BUF_SIZE*8) |
| 123 | bit = bit-(FRAME_BUF_SIZE*8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 124 | adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 125 | bit_nr = bit%8; |
| 126 | bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; |
| 127 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 128 | temp |= (1<<bit_nr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 129 | (*(volatile unsigned char*)(adr))=temp; |
| 130 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 131 | } |
| 132 | break; |
| 133 | case VFD_TYPE_MN11236: |
| 134 | for (display=0; display<4; display++) { |
| 135 | for (grid_cycle=0; grid_cycle<38; grid_cycle++) { |
| 136 | bit = grid_cycle * 256 * 4 + |
| 137 | (253 - grid_cycle) * 4 + |
| 138 | frame_buf_offs + display; |
| 139 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 140 | if (bit>=FRAME_BUF_SIZE*8) |
| 141 | bit = bit - (FRAME_BUF_SIZE * 8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 142 | adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 143 | bit_nr = bit % 8; |
| 144 | bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; |
| 145 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 146 | temp |= (1<<bit_nr); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 147 | (*(volatile unsigned char*)(adr))=temp; |
| 148 | |
| 149 | if(grid_cycle<37) |
| 150 | bit = grid_cycle*256*4+(252-grid_cycle)*4+frame_buf_offs+display; |
| 151 | |
| 152 | /* wrap arround if offset (see manual S3C2400) */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 153 | if (bit>=FRAME_BUF_SIZE*8) |
| 154 | bit = bit-(FRAME_BUF_SIZE*8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 155 | adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 156 | bit_nr = bit%8; |
| 157 | bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; |
| 158 | temp=(*(volatile unsigned char*)(adr)); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 159 | temp |= (1<<bit_nr); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 160 | (*(volatile unsigned char*)(adr))=temp; |
| 161 | } |
| 162 | } |
| 163 | break; |
| 164 | default: |
| 165 | printf ("Warning: unknown display type\n"); |
| 166 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | *create translation table for getting easy the right position in the |
| 172 | *physical framebuffer for some x/y-coordinates of the VFDs |
| 173 | */ |
| 174 | void create_vfd_table(void) |
| 175 | { |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 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 | { |
| 283 | ulong adr; |
| 284 | unsigned char bit_nr, temp; |
| 285 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 286 | if (! gd->vfd_type) { |
| 287 | /* Unknown type. */ |
| 288 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 289 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 291 | /* Pixel-Eintrag Nr. 1 */ |
| 292 | adr = adr_vfd_table[x][y][color][display][0]; |
| 293 | /* Pixel-Eintrag Nr. 1 */ |
| 294 | bit_nr = bit_vfd_table[x][y][color][display][0]; |
| 295 | temp=(*(volatile unsigned char*)(adr)); |
| 296 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 297 | if (value) |
| 298 | temp |= (1<<bit_nr); |
| 299 | else |
| 300 | temp &= ~(1<<bit_nr); |
| 301 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 302 | (*(volatile unsigned char*)(adr))=temp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* |
| 306 | * transfer image from BMP-File |
| 307 | */ |
| 308 | void transfer_pic(int display, unsigned char *adr, int height, int width) |
| 309 | { |
| 310 | int x, y; |
| 311 | unsigned char temp; |
| 312 | |
| 313 | for (; height > 0; height -= 18) |
| 314 | { |
| 315 | if (height > 18) |
| 316 | y = 18; |
| 317 | else |
| 318 | y = height; |
| 319 | for (; y > 0; y--) |
| 320 | { |
| 321 | for (x = 0; x < width; x += 2) |
| 322 | { |
| 323 | temp = *adr++; |
| 324 | set_vfd_pixel(x, y-1, 0, display, 0); |
| 325 | set_vfd_pixel(x, y-1, 1, display, 0); |
| 326 | if ((temp >> 4) == BLAU) |
| 327 | set_vfd_pixel(x, y-1, 0, display, 1); |
| 328 | else if ((temp >> 4) == ROT) |
| 329 | set_vfd_pixel(x, y-1, 1, display, 1); |
| 330 | else if ((temp >> 4) == VIOLETT) |
| 331 | { |
| 332 | set_vfd_pixel(x, y-1, 0, display, 1); |
| 333 | set_vfd_pixel(x, y-1, 1, display, 1); |
| 334 | } |
| 335 | set_vfd_pixel(x+1, y-1, 0, display, 0); |
| 336 | set_vfd_pixel(x+1, y-1, 1, display, 0); |
| 337 | if ((temp & 0x0F) == BLAU) |
| 338 | set_vfd_pixel(x+1, y-1, 0, display, 1); |
| 339 | else if ((temp & 0x0F) == ROT) |
| 340 | set_vfd_pixel(x+1, y-1, 1, display, 1); |
| 341 | else if ((temp & 0x0F) == VIOLETT) |
| 342 | { |
| 343 | set_vfd_pixel(x+1, y-1, 0, display, 1); |
| 344 | set_vfd_pixel(x+1, y-1, 1, display, 1); |
| 345 | } |
| 346 | } |
| 347 | } |
wdenk | c8c3a8b | 2003-05-21 20:26:20 +0000 | [diff] [blame] | 348 | if (display > 0) |
| 349 | display--; |
| 350 | else |
| 351 | display = 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 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 | { |
Wolfgang Denk | 3e9a299 | 2006-06-16 15:47:05 +0200 | [diff] [blame^] | 361 | int i; |
| 362 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 363 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
| 364 | S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS(); |
| 365 | S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 366 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 367 | /* try to determine display type from the value |
| 368 | * defined by pull-ups |
| 369 | */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 370 | gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */ |
| 371 | gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */ |
Wolfgang Denk | 3e9a299 | 2006-06-16 15:47:05 +0200 | [diff] [blame^] | 372 | /* allow signals to settle */ |
| 373 | for (i=0; i<10000; i++) /* udelay isn't working yet at this point! */ |
| 374 | __asm("NOP"); |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 375 | vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 376 | |
| 377 | VFD_DISABLE; /* activate blank for the vfd */ |
| 378 | |
| 379 | #define NEW_CPLD_CLK |
| 380 | |
| 381 | #ifdef NEW_CPLD_CLK |
| 382 | if (vfd_board_id) { |
| 383 | /* If new board revision, then use PWM 3 as cpld-clock */ |
| 384 | /* Enable 500 Hz timer for fill level sensor to operate properly */ |
| 385 | /* Configure TOUT3 as functional pin, disable pull-up */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 386 | gpio->PDCON &= ~0x30000; |
| 387 | gpio->PDCON |= 0x20000; |
| 388 | gpio->PDUP |= (1 << 8); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 389 | |
| 390 | /* Configure the prescaler */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 391 | timers->TCFG0 &= ~0xff00; |
| 392 | timers->TCFG0 |= 0x0f00; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 393 | |
| 394 | /* Select MUX input (divider) for timer3 (1/16) */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 395 | timers->TCFG1 &= ~0xf000; |
| 396 | timers->TCFG1 |= 0x3000; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 397 | |
| 398 | /* Enable autoreload and set the counter and compare |
| 399 | * registers to values for the 500 Hz clock |
| 400 | * (for a given prescaler (15) and divider (16)): |
| 401 | * counter = (66000000 / 500) >> 9; |
| 402 | */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 403 | timers->ch[3].TCNTB = 0x101; |
| 404 | timers->ch[3].TCMPB = 0x101 / 2; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 405 | |
| 406 | /* Start timer */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 407 | timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3; |
| 408 | timers->TCON = (timers->TCON | START3) & ~UPDATE3; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 409 | } |
| 410 | #endif |
| 411 | /* If old board revision, then use vm-signal as cpld-clock */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 412 | lcd->LCDCON2 = 0x00FFC000; |
| 413 | lcd->LCDCON3 = 0x0007FF00; |
| 414 | lcd->LCDCON4 = 0x00000000; |
| 415 | lcd->LCDCON5 = 0x00000400; |
| 416 | lcd->LCDCON1 = 0x00000B75; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 417 | /* VM (GPD1) is used as clock for the CPLD */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 418 | gpio->PDCON = (gpio->PDCON & 0xFFFFFFF3) | 0x00000008; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 419 | |
| 420 | return 0; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
| 424 | * initialize LCD-Controller of the S3C2400 for using VFDs |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 425 | * |
| 426 | * VFD detection depends on the board revision: |
| 427 | * starting from Rev. 200 a type code can be read from the data pins, |
| 428 | * driven by some pull-up resistors; all earlier systems must be |
| 429 | * manually configured. The type is set in the "vfd_type" environment |
| 430 | * variable. |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 431 | */ |
| 432 | int drv_vfd_init(void) |
| 433 | { |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 434 | S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD(); |
| 435 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 436 | char *tmp; |
| 437 | ulong palette; |
| 438 | static int vfd_init_done = 0; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 439 | int vfd_inv_data = 0; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 440 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 441 | if (vfd_init_done != 0) |
| 442 | return (0); |
| 443 | vfd_init_done = 1; |
| 444 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 445 | debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 446 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 447 | switch (vfd_board_id) { |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 448 | case 0: /* board revision < Rev.200 */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 449 | if ((tmp = getenv ("vfd_type")) == NULL) { |
| 450 | break; |
| 451 | } |
| 452 | if (strcmp(tmp, "T119C") == 0) { |
| 453 | gd->vfd_type = VFD_TYPE_T119C; |
| 454 | } else if (strcmp(tmp, "MN11236") == 0) { |
| 455 | gd->vfd_type = VFD_TYPE_MN11236; |
| 456 | } else { |
| 457 | /* cannot use printf for a warning here */ |
| 458 | gd->vfd_type = 0; /* unknown */ |
| 459 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 460 | |
| 461 | break; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 462 | default: /* default to MN11236, data inverted */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 463 | gd->vfd_type = VFD_TYPE_MN11236; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 464 | vfd_inv_data = 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 465 | setenv ("vfd_type", "MN11236"); |
| 466 | } |
| 467 | debug ("VFD type: %s%s\n", |
| 468 | (gd->vfd_type == VFD_TYPE_T119C) ? "T119C" : |
| 469 | (gd->vfd_type == VFD_TYPE_MN11236) ? "MN11236" : |
| 470 | "unknown", |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 471 | vfd_inv_data ? ", inverted data" : ""); |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 472 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 473 | gd->fb_base = gd->fb_base; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 474 | create_vfd_table(); |
| 475 | init_grid_ctrl(); |
| 476 | |
| 477 | for (palette=0; palette < 16; palette++) |
| 478 | (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette; |
| 479 | for (palette=16; palette < 256; palette++) |
| 480 | (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00; |
| 481 | |
| 482 | /* |
| 483 | * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben |
| 484 | * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt |
| 485 | * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt |
| 486 | * (wrap around) |
| 487 | * see manual S3C2400 |
| 488 | */ |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 489 | /* Stopp LCD-Controller */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 490 | lcd->LCDCON1 = 0x00000000; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 491 | /* frame buffer startadr */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 492 | lcd->LCDSADDR1 = gd->fb_base >> 1; |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 493 | /* frame buffer endadr */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 494 | lcd->LCDSADDR2 = (gd->fb_base + FRAME_BUF_SIZE) >> 1; |
| 495 | lcd->LCDSADDR3 = ((256/4)); |
| 496 | lcd->LCDCON2 = 0x000DC000; |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 497 | if(gd->vfd_type == VFD_TYPE_MN11236) |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 498 | lcd->LCDCON2 = 37 << 14; /* MN11236: 38 lines */ |
wdenk | 4a6fd34 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 499 | else |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 500 | lcd->LCDCON2 = 55 << 14; /* T119C: 56 lines */ |
| 501 | lcd->LCDCON3 = 0x0051000A; |
| 502 | lcd->LCDCON4 = 0x00000001; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 503 | if (gd->vfd_type && vfd_inv_data) |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 504 | lcd->LCDCON5 = 0x000004C0; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 505 | else |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 506 | lcd->LCDCON5 = 0x00000440; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 507 | |
| 508 | /* Port pins as LCD output */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 509 | gpio->PCCON = (gpio->PCCON & 0xFFFFFF00)| 0x000000AA; |
| 510 | gpio->PDCON = (gpio->PDCON & 0xFFFFFF03)| 0x000000A8; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 511 | |
| 512 | /* Synchronize VFD enable with LCD controller to avoid flicker */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 513 | lcd->LCDCON1 = 0x00000B75; /* Start LCD-Controller */ |
| 514 | while((lcd->LCDCON5 & 0x180000)!=0x100000); /* Wait for end of VSYNC */ |
| 515 | while((lcd->LCDCON5 & 0x060000)!=0x040000); /* Wait for next HSYNC */ |
| 516 | while((lcd->LCDCON5 & 0x060000)==0x040000); |
| 517 | while((lcd->LCDCON5 & 0x060000)!=0x000000); |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 518 | if(gd->vfd_type) |
| 519 | VFD_ENABLE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 520 | |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 521 | debug ("LCDSADDR1: %lX\n", lcd->LCDSADDR1); |
| 522 | debug ("LCDSADDR2: %lX\n", lcd->LCDSADDR2); |
| 523 | debug ("LCDSADDR3: %lX\n", lcd->LCDSADDR3); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 524 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 525 | return 0; |
| 526 | } |
| 527 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 528 | /* |
| 529 | * Disable VFD: should be run before resetting the system: |
| 530 | * disable VM, enable pull-up |
| 531 | */ |
| 532 | void disable_vfd (void) |
| 533 | { |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 534 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
| 535 | |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 536 | VFD_DISABLE; |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 537 | gpio->PDCON &= ~0xC; |
| 538 | gpio->PDUP &= ~0x2; |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 539 | } |
| 540 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 541 | /************************************************************************/ |
| 542 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 543 | /************************************************************************/ |
| 544 | |
| 545 | /* |
| 546 | * This is called early in the system initialization to grab memory |
| 547 | * for the VFD controller. |
| 548 | * |
| 549 | * Note that this is running from ROM, so no write access to global data. |
| 550 | */ |
| 551 | ulong vfd_setmem (ulong addr) |
| 552 | { |
| 553 | ulong size; |
| 554 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 555 | /* Round up to nearest full page */ |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 556 | size = (FRAME_BUF_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 557 | |
| 558 | debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr); |
| 559 | |
| 560 | return (size); |
| 561 | } |
| 562 | |
wdenk | f325e18 | 2004-10-09 23:28:40 +0000 | [diff] [blame] | 563 | /* |
| 564 | * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb, |
| 565 | * descriptors and palette areas. |
| 566 | */ |
| 567 | ulong calc_fbsize (void) |
| 568 | { |
| 569 | return FRAME_BUF_SIZE; |
| 570 | } |
| 571 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 572 | #endif /* CONFIG_VFD */ |