lcd.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. #ifdef 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. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
  42. udelay(10); /* wait 10us */
  43. if (config == 1)
  44. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
  45. else
  46. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
  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. udelay(10); /* wait 10us */
  60. out32(GPIO0_OR, in32(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. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
  66. }
  67. #endif /* #ifdef 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. }
  195. if ((dst != NULL) && (dst != (uchar *)logo_bmp))
  196. free(dst);
  197. }
  198. void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
  199. uchar *logo_bmp, ulong len)
  200. {
  201. int i;
  202. ushort s1dReg;
  203. uchar s1dValue;
  204. int reg_byte_swap;
  205. /*
  206. * Detect epson
  207. */
  208. out_8(&lcd_reg[0], 0x00);
  209. out_8(&lcd_reg[1], 0x00);
  210. if (in_8(&lcd_reg[0]) == 0x1c) {
  211. /*
  212. * Big epson detected
  213. */
  214. reg_byte_swap = FALSE;
  215. palette_index = 0x1e2;
  216. palette_value = 0x1e4;
  217. lcd_depth = 16;
  218. puts("LCD: S1D13806");
  219. } else if (in_8(&lcd_reg[1]) == 0x1c) {
  220. /*
  221. * Big epson detected (with register swap bug)
  222. */
  223. reg_byte_swap = TRUE;
  224. palette_index = 0x1e3;
  225. palette_value = 0x1e5;
  226. lcd_depth = 16;
  227. puts("LCD: S1D13806S");
  228. } else if (in_8(&lcd_reg[0]) == 0x18) {
  229. /*
  230. * Small epson detected (704)
  231. */
  232. reg_byte_swap = FALSE;
  233. palette_index = 0x15;
  234. palette_value = 0x17;
  235. lcd_depth = 8;
  236. puts("LCD: S1D13704");
  237. } else if (in_8(&lcd_reg[0x10000]) == 0x24) {
  238. /*
  239. * Small epson detected (705)
  240. */
  241. reg_byte_swap = FALSE;
  242. palette_index = 0x15;
  243. palette_value = 0x17;
  244. lcd_depth = 8;
  245. lcd_reg += 0x10000; /* add offset for 705 regs */
  246. puts("LCD: S1D13705");
  247. } else {
  248. puts("LCD: No controller detected!\n");
  249. return;
  250. }
  251. /*
  252. * Setup lcd controller regs
  253. */
  254. for (i = 0; i < reg_count; i++) {
  255. s1dReg = regs[i].Index;
  256. if (reg_byte_swap) {
  257. if ((s1dReg & 0x0001) == 0)
  258. s1dReg |= 0x0001;
  259. else
  260. s1dReg &= ~0x0001;
  261. }
  262. s1dValue = regs[i].Value;
  263. lcd_reg[s1dReg] = s1dValue;
  264. }
  265. /*
  266. * Save reg & mem pointer for later usage (e.g. bmp command)
  267. */
  268. glob_lcd_reg = lcd_reg;
  269. glob_lcd_mem = lcd_mem;
  270. /*
  271. * Display bmp image
  272. */
  273. lcd_bmp(logo_bmp);
  274. }
  275. #ifdef CONFIG_VIDEO_SM501
  276. int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  277. {
  278. ulong addr;
  279. char *str;
  280. if (argc != 2) {
  281. printf ("Usage:\n%s\n", cmdtp->usage);
  282. return 1;
  283. }
  284. addr = simple_strtoul(argv[1], NULL, 16);
  285. str = getenv("bd_type");
  286. if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) {
  287. /*
  288. * SM501 available, use standard bmp command
  289. */
  290. return (video_display_bitmap(addr, 0, 0));
  291. } else {
  292. /*
  293. * No SM501 available, use esd epson bmp command
  294. */
  295. lcd_bmp((uchar *)addr);
  296. return 0;
  297. }
  298. }
  299. U_BOOT_CMD(
  300. esdbmp, 2, 1, do_esdbmp,
  301. "esdbmp - display BMP image\n",
  302. "<imageAddr> - display image\n"
  303. );
  304. #endif