lcd.c 7.5 KB

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