lcd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * (C) Copyright 2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <lcd.h>
  22. #include <mpc5xxx.h>
  23. #include <malloc.h>
  24. #ifdef CONFIG_LCD
  25. #undef SWAPPED_LCD /* For the previous h/w version */
  26. /*
  27. * The name of the device used for communication
  28. * with the PSoC.
  29. */
  30. #define PSOC_PSC MPC5XXX_PSC2
  31. #define PSOC_BAUD 230400UL
  32. #define RTS_ASSERT 1
  33. #define RTS_NEGATE 0
  34. #define CTS_ASSERT 1
  35. #define CTS_NEGATE 0
  36. /*
  37. * Dimensions in pixels
  38. */
  39. #define LCD_WIDTH 160
  40. #define LCD_HEIGHT 100
  41. /*
  42. * Dimensions in bytes
  43. */
  44. #define LCD_BUF_SIZE ((LCD_WIDTH*LCD_HEIGHT)>>3)
  45. #if LCD_BPP != LCD_MONOCHROME
  46. #error "MCC200 support only monochrome displays (1 bpp)!"
  47. #endif
  48. #define PSOC_RETRIES 10 /* each of PSOC_WAIT_TIME */
  49. #define PSOC_WAIT_TIME 10 /* usec */
  50. #include <video_font.h>
  51. #define FONT_WIDTH VIDEO_FONT_WIDTH
  52. DECLARE_GLOBAL_DATA_PTR;
  53. /*
  54. * LCD information
  55. */
  56. vidinfo_t panel_info = {
  57. LCD_WIDTH, LCD_HEIGHT, LCD_BPP
  58. };
  59. /*
  60. * The device we use to communicate with PSoC
  61. */
  62. int serial_inited = 0;
  63. /*
  64. * Exported functions
  65. */
  66. void lcd_initcolregs (void);
  67. void lcd_ctrl_init (void *lcdbase);
  68. void lcd_enable (void);
  69. /*
  70. * Imported functions to support the PSoC protocol
  71. */
  72. extern int serial_init_dev (unsigned long dev_base);
  73. extern void serial_setrts_dev (unsigned long dev_base, int s);
  74. extern int serial_getcts_dev (unsigned long dev_base);
  75. extern void serial_putc_raw_dev(unsigned long dev_base, const char c);
  76. /*
  77. * Just stubs for our driver, needed for compiling compabilty with
  78. * the common LCD driver code.
  79. */
  80. void lcd_initcolregs (void)
  81. {
  82. }
  83. void lcd_ctrl_init (void *lcdbase)
  84. {
  85. }
  86. /*
  87. * Function sends the contents of the frame-buffer to the LCD
  88. */
  89. void lcd_enable (void)
  90. {
  91. int i, retries, fb_size;
  92. if (!serial_inited) {
  93. unsigned long baud;
  94. baud = gd->baudrate;
  95. gd->baudrate = PSOC_BAUD;
  96. serial_init_dev(PSOC_PSC);
  97. gd->baudrate = baud;
  98. serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
  99. serial_inited = 1;
  100. }
  101. /*
  102. * Implement PSoC communication protocol:
  103. * 1. Assert RTS, wait CTS assertion
  104. * 2. Transmit data
  105. * 3. Negate RTS, wait CTS negation
  106. */
  107. /* 1 */
  108. serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
  109. for (retries = PSOC_RETRIES; retries; retries--) {
  110. if (serial_getcts_dev(PSOC_PSC) == CTS_ASSERT)
  111. break;
  112. udelay (PSOC_WAIT_TIME);
  113. }
  114. if (!retries) {
  115. printf ("%s Error: PSoC doesn't respond on "
  116. "RTS ASSERT\n", __FUNCTION__);
  117. }
  118. /* 2 */
  119. fb_size = panel_info.vl_row * (panel_info.vl_col >> 3);
  120. #if !defined(SWAPPED_LCD)
  121. for (i=0; i<fb_size; i++) {
  122. serial_putc_raw_dev(PSOC_PSC, ((char *)gd->fb_base)[i]);
  123. }
  124. #else
  125. {
  126. int x, y, pwidth;
  127. char *p = (char *)gd->fb_base;
  128. pwidth = ((panel_info.vl_col+7) >> 3);
  129. for (y=0; y<panel_info.vl_row; y++) {
  130. i = y * pwidth;
  131. for (x=0; x<pwidth; x+=5) {
  132. serial_putc_raw_dev (PSOC_PSC, (p[i+x+2]<<4 & 0xF0) | (p[i+x+3]>>4 & 0x0F));
  133. serial_putc_raw_dev (PSOC_PSC, (p[i+x+3]<<4 & 0xF0) | (p[i+x+4]>>4 & 0x0F));
  134. serial_putc_raw_dev (PSOC_PSC, (p[i+x+4]<<4 & 0xF0) | (p[i+x]>>4 & 0x0F));
  135. serial_putc_raw_dev (PSOC_PSC, (p[i+x]<<4 & 0xF0) | (p[i+x+1]>>4 & 0x0F));
  136. serial_putc_raw_dev (PSOC_PSC, (p[i+x+1]<<4 & 0xF0) | (p[i+x+2]>>4 & 0x0F));
  137. }
  138. }
  139. }
  140. #endif
  141. /* 3 */
  142. serial_setrts_dev (PSOC_PSC, RTS_NEGATE);
  143. for (retries = PSOC_RETRIES; retries; retries--) {
  144. if (serial_getcts_dev(PSOC_PSC) == CTS_NEGATE)
  145. break;
  146. udelay (PSOC_WAIT_TIME);
  147. }
  148. return;
  149. }
  150. #ifdef CONFIG_PROGRESSBAR
  151. void show_progress (int size, int tot)
  152. {
  153. int cnt;
  154. int i;
  155. static int rc = 0;
  156. rc += size;
  157. cnt = ((LCD_WIDTH/FONT_WIDTH) * rc) / tot;
  158. rc -= (cnt * tot) / (LCD_WIDTH/FONT_WIDTH);
  159. for (i = 0; i < cnt; i++) {
  160. lcd_putc(0xdc);
  161. }
  162. if (cnt) {
  163. lcd_enable(); /* MCC200-specific - send the framebuffer to PSoC */
  164. }
  165. }
  166. #endif
  167. int bmp_display(ulong addr, int x, int y)
  168. {
  169. int ret;
  170. bmp_image_t *bmp = (bmp_image_t *)addr;
  171. if (!bmp) {
  172. printf("There is no valid bmp file at the given address\n");
  173. return 1;
  174. }
  175. ret = lcd_display_bitmap((ulong)bmp, x, y);
  176. if ((unsigned long)bmp != addr)
  177. free(bmp);
  178. return ret;
  179. }
  180. #endif /* CONFIG_LCD */