lcd.c 7.6 KB

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