vfd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. #ifdef CONFIG_VFD
  38. /************************************************************************/
  39. /* ** CONFIG STUFF -- should be moved to board config file */
  40. /************************************************************************/
  41. /************************************************************************/
  42. #ifndef PAGE_SIZE
  43. #define PAGE_SIZE 4096
  44. #endif
  45. #define ROT 0x09
  46. #define BLAU 0x0C
  47. #define VIOLETT 0X0D
  48. /* MAGIC */
  49. #define FRAME_BUF_SIZE ((256*4*56)/8)
  50. #define frame_buf_offs 4
  51. /* defines for starting Timer3 as CPLD-Clk */
  52. #define START3 (1 << 16)
  53. #define UPDATE3 (1 << 17)
  54. #define INVERT3 (1 << 18)
  55. #define RELOAD3 (1 << 19)
  56. /* CPLD-Register for controlling vfd-blank-signal */
  57. #define VFD_DISABLE (*(volatile uchar *)0x04038000=0x0000)
  58. #define VFD_ENABLE (*(volatile uchar *)0x04038000=0x0001)
  59. /* Supported VFD Types */
  60. #define VFD_TYPE_T119C 1 /* Noritake T119C VFD */
  61. #define VFD_TYPE_MN11236 2
  62. /*#define NEW_CPLD_CLK*/
  63. int vfd_board_id;
  64. /* taken from armboot/common/vfd.c */
  65. unsigned long adr_vfd_table[112][18][2][4][2];
  66. unsigned char bit_vfd_table[112][18][2][4][2];
  67. /*
  68. * initialize the values for the VFD-grid-control in the framebuffer
  69. */
  70. void init_grid_ctrl(void)
  71. {
  72. DECLARE_GLOBAL_DATA_PTR;
  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. DECLARE_GLOBAL_DATA_PTR;
  153. unsigned long vfd_table[112][18][2][4][2];
  154. unsigned int x, y, color, display, entry, pixel;
  155. unsigned int x_abcdef = 0;
  156. switch (gd->vfd_type) {
  157. case VFD_TYPE_T119C:
  158. for(y=0; y<=17; y++) { /* Line */
  159. for(x=0; x<=111; x++) { /* Column */
  160. for(display=0; display <=3; display++) {
  161. /* Display 0 blue pixels */
  162. vfd_table[x][y][0][display][0] =
  163. (x==0) ? y*16+display
  164. : (x%4)*4+y*16+((x-1)/2)*1024+display;
  165. /* Display 0 red pixels */
  166. vfd_table[x][y][1][display][0] =
  167. (x==0) ? y*16+512+display
  168. : (x%4)*4+y*16+((x-1)/2)*1024+512+display;
  169. }
  170. }
  171. }
  172. break;
  173. case VFD_TYPE_MN11236:
  174. for(y=0; y<=17; y++) { /* Line */
  175. for(x=0; x<=111; x++) { /* Column */
  176. for(display=0; display <=3; display++) {
  177. vfd_table[x][y][0][display][0]=0;
  178. vfd_table[x][y][0][display][1]=0;
  179. vfd_table[x][y][1][display][0]=0;
  180. vfd_table[x][y][1][display][1]=0;
  181. switch (x%6) {
  182. case 0: x_abcdef=0; break; /* a -> a */
  183. case 1: x_abcdef=2; break; /* b -> c */
  184. case 2: x_abcdef=4; break; /* c -> e */
  185. case 3: x_abcdef=5; break; /* d -> f */
  186. case 4: x_abcdef=3; break; /* e -> d */
  187. case 5: x_abcdef=1; break; /* f -> b */
  188. }
  189. /* blue pixels */
  190. vfd_table[x][y][0][display][0] =
  191. (x>1) ? x_abcdef*4+((x-1)/3)*1024+y*48+display
  192. : x_abcdef*4+ 0+y*48+display;
  193. /* blue pixels */
  194. if (x>1 && (x-1)%3)
  195. vfd_table[x][y][0][display][1] = x_abcdef*4+((x-1)/3+1)*1024+y*48+display;
  196. /* red pixels */
  197. vfd_table[x][y][1][display][0] =
  198. (x>1) ? x_abcdef*4+24+((x-1)/3)*1024+y*48+display
  199. : x_abcdef*4+24+ 0+y*48+display;
  200. /* red pixels */
  201. if (x>1 && (x-1)%3)
  202. vfd_table[x][y][1][display][1] = x_abcdef*4+24+((x-1)/3+1)*1024+y*48+display;
  203. }
  204. }
  205. }
  206. break;
  207. default:
  208. /* do nothing */
  209. return;
  210. }
  211. /*
  212. * Create table with entries for physical byte adresses and
  213. * bit-number within the byte
  214. * from table with bit-numbers within the total framebuffer
  215. */
  216. for(y=0;y<18;y++) {
  217. for(x=0;x<112;x++) {
  218. for(color=0;color<2;color++) {
  219. for(display=0;display<4;display++) {
  220. for(entry=0;entry<2;entry++) {
  221. unsigned long adr = gd->fb_base;
  222. unsigned int bit_nr = 0;
  223. if (vfd_table[x][y][color][display][entry]) {
  224. pixel = vfd_table[x][y][color][display][entry] + frame_buf_offs;
  225. /*
  226. * wrap arround if offset
  227. * (see manual S3C2400)
  228. */
  229. if (pixel>=FRAME_BUF_SIZE*8)
  230. pixel = pixel-(FRAME_BUF_SIZE*8);
  231. adr = gd->fb_base+(pixel/32)*4+(3-(pixel%32)/8);
  232. bit_nr = pixel%8;
  233. bit_nr = (bit_nr>3)?bit_nr-4:bit_nr+4;
  234. }
  235. adr_vfd_table[x][y][color][display][entry] = adr;
  236. bit_vfd_table[x][y][color][display][entry] = bit_nr;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. /*
  244. * Set/clear pixel of the VFDs
  245. */
  246. void set_vfd_pixel(unsigned char x, unsigned char y,
  247. unsigned char color, unsigned char display,
  248. unsigned char value)
  249. {
  250. DECLARE_GLOBAL_DATA_PTR;
  251. ulong adr;
  252. unsigned char bit_nr, temp;
  253. if (! gd->vfd_type) {
  254. /* Unknown type. */
  255. return;
  256. }
  257. /* Pixel-Eintrag Nr. 1 */
  258. adr = adr_vfd_table[x][y][color][display][0];
  259. /* Pixel-Eintrag Nr. 1 */
  260. bit_nr = bit_vfd_table[x][y][color][display][0];
  261. temp=(*(volatile unsigned char*)(adr));
  262. if (value)
  263. temp |= (1<<bit_nr);
  264. else
  265. temp &= ~(1<<bit_nr);
  266. (*(volatile unsigned char*)(adr))=temp;
  267. }
  268. /*
  269. * transfer image from BMP-File
  270. */
  271. void transfer_pic(int display, unsigned char *adr, int height, int width)
  272. {
  273. int x, y;
  274. unsigned char temp;
  275. for (; height > 0; height -= 18)
  276. {
  277. if (height > 18)
  278. y = 18;
  279. else
  280. y = height;
  281. for (; y > 0; y--)
  282. {
  283. for (x = 0; x < width; x += 2)
  284. {
  285. temp = *adr++;
  286. set_vfd_pixel(x, y-1, 0, display, 0);
  287. set_vfd_pixel(x, y-1, 1, display, 0);
  288. if ((temp >> 4) == BLAU)
  289. set_vfd_pixel(x, y-1, 0, display, 1);
  290. else if ((temp >> 4) == ROT)
  291. set_vfd_pixel(x, y-1, 1, display, 1);
  292. else if ((temp >> 4) == VIOLETT)
  293. {
  294. set_vfd_pixel(x, y-1, 0, display, 1);
  295. set_vfd_pixel(x, y-1, 1, display, 1);
  296. }
  297. set_vfd_pixel(x+1, y-1, 0, display, 0);
  298. set_vfd_pixel(x+1, y-1, 1, display, 0);
  299. if ((temp & 0x0F) == BLAU)
  300. set_vfd_pixel(x+1, y-1, 0, display, 1);
  301. else if ((temp & 0x0F) == ROT)
  302. set_vfd_pixel(x+1, y-1, 1, display, 1);
  303. else if ((temp & 0x0F) == VIOLETT)
  304. {
  305. set_vfd_pixel(x+1, y-1, 0, display, 1);
  306. set_vfd_pixel(x+1, y-1, 1, display, 1);
  307. }
  308. }
  309. }
  310. if (display > 0)
  311. display--;
  312. else
  313. display = 3;
  314. }
  315. }
  316. /*
  317. * This function initializes VFD clock that is needed for the CPLD that
  318. * manages the keyboard.
  319. */
  320. int vfd_init_clocks (void)
  321. {
  322. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  323. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  324. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  325. /* try to determine display type from the value
  326. * defined by pull-ups
  327. */
  328. gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pullups */
  329. gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as inputs */
  330. udelay (10); /* allow signals to settle */
  331. vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */
  332. VFD_DISABLE; /* activate blank for the vfd */
  333. #define NEW_CPLD_CLK
  334. #ifdef NEW_CPLD_CLK
  335. if (vfd_board_id) {
  336. /* If new board revision, then use PWM 3 as cpld-clock */
  337. /* Enable 500 Hz timer for fill level sensor to operate properly */
  338. /* Configure TOUT3 as functional pin, disable pull-up */
  339. gpio->PDCON &= ~0x30000;
  340. gpio->PDCON |= 0x20000;
  341. gpio->PDUP |= (1 << 8);
  342. /* Configure the prescaler */
  343. timers->TCFG0 &= ~0xff00;
  344. timers->TCFG0 |= 0x0f00;
  345. /* Select MUX input (divider) for timer3 (1/16) */
  346. timers->TCFG1 &= ~0xf000;
  347. timers->TCFG1 |= 0x3000;
  348. /* Enable autoreload and set the counter and compare
  349. * registers to values for the 500 Hz clock
  350. * (for a given prescaler (15) and divider (16)):
  351. * counter = (66000000 / 500) >> 9;
  352. */
  353. timers->ch[3].TCNTB = 0x101;
  354. timers->ch[3].TCMPB = 0x101 / 2;
  355. /* Start timer */
  356. timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3;
  357. timers->TCON = (timers->TCON | START3) & ~UPDATE3;
  358. }
  359. #endif
  360. /* If old board revision, then use vm-signal as cpld-clock */
  361. lcd->LCDCON2 = 0x00FFC000;
  362. lcd->LCDCON3 = 0x0007FF00;
  363. lcd->LCDCON4 = 0x00000000;
  364. lcd->LCDCON5 = 0x00000400;
  365. lcd->LCDCON1 = 0x00000B75;
  366. /* VM (GPD1) is used as clock for the CPLD */
  367. gpio->PDCON = (gpio->PDCON & 0xFFFFFFF3) | 0x00000008;
  368. return 0;
  369. }
  370. /*
  371. * initialize LCD-Controller of the S3C2400 for using VFDs
  372. *
  373. * VFD detection depends on the board revision:
  374. * starting from Rev. 200 a type code can be read from the data pins,
  375. * driven by some pull-up resistors; all earlier systems must be
  376. * manually configured. The type is set in the "vfd_type" environment
  377. * variable.
  378. */
  379. int drv_vfd_init(void)
  380. {
  381. S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
  382. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  383. char *tmp;
  384. ulong palette;
  385. static int vfd_init_done = 0;
  386. int vfd_inv_data = 0;
  387. DECLARE_GLOBAL_DATA_PTR;
  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. #endif /* CONFIG_VFD */