lcd.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * (C) Copyright 2003-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * (C) Copyright 2005
  6. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include "lcd.h"
  27. extern int video_display_bitmap (ulong, int, int);
  28. int palette_index;
  29. int palette_value;
  30. int lcd_depth;
  31. unsigned char *glob_lcd_reg;
  32. unsigned char *glob_lcd_mem;
  33. #ifdef CFG_LCD_ENDIAN
  34. void lcd_setup(int lcd, int config)
  35. {
  36. if (lcd == 0) {
  37. /*
  38. * Set endianess and reset lcd controller 0 (small)
  39. */
  40. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
  41. udelay(10); /* wait 10us */
  42. if (config == 1) {
  43. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
  44. } else {
  45. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
  46. }
  47. udelay(10); /* wait 10us */
  48. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */
  49. } else {
  50. /*
  51. * Set endianess and reset lcd controller 1 (big)
  52. */
  53. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */
  54. udelay(10); /* wait 10us */
  55. if (config == 1) {
  56. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
  57. } else {
  58. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
  59. }
  60. udelay(10); /* wait 10us */
  61. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */
  62. }
  63. /*
  64. * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive
  65. */
  66. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
  67. }
  68. #endif /* #ifdef CFG_LCD_ENDIAN */
  69. void lcd_bmp(uchar *logo_bmp)
  70. {
  71. int i;
  72. uchar *ptr;
  73. ushort *ptr2;
  74. ushort val;
  75. unsigned char *dst;
  76. int x, y;
  77. int width, height, bpp, colors, line_size;
  78. int header_size;
  79. unsigned char *bmp;
  80. unsigned char r, g, b;
  81. BITMAPINFOHEADER *bm_info;
  82. ulong len;
  83. int do_free = 0;
  84. /*
  85. * Check for bmp mark 'BM'
  86. */
  87. if (*(ushort *)logo_bmp != 0x424d) {
  88. /*
  89. * Decompress bmp image
  90. */
  91. len = CFG_VIDEO_LOGO_MAX_SIZE;
  92. dst = malloc(CFG_LCD_LOGO_MAX_SIZE);
  93. do_free = 1;
  94. if (gunzip(dst, CFG_LCD_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
  95. return;
  96. }
  97. /*
  98. * Check for bmp mark 'BM'
  99. */
  100. if (*(ushort *)dst != 0x424d) {
  101. printf("LCD: Unknown image format!\n");
  102. free(dst);
  103. return;
  104. }
  105. } else {
  106. /*
  107. * Uncompressed BMP image, just use this pointer
  108. */
  109. dst = (uchar *)logo_bmp;
  110. }
  111. /*
  112. * Get image info from bmp-header
  113. */
  114. bm_info = (BITMAPINFOHEADER *)(dst + 14);
  115. bpp = LOAD_SHORT(bm_info->biBitCount);
  116. width = LOAD_LONG(bm_info->biWidth);
  117. height = LOAD_LONG(bm_info->biHeight);
  118. switch (bpp) {
  119. case 1:
  120. colors = 1;
  121. line_size = width >> 3;
  122. break;
  123. case 4:
  124. colors = 16;
  125. line_size = width >> 1;
  126. break;
  127. case 8:
  128. colors = 256;
  129. line_size = width;
  130. break;
  131. case 24:
  132. colors = 0;
  133. line_size = width * 3;
  134. break;
  135. default:
  136. printf("LCD: Unknown bpp (%d) im image!\n", bpp);
  137. free(dst);
  138. return;
  139. }
  140. printf(" (%d*%d, %dbpp)\n", width, height, bpp);
  141. /*
  142. * Write color palette
  143. */
  144. if ((colors <= 256) && (lcd_depth <= 8)) {
  145. ptr = (unsigned char *)(dst + 14 + 40);
  146. for (i=0; i<colors; i++) {
  147. b = *ptr++;
  148. g = *ptr++;
  149. r = *ptr++;
  150. ptr++;
  151. S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
  152. }
  153. }
  154. /*
  155. * Write bitmap data into framebuffer
  156. */
  157. ptr = glob_lcd_mem;
  158. ptr2 = (ushort *)glob_lcd_mem;
  159. header_size = 14 + 40 + 4*colors; /* skip bmp header */
  160. for (y=0; y<height; y++) {
  161. bmp = &dst[(height-1-y)*line_size + header_size];
  162. if (lcd_depth == 16) {
  163. if (bpp == 24) {
  164. for (x=0; x<width; x++) {
  165. /*
  166. * Generate epson 16bpp fb-format from 24bpp image
  167. */
  168. b = *bmp++ >> 3;
  169. g = *bmp++ >> 2;
  170. r = *bmp++ >> 3;
  171. val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
  172. *ptr2++ = val;
  173. }
  174. } else if (bpp == 8) {
  175. for (x=0; x<line_size; x++) {
  176. /* query rgb value from palette */
  177. ptr = (unsigned char *)(dst + 14 + 40) ;
  178. ptr += (*bmp++) << 2;
  179. b = *ptr++ >> 3;
  180. g = *ptr++ >> 2;
  181. r = *ptr++ >> 3;
  182. val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
  183. *ptr2++ = val;
  184. }
  185. }
  186. } else {
  187. for (x=0; x<line_size; x++) {
  188. *ptr++ = *bmp++;
  189. }
  190. }
  191. }
  192. if (do_free) {
  193. free(dst);
  194. }
  195. }
  196. void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
  197. uchar *logo_bmp, ulong len)
  198. {
  199. int i;
  200. ushort s1dReg;
  201. uchar s1dValue;
  202. int reg_byte_swap;
  203. /*
  204. * Detect epson
  205. */
  206. if (lcd_reg[0] == 0x1c) {
  207. /*
  208. * Big epson detected
  209. */
  210. reg_byte_swap = FALSE;
  211. palette_index = 0x1e2;
  212. palette_value = 0x1e4;
  213. lcd_depth = 16;
  214. puts("LCD: S1D13806");
  215. } else if (lcd_reg[1] == 0x1c) {
  216. /*
  217. * Big epson detected (with register swap bug)
  218. */
  219. reg_byte_swap = TRUE;
  220. palette_index = 0x1e3;
  221. palette_value = 0x1e5;
  222. lcd_depth = 16;
  223. puts("LCD: S1D13806S");
  224. } else if (lcd_reg[0] == 0x18) {
  225. /*
  226. * Small epson detected (704)
  227. */
  228. reg_byte_swap = FALSE;
  229. palette_index = 0x15;
  230. palette_value = 0x17;
  231. lcd_depth = 8;
  232. puts("LCD: S1D13704");
  233. } else if (lcd_reg[0x10000] == 0x24) {
  234. /*
  235. * Small epson detected (705)
  236. */
  237. reg_byte_swap = FALSE;
  238. palette_index = 0x15;
  239. palette_value = 0x17;
  240. lcd_depth = 8;
  241. lcd_reg += 0x10000; /* add offset for 705 regs */
  242. puts("LCD: S1D13705");
  243. } else {
  244. puts("LCD: No controller detected!\n");
  245. return;
  246. }
  247. /*
  248. * Setup lcd controller regs
  249. */
  250. for (i = 0; i<reg_count; i++) {
  251. s1dReg = regs[i].Index;
  252. if (reg_byte_swap) {
  253. if ((s1dReg & 0x0001) == 0)
  254. s1dReg |= 0x0001;
  255. else
  256. s1dReg &= ~0x0001;
  257. }
  258. s1dValue = regs[i].Value;
  259. lcd_reg[s1dReg] = s1dValue;
  260. }
  261. /*
  262. * Save reg & mem pointer for later usage (e.g. bmp command)
  263. */
  264. glob_lcd_reg = lcd_reg;
  265. glob_lcd_mem = lcd_mem;
  266. /*
  267. * Display bmp image
  268. */
  269. lcd_bmp(logo_bmp);
  270. }
  271. int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  272. {
  273. ulong addr;
  274. char *str;
  275. if (argc != 2) {
  276. printf ("Usage:\n%s\n", cmdtp->usage);
  277. return 1;
  278. }
  279. addr = simple_strtoul(argv[1], NULL, 16);
  280. str = getenv("bd_type");
  281. if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
  282. /*
  283. * SM501 available, use standard bmp command
  284. */
  285. return (video_display_bitmap(addr, 0, 0));
  286. } else {
  287. /*
  288. * No SM501 available, use esd epson bmp command
  289. */
  290. lcd_bmp((uchar *)addr);
  291. return 0;
  292. }
  293. }
  294. U_BOOT_CMD(
  295. esdbmp, 2, 1, do_esdbmp,
  296. "esdbmp - display BMP image\n",
  297. "<imageAddr> - display image\n"
  298. );