lcd.c 8.1 KB

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