lcd.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * (C) Copyright 2003-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include "lcd.h"
  24. int palette_index;
  25. int palette_value;
  26. #ifdef CFG_LCD_ENDIAN
  27. void lcd_setup(int lcd, int config)
  28. {
  29. if (lcd == 0) {
  30. /*
  31. * Set endianess and reset lcd controller 0 (small)
  32. */
  33. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */
  34. udelay(10); /* wait 10us */
  35. if (config == 1) {
  36. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
  37. } else {
  38. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
  39. }
  40. udelay(10); /* wait 10us */
  41. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */
  42. } else {
  43. /*
  44. * Set endianess and reset lcd controller 1 (big)
  45. */
  46. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */
  47. udelay(10); /* wait 10us */
  48. if (config == 1) {
  49. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */
  50. } else {
  51. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */
  52. }
  53. udelay(10); /* wait 10us */
  54. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */
  55. }
  56. /*
  57. * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive
  58. */
  59. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */
  60. }
  61. #endif /* #ifdef CFG_LCD_ENDIAN */
  62. void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count,
  63. uchar *logo_bmp, ulong len)
  64. {
  65. int i;
  66. ushort s1dReg;
  67. uchar s1dValue;
  68. uchar *ptr;
  69. ushort *ptr2;
  70. ushort val;
  71. unsigned char *dst;
  72. int x, y;
  73. int width, height, bpp, colors, line_size;
  74. int header_size;
  75. unsigned char *bmp;
  76. unsigned char r, g, b;
  77. BITMAPINFOHEADER *bm_info;
  78. int reg_byte_swap;
  79. /*
  80. * Detect epson
  81. */
  82. if (lcd_reg[0] == 0x1c) {
  83. /*
  84. * Big epson detected
  85. */
  86. reg_byte_swap = FALSE;
  87. palette_index = 0x1e2;
  88. palette_value = 0x1e4;
  89. puts("LCD: S1D13806");
  90. } else if (lcd_reg[1] == 0x1c) {
  91. /*
  92. * Big epson detected (with register swap bug)
  93. */
  94. reg_byte_swap = TRUE;
  95. palette_index = 0x1e3;
  96. palette_value = 0x1e5;
  97. puts("LCD: S1D13806S");
  98. } else if (lcd_reg[0] == 0x18) {
  99. /*
  100. * Small epson detected (704)
  101. */
  102. reg_byte_swap = FALSE;
  103. palette_index = 0x15;
  104. palette_value = 0x17;
  105. puts("LCD: S1D13704");
  106. } else if (lcd_reg[0x10000] == 0x24) {
  107. /*
  108. * Small epson detected (705)
  109. */
  110. reg_byte_swap = FALSE;
  111. palette_index = 0x15;
  112. palette_value = 0x17;
  113. lcd_reg += 0x10000; /* add offset for 705 regs */
  114. puts("LCD: S1D13705");
  115. } else {
  116. puts("LCD: No controller detected!\n");
  117. return;
  118. }
  119. for (i = 0; i<reg_count; i++) {
  120. s1dReg = regs[i].Index;
  121. if (reg_byte_swap) {
  122. if ((s1dReg & 0x0001) == 0)
  123. s1dReg |= 0x0001;
  124. else
  125. s1dReg &= ~0x0001;
  126. }
  127. s1dValue = regs[i].Value;
  128. lcd_reg[s1dReg] = s1dValue;
  129. }
  130. /*
  131. * Decompress bmp image
  132. */
  133. dst = malloc(CFG_LCD_LOGO_MAX_SIZE);
  134. if (gunzip(dst, CFG_LCD_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) {
  135. return;
  136. }
  137. /*
  138. * Check for bmp mark 'BM'
  139. */
  140. if (*(ushort *)dst != 0x424d) {
  141. printf("LCD: Unknown image format!\n");
  142. free(dst);
  143. return;
  144. }
  145. /*
  146. * Get image info from bmp-header
  147. */
  148. bm_info = (BITMAPINFOHEADER *)(dst + 14);
  149. bpp = LOAD_SHORT(bm_info->biBitCount);
  150. width = LOAD_LONG(bm_info->biWidth);
  151. height = LOAD_LONG(bm_info->biHeight);
  152. switch (bpp) {
  153. case 1:
  154. colors = 1;
  155. line_size = width >> 3;
  156. break;
  157. case 4:
  158. colors = 16;
  159. line_size = width >> 1;
  160. break;
  161. case 8:
  162. colors = 256;
  163. line_size = width;
  164. break;
  165. case 24:
  166. colors = 0;
  167. line_size = width * 3;
  168. break;
  169. default:
  170. printf("LCD: Unknown bpp (%d) im image!\n", bpp);
  171. free(dst);
  172. return;
  173. }
  174. printf(" (%d*%d, %dbpp)\n", width, height, bpp);
  175. /*
  176. * Write color palette
  177. */
  178. if (colors <= 256) {
  179. ptr = (unsigned char *)(dst + 14 + 40);
  180. for (i=0; i<colors; i++) {
  181. b = *ptr++;
  182. g = *ptr++;
  183. r = *ptr++;
  184. ptr++;
  185. S1D_WRITE_PALETTE(lcd_reg, i, r, g, b);
  186. }
  187. }
  188. /*
  189. * Write bitmap data into framebuffer
  190. */
  191. ptr = lcd_mem;
  192. ptr2 = (ushort *)lcd_mem;
  193. header_size = 14 + 40 + 4*colors; /* skip bmp header */
  194. for (y=0; y<height; y++) {
  195. bmp = &dst[(height-1-y)*line_size + header_size];
  196. if (bpp == 24) {
  197. for (x=0; x<width; x++) {
  198. /*
  199. * Generate epson 16bpp fb-format from 24bpp image
  200. */
  201. b = *bmp++ >> 3;
  202. g = *bmp++ >> 2;
  203. r = *bmp++ >> 3;
  204. val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
  205. *ptr2++ = val;
  206. }
  207. } else {
  208. for (x=0; x<line_size; x++) {
  209. *ptr++ = *bmp++;
  210. }
  211. }
  212. }
  213. free(dst);
  214. }