X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=board%2Ftrab%2Fvfd.c;h=1abc2adc65ad47dd8d2c4f5d4d0b4694e0ca6447;hb=9fd5e31fe0245c44a11d35a8603bb6b25c97b5c8;hp=1ea483f0c6bcf527bfaa8767b005922a102e0417;hpb=c609719b8d1b2dca590e0ed499016d041203e403;p=u-boot diff --git a/board/trab/vfd.c b/board/trab/vfd.c index 1ea483f0c6..1abc2adc65 100644 --- a/board/trab/vfd.c +++ b/board/trab/vfd.c @@ -55,12 +55,30 @@ #define BLAU 0x0C #define VIOLETT 0X0D -ulong vfdbase; -ulong frame_buf_size; +/* MAGIC */ +#define FRAME_BUF_SIZE ((256*4*56)/8) #define frame_buf_offs 4 +/* defines for starting Timer3 as CPLD-Clk */ +#define START3 (1 << 16) +#define UPDATE3 (1 << 17) +#define INVERT3 (1 << 18) +#define RELOAD3 (1 << 19) + +/* CPLD-Register for controlling vfd-blank-signal */ +#define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000) +#define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001) + +/* Supported VFD Types */ +#define VFD_TYPE_T119C 1 /* Noritake T119C VFD */ +#define VFD_TYPE_MN11236 2 + +/*#define NEW_CPLD_CLK*/ + +int vfd_board_id; + /* taken from armboot/common/vfd.c */ -ulong adr_vfd_table[112][18][2][4][2]; +unsigned long adr_vfd_table[112][18][2][4][2]; unsigned char bit_vfd_table[112][18][2][4][2]; /* @@ -68,26 +86,31 @@ unsigned char bit_vfd_table[112][18][2][4][2]; */ void init_grid_ctrl(void) { + DECLARE_GLOBAL_DATA_PTR; ulong adr, grid_cycle; unsigned int bit, display; unsigned char temp, bit_nr; - for (adr=vfdbase; adr<=(vfdbase+7168); adr+=4) /*clear frame buffer */ - (*(volatile ulong*)(adr))=0; - - for(display=0;display<=3;display++) - { - for(grid_cycle=0;grid_cycle<=55;grid_cycle++) - { - bit = grid_cycle*256*4+(grid_cycle+200)*4+frame_buf_offs+display; + /* + * clear frame buffer (logical clear => set to "black") + */ + memset ((void *)(gd->fb_base), 0, FRAME_BUF_SIZE); + + switch (gd->vfd_type) { + case VFD_TYPE_T119C: + for (display=0; display<4; display++) { + for(grid_cycle=0; grid_cycle<56; grid_cycle++) { + bit = grid_cycle * 256 * 4 + + (grid_cycle + 200) * 4 + + frame_buf_offs + display; /* wrap arround if offset (see manual S3C2400) */ - if (bit>=frame_buf_size*8) - bit = bit-(frame_buf_size*8); - adr = vfdbase+(bit/32)*4+(3-(bit%32)/8); - bit_nr = bit%8; - bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; + if (bit>=FRAME_BUF_SIZE*8) + bit = bit - (FRAME_BUF_SIZE * 8); + adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); + bit_nr = bit % 8; + bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; temp=(*(volatile unsigned char*)(adr)); - temp|=(1<=frame_buf_size*8) - bit = bit-(frame_buf_size*8); - adr = vfdbase+(bit/32)*4+(3-(bit%32)/8); + if (bit>=FRAME_BUF_SIZE*8) + bit = bit-(FRAME_BUF_SIZE*8); + adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); bit_nr = bit%8; bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; temp=(*(volatile unsigned char*)(adr)); - temp|=(1<=FRAME_BUF_SIZE*8) + bit = bit - (FRAME_BUF_SIZE * 8); + adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8); + bit_nr = bit % 8; + bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4; + temp=(*(volatile unsigned char*)(adr)); + temp |= (1<=FRAME_BUF_SIZE*8) + bit = bit-(FRAME_BUF_SIZE*8); + adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8); + bit_nr = bit%8; + bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; + temp=(*(volatile unsigned char*)(adr)); + temp |= (1<vfd_type) { + case VFD_TYPE_T119C: + for(y=0; y<=17; y++) { /* Line */ + for(x=0; x<=111; x++) { /* Column */ + for(display=0; display <=3; display++) { + + /* Display 0 blue pixels */ + vfd_table[x][y][0][display][0] = + (x==0) ? y*16+display + : (x%4)*4+y*16+((x-1)/2)*1024+display; + /* Display 0 red pixels */ + vfd_table[x][y][1][display][0] = + (x==0) ? y*16+512+display + : (x%4)*4+y*16+((x-1)/2)*1024+512+display; + } + } + } + break; + case VFD_TYPE_MN11236: + for(y=0; y<=17; y++) { /* Line */ + for(x=0; x<=111; x++) { /* Column */ + for(display=0; display <=3; display++) { + + vfd_table[x][y][0][display][0]=0; + vfd_table[x][y][0][display][1]=0; + vfd_table[x][y][1][display][0]=0; + vfd_table[x][y][1][display][1]=0; + + switch (x%6) { + case 0: x_abcdef=0; break; /* a -> a */ + case 1: x_abcdef=2; break; /* b -> c */ + case 2: x_abcdef=4; break; /* c -> e */ + case 3: x_abcdef=5; break; /* d -> f */ + case 4: x_abcdef=3; break; /* e -> d */ + case 5: x_abcdef=1; break; /* f -> b */ + } + + /* blue pixels */ + vfd_table[x][y][0][display][0] = + (x>1) ? x_abcdef*4+((x-1)/3)*1024+y*48+display + : x_abcdef*4+ 0+y*48+display; + /* blue pixels */ + if (x>1 && (x-1)%3) + vfd_table[x][y][0][display][1] = x_abcdef*4+((x-1)/3+1)*1024+y*48+display; + + /* red pixels */ + vfd_table[x][y][1][display][0] = + (x>1) ? x_abcdef*4+24+((x-1)/3)*1024+y*48+display + : x_abcdef*4+24+ 0+y*48+display; + /* red pixels */ + if (x>1 && (x-1)%3) + vfd_table[x][y][1][display][1] = x_abcdef*4+24+((x-1)/3+1)*1024+y*48+display; + } } + } + break; + default: + /* do nothing */ + return; } /* - * Create translation table for Noritake-T119C-VFD-specific - * organized frame-buffer * Create table with entries for physical byte adresses and * bit-number within the byte * from table with bit-numbers within the total framebuffer */ - for(y=0;y<=17;y++) - { - for(x=0;x<=111;x++) - { - for(color=0;color<=1;color++) - { - for(display=0;display<=3;display++) - { - for(entry=0;entry<=1;entry++) - { - pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs; - /* - * wrap arround if offset - * (see manual S3C2400) - */ - if (pixel>=frame_buf_size*8) - pixel = pixel-(frame_buf_size*8); - adr = vfdbase+(pixel/32)*4+(3-(pixel%32)/8); - bit_nr = pixel%8; - bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; - adr_vfd_table[x][y][color][display][entry] = adr; - bit_vfd_table[x][y][color][display][entry] = bit_nr; - } - } + for(y=0;y<18;y++) { + for(x=0;x<112;x++) { + for(color=0;color<2;color++) { + for(display=0;display<4;display++) { + for(entry=0;entry<2;entry++) { + unsigned long adr = gd->fb_base; + unsigned int bit_nr = 0; + + if (vfd_table[x][y][color][display][entry]) { + + pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs; + /* + * wrap arround if offset + * (see manual S3C2400) + */ + if (pixel>=FRAME_BUF_SIZE*8) + pixel = pixel-(FRAME_BUF_SIZE*8); + adr = gd->fb_base+(pixel/32)*4+(3-(pixel%32)/8); + bit_nr = pixel%8; + bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4; + } + adr_vfd_table[x][y][color][display][entry] = adr; + bit_vfd_table[x][y][color][display][entry] = bit_nr; } + } } + } } } /* * Set/clear pixel of the VFDs */ -void set_vfd_pixel(unsigned char x, unsigned char y, unsigned char color, unsigned char display, unsigned char value) +void set_vfd_pixel(unsigned char x, unsigned char y, + unsigned char color, unsigned char display, + unsigned char value) { + DECLARE_GLOBAL_DATA_PTR; ulong adr; unsigned char bit_nr, temp; - if (value!=0) - { - /* Pixel-Eintrag Nr. 1 */ - adr = adr_vfd_table[x][y][color][display][0]; - /* Pixel-Eintrag Nr. 1 */ - bit_nr = bit_vfd_table[x][y][color][display][0]; - temp=(*(volatile unsigned char*)(adr)); - temp|=1<vfd_type) { + /* Unknown type. */ + return; } + + /* Pixel-Eintrag Nr. 1 */ + adr = adr_vfd_table[x][y][color][display][0]; + /* Pixel-Eintrag Nr. 1 */ + bit_nr = bit_vfd_table[x][y][color][display][0]; + temp=(*(volatile unsigned char*)(adr)); + + if (value) + temp |= (1< 3) - display = 0; + if (display > 0) + display--; + else + display = 3; } } +/* + * This function initializes VFD clock that is needed for the CPLD that + * manages the keyboard. + */ +int vfd_init_clocks (void) +{ + S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); + S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS(); + S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD(); + + /* try to determine display type from the value + * defined by pull-ups + */ + gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */ + gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */ + udelay (10); /* allow signals to settle */ + vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */ + + VFD_DISABLE; /* activate blank for the vfd */ + +#define NEW_CPLD_CLK + +#ifdef NEW_CPLD_CLK + if (vfd_board_id) { + /* If new board revision, then use PWM 3 as cpld-clock */ + /* Enable 500 Hz timer for fill level sensor to operate properly */ + /* Configure TOUT3 as functional pin, disable pull-up */ + gpio->PDCON &= ~0x30000; + gpio->PDCON |= 0x20000; + gpio->PDUP |= (1 << 8); + + /* Configure the prescaler */ + timers->TCFG0 &= ~0xff00; + timers->TCFG0 |= 0x0f00; + + /* Select MUX input (divider) for timer3 (1/16) */ + timers->TCFG1 &= ~0xf000; + timers->TCFG1 |= 0x3000; + + /* Enable autoreload and set the counter and compare + * registers to values for the 500 Hz clock + * (for a given prescaler (15) and divider (16)): + * counter = (66000000 / 500) >> 9; + */ + timers->ch[3].TCNTB = 0x101; + timers->ch[3].TCMPB = 0x101 / 2; + + /* Start timer */ + timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3; + timers->TCON = (timers->TCON | START3) & ~UPDATE3; + } +#endif + /* If old board revision, then use vm-signal as cpld-clock */ + lcd->LCDCON2 = 0x00FFC000; + lcd->LCDCON3 = 0x0007FF00; + lcd->LCDCON4 = 0x00000000; + lcd->LCDCON5 = 0x00000400; + lcd->LCDCON1 = 0x00000B75; + /* VM (GPD1) is used as clock for the CPLD */ + gpio->PDCON = (gpio->PDCON & 0xFFFFFFF3) | 0x00000008; + + return 0; +} + /* * initialize LCD-Controller of the S3C2400 for using VFDs + * + * VFD detection depends on the board revision: + * starting from Rev. 200 a type code can be read from the data pins, + * driven by some pull-up resistors; all earlier systems must be + * manually configured. The type is set in the "vfd_type" environment + * variable. */ int drv_vfd_init(void) { + S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD(); + S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); + char *tmp; ulong palette; + static int vfd_init_done = 0; + int vfd_inv_data = 0; DECLARE_GLOBAL_DATA_PTR; - vfdbase = gd->fb_base; + if (vfd_init_done != 0) + return (0); + vfd_init_done = 1; + + debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id); + + switch (vfd_board_id) { + case 0: /* board revision < Rev.200 */ + if ((tmp = getenv ("vfd_type")) == NULL) { + break; + } + if (strcmp(tmp, "T119C") == 0) { + gd->vfd_type = VFD_TYPE_T119C; + } else if (strcmp(tmp, "MN11236") == 0) { + gd->vfd_type = VFD_TYPE_MN11236; + } else { + /* cannot use printf for a warning here */ + gd->vfd_type = 0; /* unknown */ + } + + break; + default: /* default to MN11236, data inverted */ + gd->vfd_type = VFD_TYPE_MN11236; + vfd_inv_data = 1; + setenv ("vfd_type", "MN11236"); + } + debug ("VFD type: %s%s\n", + (gd->vfd_type == VFD_TYPE_T119C) ? "T119C" : + (gd->vfd_type == VFD_TYPE_MN11236) ? "MN11236" : + "unknown", + vfd_inv_data ? ", inverted data" : ""); + + gd->fb_base = gd->fb_base; create_vfd_table(); init_grid_ctrl(); + for (palette=0; palette < 16; palette++) + (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette; + for (palette=16; palette < 256; palette++) + (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00; + /* * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt @@ -353,39 +485,58 @@ int drv_vfd_init(void) * (wrap around) * see manual S3C2400 */ + /* Stopp LCD-Controller */ + lcd->LCDCON1 = 0x00000000; /* frame buffer startadr */ - rLCDSADDR1 = vfdbase >> 1; + lcd->LCDSADDR1 = gd->fb_base >> 1; /* frame buffer endadr */ - rLCDSADDR2 = (vfdbase + frame_buf_size) >> 1; - rLCDSADDR3 = ((256/4)); - - /* Port-Pins als LCD-Ausgang */ - rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA; - /* Port-Pins als LCD-Ausgang */ - rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8; -#ifdef WITH_VFRAME - /* mit VFRAME zum Messen */ - rPDCON = (rPDCON & 0xFFFFFF00)| 0x000000AA; -#endif + lcd->LCDSADDR2 = (gd->fb_base + FRAME_BUF_SIZE) >> 1; + lcd->LCDSADDR3 = ((256/4)); + lcd->LCDCON2 = 0x000DC000; + if(gd->vfd_type == VFD_TYPE_MN11236) + lcd->LCDCON2 = 37 << 14; /* MN11236: 38 lines */ + else + lcd->LCDCON2 = 55 << 14; /* T119C: 56 lines */ + lcd->LCDCON3 = 0x0051000A; + lcd->LCDCON4 = 0x00000001; + if (gd->vfd_type && vfd_inv_data) + lcd->LCDCON5 = 0x000004C0; + else + lcd->LCDCON5 = 0x00000440; - rLCDCON2 = 0x000DC000; - rLCDCON3 = 0x0051000A; - rLCDCON4 = 0x00000001; - rLCDCON5 = 0x00000440; - rLCDCON1 = 0x00000B75; + /* Port pins as LCD output */ + gpio->PCCON = (gpio->PCCON & 0xFFFFFF00)| 0x000000AA; + gpio->PDCON = (gpio->PDCON & 0xFFFFFF03)| 0x000000A8; - debug ("LCDSADDR1: %lX\n", rLCDSADDR1); - debug ("LCDSADDR2: %lX\n", rLCDSADDR2); - debug ("LCDSADDR3: %lX\n", rLCDSADDR3); + /* Synchronize VFD enable with LCD controller to avoid flicker */ + lcd->LCDCON1 = 0x00000B75; /* Start LCD-Controller */ + while((lcd->LCDCON5 & 0x180000)!=0x100000); /* Wait for end of VSYNC */ + while((lcd->LCDCON5 & 0x060000)!=0x040000); /* Wait for next HSYNC */ + while((lcd->LCDCON5 & 0x060000)==0x040000); + while((lcd->LCDCON5 & 0x060000)!=0x000000); + if(gd->vfd_type) + VFD_ENABLE; - for(palette=0;palette<=15;palette++) - (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette; - for(palette=16;palette<=255;palette++) - (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00; + debug ("LCDSADDR1: %lX\n", lcd->LCDSADDR1); + debug ("LCDSADDR2: %lX\n", lcd->LCDSADDR2); + debug ("LCDSADDR3: %lX\n", lcd->LCDSADDR3); return 0; } +/* + * Disable VFD: should be run before resetting the system: + * disable VM, enable pull-up + */ +void disable_vfd (void) +{ + S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); + + VFD_DISABLE; + gpio->PDCON &= ~0xC; + gpio->PDUP &= ~0x2; +} + /************************************************************************/ /* ** ROM capable initialization part - needed to reserve FB memory */ /************************************************************************/ @@ -400,11 +551,8 @@ ulong vfd_setmem (ulong addr) { ulong size; - /* MAGIC */ - frame_buf_size = (256*4*56)/8; - /* Round up to nearest full page */ - size = (frame_buf_size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); + size = (FRAME_BUF_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr);