vfd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. if (vfd_table[x][y][color][display][entry]) {
  223. pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs;
  224. /*
  225. * wrap arround if offset
  226. * (see manual S3C2400)
  227. */
  228. if (pixel>=FRAME_BUF_SIZE*8)
  229. pixel = pixel-(FRAME_BUF_SIZE*8);
  230. adr = gd->fb_base+(pixel/32)*4+(3-(pixel%32)/8);
  231. bit_nr = pixel%8;
  232. bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
  233. }
  234. adr_vfd_table[x][y][color][display][entry] = adr;
  235. bit_vfd_table[x][y][color][display][entry] = bit_nr;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. }
  242. /*
  243. * Set/clear pixel of the VFDs
  244. */
  245. void set_vfd_pixel(unsigned char x, unsigned char y,
  246. unsigned char color, unsigned char display,
  247. unsigned char value)
  248. {
  249. ulong adr;
  250. unsigned char bit_nr, temp;
  251. if (! gd->vfd_type) {
  252. /* Unknown type. */
  253. return;
  254. }
  255. /* Pixel-Eintrag Nr. 1 */
  256. adr = adr_vfd_table[x][y][color][display][0];
  257. /* Pixel-Eintrag Nr. 1 */
  258. bit_nr = bit_vfd_table[x][y][color][display][0];
  259. temp=(*(volatile unsigned char*)(adr));
  260. if (value)
  261. temp |= (1<<bit_nr);
  262. else
  263. temp &= ~(1<<bit_nr);
  264. (*(volatile unsigned char*)(adr))=temp;
  265. }
  266. /*
  267. * transfer image from BMP-File
  268. */
  269. void transfer_pic(int display, unsigned char *adr, int height, int width)
  270. {
  271. int x, y;
  272. unsigned char temp;
  273. for (; height > 0; height -= 18)
  274. {
  275. if (height > 18)
  276. y = 18;
  277. else
  278. y = height;
  279. for (; y > 0; y--)
  280. {
  281. for (x = 0; x < width; x += 2)
  282. {
  283. temp = *adr++;
  284. set_vfd_pixel(x, y-1, 0, display, 0);
  285. set_vfd_pixel(x, y-1, 1, display, 0);
  286. if ((temp >> 4) == BLAU)
  287. set_vfd_pixel(x, y-1, 0, display, 1);
  288. else if ((temp >> 4) == ROT)
  289. set_vfd_pixel(x, y-1, 1, display, 1);
  290. else if ((temp >> 4) == VIOLETT)
  291. {
  292. set_vfd_pixel(x, y-1, 0, display, 1);
  293. set_vfd_pixel(x, y-1, 1, display, 1);
  294. }
  295. set_vfd_pixel(x+1, y-1, 0, display, 0);
  296. set_vfd_pixel(x+1, y-1, 1, display, 0);
  297. if ((temp & 0x0F) == BLAU)
  298. set_vfd_pixel(x+1, y-1, 0, display, 1);
  299. else if ((temp & 0x0F) == ROT)
  300. set_vfd_pixel(x+1, y-1, 1, display, 1);
  301. else if ((temp & 0x0F) == VIOLETT)
  302. {
  303. set_vfd_pixel(x+1, y-1, 0, display, 1);
  304. set_vfd_pixel(x+1, y-1, 1, display, 1);
  305. }
  306. }
  307. }
  308. if (display > 0)
  309. display--;
  310. else
  311. display = 3;
  312. }
  313. }
  314. /*
  315. * This function initializes VFD clock that is needed for the CPLD that
  316. * manages the keyboard.
  317. */
  318. int vfd_init_clocks (void)
  319. {
  320. int i;
  321. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  322. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  323. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  324. /* try to determine display type from the value
  325. * defined by pull-ups
  326. */
  327. gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */
  328. gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */
  329. /* allow signals to settle */
  330. for (i=0; i<10000; i++) /* udelay isn't working yet at this point! */
  331. __asm("NOP");
  332. vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */
  333. VFD_DISABLE; /* activate blank for the vfd */
  334. #define NEW_CPLD_CLK
  335. #ifdef NEW_CPLD_CLK
  336. if (vfd_board_id) {
  337. /* If new board revision, then use PWM 3 as cpld-clock */
  338. /* Enable 500 Hz timer for fill level sensor to operate properly */
  339. /* Configure TOUT3 as functional pin, disable pull-up */
  340. gpio->PDCON &= ~0x30000;
  341. gpio->PDCON |= 0x20000;
  342. gpio->PDUP |= (1 << 8);
  343. /* Configure the prescaler */
  344. timers->TCFG0 &= ~0xff00;
  345. timers->TCFG0 |= 0x0f00;
  346. /* Select MUX input (divider) for timer3 (1/16) */
  347. timers->TCFG1 &= ~0xf000;
  348. timers->TCFG1 |= 0x3000;
  349. /* Enable autoreload and set the counter and compare
  350. * registers to values for the 500 Hz clock
  351. * (for a given prescaler (15) and divider (16)):
  352. * counter = (66000000 / 500) >> 9;
  353. */
  354. timers->ch[3].TCNTB = 0x101;
  355. timers->ch[3].TCMPB = 0x101 / 2;
  356. /* Start timer */
  357. timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3;
  358. timers->TCON = (timers->TCON | START3) & ~UPDATE3;
  359. }
  360. #endif
  361. /* If old board revision, then use vm-signal as cpld-clock */
  362. lcd->LCDCON2 = 0x00FFC000;
  363. lcd->LCDCON3 = 0x0007FF00;
  364. lcd->LCDCON4 = 0x00000000;
  365. lcd->LCDCON5 = 0x00000400;
  366. lcd->LCDCON1 = 0x00000B75;
  367. /* VM (GPD1) is used as clock for the CPLD */
  368. gpio->PDCON = (gpio->PDCON & 0xFFFFFFF3) | 0x00000008;
  369. return 0;
  370. }
  371. /*
  372. * initialize LCD-Controller of the S3C2400 for using VFDs
  373. *
  374. * VFD detection depends on the board revision:
  375. * starting from Rev. 200 a type code can be read from the data pins,
  376. * driven by some pull-up resistors; all earlier systems must be
  377. * manually configured. The type is set in the "vfd_type" environment
  378. * variable.
  379. */
  380. int drv_vfd_init(void)
  381. {
  382. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  383. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  384. char *tmp;
  385. ulong palette;
  386. static int vfd_init_done = 0;
  387. int vfd_inv_data = 0;
  388. if (vfd_init_done != 0)
  389. return (0);
  390. vfd_init_done = 1;
  391. debug("Detecting Revison of WA4-VFD: ID=0x%X\n", vfd_board_id);
  392. switch (vfd_board_id) {
  393. case 0: /* board revision < Rev.200 */
  394. if ((tmp = getenv ("vfd_type")) == NULL) {
  395. break;
  396. }
  397. if (strcmp(tmp, "T119C") == 0) {
  398. gd->vfd_type = VFD_TYPE_T119C;
  399. } else if (strcmp(tmp, "MN11236") == 0) {
  400. gd->vfd_type = VFD_TYPE_MN11236;
  401. } else {
  402. /* cannot use printf for a warning here */
  403. gd->vfd_type = 0; /* unknown */
  404. }
  405. break;
  406. default: /* default to MN11236, data inverted */
  407. gd->vfd_type = VFD_TYPE_MN11236;
  408. vfd_inv_data = 1;
  409. setenv ("vfd_type", "MN11236");
  410. }
  411. debug ("VFD type: %s%s\n",
  412. (gd->vfd_type == VFD_TYPE_T119C) ? "T119C" :
  413. (gd->vfd_type == VFD_TYPE_MN11236) ? "MN11236" :
  414. "unknown",
  415. vfd_inv_data ? ", inverted data" : "");
  416. gd->fb_base = gd->fb_base;
  417. create_vfd_table();
  418. init_grid_ctrl();
  419. for (palette=0; palette < 16; palette++)
  420. (*(volatile unsigned int*)(PALETTE+(palette*4)))=palette;
  421. for (palette=16; palette < 256; palette++)
  422. (*(volatile unsigned int*)(PALETTE+(palette*4)))=0x00;
  423. /*
  424. * Hinweis: Der Framebuffer ist um genau ein Nibble verschoben
  425. * Das erste angezeigte Pixel wird aus dem zweiten Nibble geholt
  426. * das letzte angezeigte Pixel wird aus dem ersten Nibble geholt
  427. * (wrap around)
  428. * see manual S3C2400
  429. */
  430. /* Stopp LCD-Controller */
  431. lcd->LCDCON1 = 0x00000000;
  432. /* frame buffer startadr */
  433. lcd->LCDSADDR1 = gd->fb_base >> 1;
  434. /* frame buffer endadr */
  435. lcd->LCDSADDR2 = (gd->fb_base + FRAME_BUF_SIZE) >> 1;
  436. lcd->LCDSADDR3 = ((256/4));
  437. lcd->LCDCON2 = 0x000DC000;
  438. if(gd->vfd_type == VFD_TYPE_MN11236)
  439. lcd->LCDCON2 = 37 << 14; /* MN11236: 38 lines */
  440. else
  441. lcd->LCDCON2 = 55 << 14; /* T119C: 56 lines */
  442. lcd->LCDCON3 = 0x0051000A;
  443. lcd->LCDCON4 = 0x00000001;
  444. if (gd->vfd_type && vfd_inv_data)
  445. lcd->LCDCON5 = 0x000004C0;
  446. else
  447. lcd->LCDCON5 = 0x00000440;
  448. /* Port pins as LCD output */
  449. gpio->PCCON = (gpio->PCCON & 0xFFFFFF00)| 0x000000AA;
  450. gpio->PDCON = (gpio->PDCON & 0xFFFFFF03)| 0x000000A8;
  451. /* Synchronize VFD enable with LCD controller to avoid flicker */
  452. lcd->LCDCON1 = 0x00000B75; /* Start LCD-Controller */
  453. while((lcd->LCDCON5 & 0x180000)!=0x100000); /* Wait for end of VSYNC */
  454. while((lcd->LCDCON5 & 0x060000)!=0x040000); /* Wait for next HSYNC */
  455. while((lcd->LCDCON5 & 0x060000)==0x040000);
  456. while((lcd->LCDCON5 & 0x060000)!=0x000000);
  457. if(gd->vfd_type)
  458. VFD_ENABLE;
  459. debug ("LCDSADDR1: %lX\n", lcd->LCDSADDR1);
  460. debug ("LCDSADDR2: %lX\n", lcd->LCDSADDR2);
  461. debug ("LCDSADDR3: %lX\n", lcd->LCDSADDR3);
  462. return 0;
  463. }
  464. /*
  465. * Disable VFD: should be run before resetting the system:
  466. * disable VM, enable pull-up
  467. */
  468. void disable_vfd (void)
  469. {
  470. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  471. VFD_DISABLE;
  472. gpio->PDCON &= ~0xC;
  473. gpio->PDUP &= ~0x2;
  474. }
  475. /************************************************************************/
  476. /* ** ROM capable initialization part - needed to reserve FB memory */
  477. /************************************************************************/
  478. /*
  479. * This is called early in the system initialization to grab memory
  480. * for the VFD controller.
  481. *
  482. * Note that this is running from ROM, so no write access to global data.
  483. */
  484. ulong vfd_setmem (ulong addr)
  485. {
  486. ulong size;
  487. /* Round up to nearest full page */
  488. size = (FRAME_BUF_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  489. debug ("Reserving %ldk for VFD Framebuffer at: %08lx\n", size>>10, addr);
  490. return (size);
  491. }
  492. /*
  493. * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
  494. * descriptors and palette areas.
  495. */
  496. ulong calc_fbsize (void)
  497. {
  498. return FRAME_BUF_SIZE;
  499. }
  500. #endif /* CONFIG_VFD */