lcd.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 = NULL;
  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. /*
  84. * Check for bmp mark 'BM'
  85. */
  86. if (*(ushort *)logo_bmp != 0x424d) {
  87. /*
  88. * Decompress bmp image
  89. */
  90. len = CFG_VIDEO_LOGO_MAX_SIZE;
  91. dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
  92. if (dst == NULL) {
  93. printf("Error: malloc in gunzip failed!\n");
  94. return;
  95. }
  96. if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
  97. return;
  98. }
  99. if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
  100. printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
  101. }
  102. /*
  103. * Check for bmp mark 'BM'
  104. */
  105. if (*(ushort *)dst != 0x424d) {
  106. printf("LCD: Unknown image format!\n");
  107. free(dst);
  108. return;
  109. }
  110. } else {
  111. /*
  112. * Uncompressed BMP image, just use this pointer
  113. */
  114. dst = (uchar *)logo_bmp;
  115. }
  116. /*
  117. * Get image info from bmp-header
  118. */
  119. bm_info = (BITMAPINFOHEADER *)(dst + 14);
  120. bpp = LOAD_SHORT(bm_info->biBitCount);
  121. width = LOAD_LONG(bm_info->biWidth);
  122. height = LOAD_LONG(bm_info->biHeight);
  123. switch (bpp) {
  124. case 1:
  125. colors = 1;
  126. line_size = width >> 3;
  127. break;
  128. case 4:
  129. colors = 16;
  130. line_size = width >> 1;
  131. break;
  132. case 8:
  133. colors = 256;
  134. line_size = width;
  135. break;
  136. case 24:
  137. colors = 0;
  138. line_size = width * 3;
  139. break;
  140. default:
  141. printf("LCD: Unknown bpp (%d) im image!\n", bpp);
  142. if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
  143. free(dst);
  144. }
  145. return;
  146. }
  147. printf(" (%d*%d, %dbpp)\n", width, height, bpp);
  148. /*
  149. * Write color palette
  150. */
  151. if ((colors <= 256) && (lcd_depth <= 8)) {
  152. ptr = (unsigned char *)(dst + 14 + 40);
  153. for (i=0; i<colors; i++) {
  154. b = *ptr++;
  155. g = *ptr++;
  156. r = *ptr++;
  157. ptr++;
  158. S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b);
  159. }
  160. }
  161. /*
  162. * Write bitmap data into framebuffer
  163. */
  164. ptr = glob_lcd_mem;
  165. ptr2 = (ushort *)glob_lcd_mem;
  166. header_size = 14 + 40 + 4*colors; /* skip bmp header */
  167. for (y=0; y<height; y++) {
  168. bmp = &dst[(height-1-y)*line_size + header_size];
  169. if (lcd_depth == 16) {
  170. if (bpp == 24) {
  171. for (x=0; x<width; x++) {
  172. /*
  173. * Generate epson 16bpp fb-format from 24bpp image
  174. */
  175. b = *bmp++ >> 3;
  176. g = *bmp++ >> 2;
  177. r = *bmp++ >> 3;
  178. val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
  179. *ptr2++ = val;
  180. }
  181. } else if (bpp == 8) {
  182. for (x=0; x<line_size; x++) {
  183. /* query rgb value from palette */
  184. ptr = (unsigned char *)(dst + 14 + 40) ;
  185. ptr += (*bmp++) << 2;
  186. b = *ptr++ >> 3;
  187. g = *ptr++ >> 2;
  188. r = *ptr++ >> 3;
  189. val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
  190. *ptr2++ = val;
  191. }
  192. }
  193. } else {
  194. for (x=0; x<line_size; x++) {
  195. *ptr++ = *bmp++;
  196. }
  197. }
  198. }
  199. if ((dst != NULL) && (dst != (uchar *)logo_bmp)) {
  200. free(dst);
  201. }
  202. }
  203. void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
  204. uchar *logo_bmp, ulong len)
  205. {
  206. int i;
  207. ushort s1dReg;
  208. uchar s1dValue;
  209. int reg_byte_swap;
  210. /*
  211. * Detect epson
  212. */
  213. if (lcd_reg[0] == 0x1c) {
  214. /*
  215. * Big epson detected
  216. */
  217. reg_byte_swap = FALSE;
  218. palette_index = 0x1e2;
  219. palette_value = 0x1e4;
  220. lcd_depth = 16;
  221. puts("LCD: S1D13806");
  222. } else if (lcd_reg[1] == 0x1c) {
  223. /*
  224. * Big epson detected (with register swap bug)
  225. */
  226. reg_byte_swap = TRUE;
  227. palette_index = 0x1e3;
  228. palette_value = 0x1e5;
  229. lcd_depth = 16;
  230. puts("LCD: S1D13806S");
  231. } else if (lcd_reg[0] == 0x18) {
  232. /*
  233. * Small epson detected (704)
  234. */
  235. reg_byte_swap = FALSE;
  236. palette_index = 0x15;
  237. palette_value = 0x17;
  238. lcd_depth = 8;
  239. puts("LCD: S1D13704");
  240. } else if (lcd_reg[0x10000] == 0x24) {
  241. /*
  242. * Small epson detected (705)
  243. */
  244. reg_byte_swap = FALSE;
  245. palette_index = 0x15;
  246. palette_value = 0x17;
  247. lcd_depth = 8;
  248. lcd_reg += 0x10000; /* add offset for 705 regs */
  249. puts("LCD: S1D13705");
  250. } else {
  251. puts("LCD: No controller detected!\n");
  252. return;
  253. }
  254. /*
  255. * Setup lcd controller regs
  256. */
  257. for (i = 0; i<reg_count; i++) {
  258. s1dReg = regs[i].Index;
  259. if (reg_byte_swap) {
  260. if ((s1dReg & 0x0001) == 0)
  261. s1dReg |= 0x0001;
  262. else
  263. s1dReg &= ~0x0001;
  264. }
  265. s1dValue = regs[i].Value;
  266. lcd_reg[s1dReg] = s1dValue;
  267. }
  268. /*
  269. * Save reg & mem pointer for later usage (e.g. bmp command)
  270. */
  271. glob_lcd_reg = lcd_reg;
  272. glob_lcd_mem = lcd_mem;
  273. /*
  274. * Display bmp image
  275. */
  276. lcd_bmp(logo_bmp);
  277. }
  278. #ifdef CONFIG_VIDEO_SM501
  279. int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  280. {
  281. ulong addr;
  282. char *str;
  283. if (argc != 2) {
  284. printf ("Usage:\n%s\n", cmdtp->usage);
  285. return 1;
  286. }
  287. addr = simple_strtoul(argv[1], NULL, 16);
  288. str = getenv("bd_type");
  289. if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
  290. /*
  291. * SM501 available, use standard bmp command
  292. */
  293. return (video_display_bitmap(addr, 0, 0));
  294. } else {
  295. /*
  296. * No SM501 available, use esd epson bmp command
  297. */
  298. lcd_bmp((uchar *)addr);
  299. return 0;
  300. }
  301. }
  302. U_BOOT_CMD(
  303. esdbmp, 2, 1, do_esdbmp,
  304. "esdbmp - display BMP image\n",
  305. "<imageAddr> - display image\n"
  306. );
  307. #endif