vfd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. /* ** DEBUG SETTINGS */
  25. /************************************************************************/
  26. /* #define DEBUG */
  27. /************************************************************************/
  28. /* ** HEADER FILES */
  29. /************************************************************************/
  30. #include <config.h>
  31. #include <common.h>
  32. #include <version.h>
  33. #include <stdarg.h>
  34. #include <linux/types.h>
  35. #include <devices.h>
  36. #include <s3c2400.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #ifdef CONFIG_VFD
  39. /************************************************************************/
  40. /* ** CONFIG STUFF -- should be moved to board config file */
  41. /************************************************************************/
  42. /************************************************************************/
  43. #ifndef PAGE_SIZE
  44. #define PAGE_SIZE 4096
  45. #endif
  46. #define ROT 0x09
  47. #define BLAU 0x0C
  48. #define VIOLETT 0X0D
  49. /* MAGIC */
  50. #define FRAME_BUF_SIZE ((256*4*56)/8)
  51. #define frame_buf_offs 4
  52. /* defines for starting Timer3 as CPLD-Clk */
  53. #define START3 (1 << 16)
  54. #define UPDATE3 (1 << 17)
  55. #define INVERT3 (1 << 18)
  56. #define RELOAD3 (1 << 19)
  57. /* CPLD-Register for controlling vfd-blank-signal */
  58. #define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000)
  59. #define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001)
  60. /* Supported VFD Types */
  61. #define VFD_TYPE_T119C 1 /* Noritake T119C VFD */
  62. #define VFD_TYPE_MN11236 2
  63. /*#define NEW_CPLD_CLK*/
  64. int vfd_board_id;
  65. /* taken from armboot/common/vfd.c */
  66. unsigned long adr_vfd_table[112][18][2][4][2];
  67. unsigned char bit_vfd_table[112][18][2][4][2];
  68. /*
  69. * initialize the values for the VFD-grid-control in the framebuffer
  70. */
  71. void init_grid_ctrl(void)
  72. {
  73. ulong adr, grid_cycle;
  74. unsigned int bit, display;
  75. unsigned char temp, bit_nr;
  76. /*
  77. * clear frame buffer (logical clear => set to "black")
  78. */
  79. memset ((void *)(gd->fb_base), 0, FRAME_BUF_SIZE);
  80. switch (gd->vfd_type) {
  81. case VFD_TYPE_T119C:
  82. for (display=0; display<4; display++) {
  83. for(grid_cycle=0; grid_cycle<56; grid_cycle++) {
  84. bit = grid_cycle * 256 * 4 +
  85. (grid_cycle + 200) * 4 +
  86. frame_buf_offs + display;
  87. /* wrap arround if offset (see manual S3C2400) */
  88. if (bit>=FRAME_BUF_SIZE*8)
  89. bit = bit - (FRAME_BUF_SIZE * 8);
  90. adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8);
  91. bit_nr = bit % 8;
  92. bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4;
  93. temp=(*(volatile unsigned char*)(adr));
  94. temp |= (1<<bit_nr);
  95. (*(volatile unsigned char*)(adr))=temp;
  96. if(grid_cycle<55)
  97. bit = grid_cycle*256*4+(grid_cycle+201)*4+frame_buf_offs+display;
  98. else
  99. bit = grid_cycle*256*4+200*4+frame_buf_offs+display-4; /* grid nr. 0 */
  100. /* wrap arround if offset (see manual S3C2400) */
  101. if (bit>=FRAME_BUF_SIZE*8)
  102. bit = bit-(FRAME_BUF_SIZE*8);
  103. adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8);
  104. bit_nr = bit%8;
  105. bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
  106. temp=(*(volatile unsigned char*)(adr));
  107. temp |= (1<<bit_nr);
  108. (*(volatile unsigned char*)(adr))=temp;
  109. }
  110. }
  111. break;
  112. case VFD_TYPE_MN11236:
  113. for (display=0; display<4; display++) {
  114. for (grid_cycle=0; grid_cycle<38; grid_cycle++) {
  115. bit = grid_cycle * 256 * 4 +
  116. (253 - grid_cycle) * 4 +
  117. frame_buf_offs + display;
  118. /* wrap arround if offset (see manual S3C2400) */
  119. if (bit>=FRAME_BUF_SIZE*8)
  120. bit = bit - (FRAME_BUF_SIZE * 8);
  121. adr = gd->fb_base + (bit/32) * 4 + (3 - (bit%32) / 8);
  122. bit_nr = bit % 8;
  123. bit_nr = (bit_nr > 3) ? bit_nr-4 : bit_nr+4;
  124. temp=(*(volatile unsigned char*)(adr));
  125. temp |= (1<<bit_nr);
  126. (*(volatile unsigned char*)(adr))=temp;
  127. if(grid_cycle<37)
  128. bit = grid_cycle*256*4+(252-grid_cycle)*4+frame_buf_offs+display;
  129. /* wrap arround if offset (see manual S3C2400) */
  130. if (bit>=FRAME_BUF_SIZE*8)
  131. bit = bit-(FRAME_BUF_SIZE*8);
  132. adr = gd->fb_base+(bit/32)*4+(3-(bit%32)/8);
  133. bit_nr = bit%8;
  134. bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
  135. temp=(*(volatile unsigned char*)(adr));
  136. temp |= (1<<bit_nr);
  137. (*(volatile unsigned char*)(adr))=temp;
  138. }
  139. }
  140. break;
  141. default:
  142. printf ("Warning: unknown display type\n");
  143. break;
  144. }
  145. }
  146. /*
  147. *create translation table for getting easy the right position in the
  148. *physical framebuffer for some x/y-coordinates of the VFDs
  149. */
  150. void create_vfd_table(void)
  151. {
  152. unsigned long vfd_table[112][18][2][4][2];
  153. unsigned int x, y, color, display, entry, pixel;
  154. unsigned int x_abcdef = 0;
  155. switch (gd->vfd_type) {
  156. case VFD_TYPE_T119C:
  157. for(y=0; y<=17; y++) { /* Line */
  158. for(x=0; x<=111; x++) { /* Column */
  159. for(display=0; display <=3; display++) {
  160. /* Display 0 blue pixels */
  161. vfd_table[x][y][0][display][0] =
  162. (x==0) ? y*16+display
  163. : (x%4)*4+y*16+((x-1)/2)*1024+display;
  164. /* Display 0 red pixels */
  165. vfd_table[x][y][1][display][0] =
  166. (x==0) ? y*16+512+display
  167. : (x%4)*4+y*16+((x-1)/2)*1024+512+display;
  168. }
  169. }
  170. }
  171. break;
  172. case VFD_TYPE_MN11236:
  173. for(y=0; y<=17; y++) { /* Line */
  174. for(x=0; x<=111; x++) { /* Column */
  175. for(display=0; display <=3; display++) {
  176. vfd_table[x][y][0][display][0]=0;
  177. vfd_table[x][y][0][display][1]=0;
  178. vfd_table[x][y][1][display][0]=0;
  179. vfd_table[x][y][1][display][1]=0;
  180. switch (x%6) {
  181. case 0: x_abcdef=0; break; /* a -> a */
  182. case 1: x_abcdef=2; break; /* b -> c */
  183. case 2: x_abcdef=4; break; /* c -> e */
  184. case 3: x_abcdef=5; break; /* d -> f */
  185. case 4: x_abcdef=3; break; /* e -> d */
  186. case 5: x_abcdef=1; break; /* f -> b */
  187. }
  188. /* blue pixels */
  189. vfd_table[x][y][0][display][0] =
  190. (x>1) ? x_abcdef*4+((x-1)/3)*1024+y*48+display
  191. : x_abcdef*4+ 0+y*48+display;
  192. /* blue pixels */
  193. if (x>1 && (x-1)%3)
  194. vfd_table[x][y][0][display][1] = x_abcdef*4+((x-1)/3+1)*1024+y*48+display;
  195. /* red pixels */
  196. vfd_table[x][y][1][display][0] =
  197. (x>1) ? x_abcdef*4+24+((x-1)/3)*1024+y*48+display
  198. : x_abcdef*4+24+ 0+y*48+display;
  199. /* red pixels */
  200. if (x>1 && (x-1)%3)
  201. vfd_table[x][y][1][display][1] = x_abcdef*4+24+((x-1)/3+1)*1024+y*48+display;
  202. }
  203. }
  204. }
  205. break;
  206. default:
  207. /* do nothing */
  208. return;
  209. }
  210. /*
  211. * Create table with entries for physical byte adresses and
  212. * bit-number within the byte
  213. * from table with bit-numbers within the total framebuffer
  214. */
  215. for(y=0;y<18;y++) {
  216. for(x=0;x<112;x++) {
  217. for(color=0;color<2;color++) {
  218. for(display=0;display<4;display++) {
  219. for(entry=0;entry<2;entry++) {
  220. unsigned long adr = gd->fb_base;
  221. unsigned int bit_nr = 0;
  222. pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs;
  223. /*
  224. * wrap arround if offset
  225. * (see manual S3C2400)
  226. */
  227. if (pixel>=FRAME_BUF_SIZE*8)
  228. pixel = pixel-(FRAME_BUF_SIZE*8);
  229. adr = gd->fb_base+(pixel/32)*4+(3-(pixel%32)/8);
  230. bit_nr = pixel%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;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. /*
  241. * Set/clear pixel of the VFDs
  242. */
  243. void set_vfd_pixel(unsigned char x, unsigned char y,
  244. unsigned char color, unsigned char display,
  245. unsigned char value)
  246. {
  247. ulong adr;
  248. unsigned char bit_nr, temp;
  249. if (! gd->vfd_type) {
  250. /* Unknown type. */
  251. return;
  252. }
  253. /* Pixel-Eintrag Nr. 1 */
  254. adr = adr_vfd_table[x][y][color][display][0];
  255. /* Pixel-Eintrag Nr. 1 */
  256. bit_nr = bit_vfd_table[x][y][color][display][0];
  257. temp=(*(volatile unsigned char*)(adr));
  258. if (value)
  259. temp |= (1<<bit_nr);
  260. else
  261. temp &= ~(1<<bit_nr);
  262. (*(volatile unsigned char*)(adr))=temp;
  263. }
  264. /*
  265. * transfer image from BMP-File
  266. */
  267. void transfer_pic(int display, unsigned char *adr, int height, int width)
  268. {
  269. int x, y;
  270. unsigned char temp;
  271. for (; height > 0; height -= 18)
  272. {
  273. if (height > 18)
  274. y = 18;
  275. else
  276. y = height;
  277. for (; y > 0; y--)
  278. {
  279. for (x = 0; x < width; x += 2)
  280. {
  281. temp = *adr++;
  282. set_vfd_pixel(x, y-1, 0, display, 0);
  283. set_vfd_pixel(x, y-1, 1, display, 0);
  284. if ((temp >> 4) == BLAU)
  285. set_vfd_pixel(x, y-1, 0, display, 1);
  286. else if ((temp >> 4) == ROT)
  287. set_vfd_pixel(x, y-1, 1, display, 1);
  288. else if ((temp >> 4) == VIOLETT)
  289. {
  290. set_vfd_pixel(x, y-1, 0, display, 1);
  291. set_vfd_pixel(x, y-1, 1, display, 1);
  292. }
  293. set_vfd_pixel(x+1, y-1, 0, display, 0);
  294. set_vfd_pixel(x+1, y-1, 1, display, 0);
  295. if ((temp & 0x0F) == BLAU)
  296. set_vfd_pixel(x+1, y-1, 0, display, 1);
  297. else if ((temp & 0x0F) == ROT)
  298. set_vfd_pixel(x+1, y-1, 1, display, 1);
  299. else if ((temp & 0x0F) == VIOLETT)
  300. {
  301. set_vfd_pixel(x+1, y-1, 0, display, 1);
  302. set_vfd_pixel(x+1, y-1, 1, display, 1);
  303. }
  304. }
  305. }
  306. if (display > 0)
  307. display--;
  308. else
  309. display = 3;
  310. }
  311. }
  312. /*
  313. * This function initializes VFD clock that is needed for the CPLD that
  314. * manages the keyboard.
  315. */
  316. int vfd_init_clocks (void)
  317. {
  318. int i;
  319. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  320. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  321. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  322. /* try to determine display type from the value
  323. * defined by pull-ups
  324. */
  325. gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */
  326. gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */
  327. /* allow signals to settle */
  328. for (i=0; i<10000; i++) /* udelay isn't working yet at this point! */
  329. __asm__("NOP");
  330. vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */
  331. VFD_DISABLE; /* activate blank for the vfd */
  332. #define NEW_CPLD_CLK
  333. #ifdef NEW_CPLD_CLK
  334. if (vfd_board_id) {
  335. /* If new board revision, then use PWM 3 as cpld-clock */
  336. /* Enable 500 Hz timer for fill level sensor to operate properly */
  337. /* Configure TOUT3 as functional pin, disable pull-up */
  338. gpio->PDCON &= ~0x30000;
  339. gpio->PDCON |= 0x20000;
  340. gpio->PDUP |= (1 << 8);
  341. /* Configure the prescaler */
  342. timers->TCFG0 &= ~0xff00;
  343. timers->TCFG0 |= 0x0f00;
  344. /* Select MUX input (divider) for timer3 (1/16) */
  345. timers->TCFG1 &= ~0xf000;
  346. timers->TCFG1 |= 0x3000;
  347. /* Enable autoreload and set the counter and compare
  348. * registers to values for the 500 Hz clock
  349. * (for a given prescaler (15) and divider (16)):
  350. * counter = (66000000 / 500) >> 9;
  351. */
  352. timers->ch[3].TCNTB = 0x101;
  353. timers->ch[3].TCMPB = 0x101 / 2;
  354. /* Start timer */
  355. timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3;
  356. timers->TCON = (timers->TCON | START3) & ~UPDATE3;
  357. }
  358. #endif
  359. /* If old board revision, then use vm-signal as cpld-clock */
  360. lcd->LCDCON2 = 0x00FFC000;
  361. lcd->LCDCON3 = 0x0007FF00;
  362. lcd->LCDCON4 = 0x00000000;
  363. lcd->LCDCON5 = 0x00000400;
  364. lcd->LCDCON1 = 0x00000B75;
  365. /* VM (GPD1) is used as clock for the CPLD */
  366. gpio->PDCON = (gpio->PDCON & 0xFFFFFFF3) | 0x00000008;
  367. return 0;
  368. }
  369. /*
  370. * initialize LCD-Controller of the S3C2400 for using VFDs
  371. *
  372. * VFD detection depends on the board revision:
  373. * starting from Rev. 200 a type code can be read from the data pins,
  374. * driven by some pull-up resistors; all earlier systems must be
  375. * manually configured. The type is set in the "vfd_type" environment
  376. * variable.
  377. */
  378. int drv_vfd_init(void)
  379. {
  380. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  381. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  382. char *tmp;
  383. ulong palette;
  384. static int vfd_init_done = 0;
  385. int vfd_inv_data = 0;
  386. if (vfd_init_done != 0)
  387. return (0);
  388. vfd_init_done = 1;
  389. debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id);
  390. switch (vfd_board_id) {
  391. case 0: /* board revision < Rev.200 */
  392. if ((tmp = getenv ("vfd_type")) == NULL) {
  393. break;
  394. }
  395. if (strcmp(tmp, "T119C") == 0) {
  396. gd->vfd_type = VFD_TYPE_T119C;
  397. } else if (strcmp(tmp, "MN11236") == 0) {
  398. gd->vfd_type = VFD_TYPE_MN11236;
  399. } else {
  400. /* cannot use printf for a warning here */
  401. gd->vfd_type = 0; /* unknown */
  402. }
  403. break;
  404. default: /* default to MN11236, data inverted */
  405. gd->vfd_type = VFD_TYPE_MN11236;
  406. vfd_inv_data = 1;
  407. setenv ("vfd_type", "MN11236");
  408. }
  409. debug ("VFD type: %s%s\n",
  410. (gd->vfd_type == VFD_TYPE_T119C) ? "T119C" :
  411. (gd->vfd_type == VFD_TYPE_MN11236) ? "MN11236" :
  412. "unknown",
  413. vfd_inv_data ? ", inverted data" : "");
  414. gd->fb_base = gd->fb_base;
  415. create_vfd_table();
  416. init_grid_ctrl();
  417. for (palette=0; palette < 16; palette++)
  418. (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette;
  419. for (palette=16; palette < 256; palette++)
  420. (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00;
  421. /*
  422. * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben
  423. * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt
  424. * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt
  425. * (wrap around)
  426. * see manual S3C2400
  427. */
  428. /* Stopp LCD-Controller */
  429. lcd->LCDCON1 = 0x00000000;
  430. /* frame buffer startadr */
  431. lcd->LCDSADDR1 = gd->fb_base >> 1;
  432. /* frame buffer endadr */
  433. lcd->LCDSADDR2 = (gd->fb_base + FRAME_BUF_SIZE) >> 1;
  434. lcd->LCDSADDR3 = ((256/4));
  435. lcd->LCDCON2 = 0x000DC000;
  436. if(gd->vfd_type == VFD_TYPE_MN11236)
  437. lcd->LCDCON2 = 37 << 14; /* MN11236: 38 lines */
  438. else
  439. lcd->LCDCON2 = 55 << 14; /* T119C: 56 lines */
  440. lcd->LCDCON3 = 0x0051000A;
  441. lcd->LCDCON4 = 0x00000001;
  442. if (gd->vfd_type && vfd_inv_data)
  443. lcd->LCDCON5 = 0x000004C0;
  444. else
  445. lcd->LCDCON5 = 0x00000440;
  446. /* Port pins as LCD output */
  447. gpio->PCCON = (gpio->PCCON & 0xFFFFFF00)| 0x000000AA;
  448. gpio->PDCON = (gpio->PDCON & 0xFFFFFF03)| 0x000000A8;
  449. /* Synchronize VFD enable with LCD controller to avoid flicker */
  450. lcd->LCDCON1 = 0x00000B75; /* Start LCD-Controller */
  451. while((lcd->LCDCON5 & 0x180000)!=0x100000); /* Wait for end of VSYNC */
  452. while((lcd->LCDCON5 & 0x060000)!=0x040000); /* Wait for next HSYNC */
  453. while((lcd->LCDCON5 & 0x060000)==0x040000);
  454. while((lcd->LCDCON5 & 0x060000)!=0x000000);
  455. if(gd->vfd_type)
  456. VFD_ENABLE;
  457. debug ("LCDSADDR1: %lX\n", lcd->LCDSADDR1);
  458. debug ("LCDSADDR2: %lX\n", lcd->LCDSADDR2);
  459. debug ("LCDSADDR3: %lX\n", lcd->LCDSADDR3);
  460. return 0;
  461. }
  462. /*
  463. * Disable VFD: should be run before resetting the system:
  464. * disable VM, enable pull-up
  465. */
  466. void disable_vfd (void)
  467. {
  468. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  469. VFD_DISABLE;
  470. gpio->PDCON &= ~0xC;
  471. gpio->PDUP &= ~0x2;
  472. }
  473. /************************************************************************/
  474. /* ** ROM capable initialization part - needed to reserve FB memory */
  475. /************************************************************************/
  476. /*
  477. * This is called early in the system initialization to grab memory
  478. * for the VFD controller.
  479. *
  480. * Note that this is running from ROM, so no write access to global data.
  481. */
  482. ulong vfd_setmem (ulong addr)
  483. {
  484. ulong size;
  485. /* Round up to nearest full page */
  486. size = (FRAME_BUF_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  487. debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr);
  488. return (size);
  489. }
  490. /*
  491. * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
  492. * descriptors and palette areas.
  493. */
  494. ulong calc_fbsize (void)
  495. {
  496. return FRAME_BUF_SIZE;
  497. }
  498. #endif /* CONFIG_VFD */