lcd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #ifdef CONFIG_LCD
  24. #undef SWAPPED_LCD /* For the previous h/w version */
  25. /*
  26. * The name of the device used for communication
  27. * with the PSoC.
  28. */
  29. #define PSOC_PSC MPC5XXX_PSC2
  30. #define PSOC_BAUD 230400UL
  31. #define RTS_ASSERT 1
  32. #define RTS_NEGATE 0
  33. #define CTS_ASSERT 1
  34. #define CTS_NEGATE 0
  35. /*
  36. * Dimensions in pixels
  37. */
  38. #define LCD_WIDTH 160
  39. #define LCD_HEIGHT 100
  40. /*
  41. * Dimensions in bytes
  42. */
  43. #define LCD_BUF_SIZE ((LCD_WIDTH*LCD_HEIGHT)>>3)
  44. #if LCD_BPP != LCD_MONOCHROME
  45. #error "MCC200 support only monochrome displays (1 bpp)!"
  46. #endif
  47. #define PSOC_RETRIES 10 /* each of PSOC_WAIT_TIME */
  48. #define PSOC_WAIT_TIME 10 /* usec */
  49. #include <video_font.h>
  50. #define FONT_WIDTH VIDEO_FONT_WIDTH
  51. DECLARE_GLOBAL_DATA_PTR;
  52. /*
  53. * LCD information
  54. */
  55. vidinfo_t panel_info = {
  56. LCD_WIDTH, LCD_HEIGHT, LCD_BPP
  57. };
  58. int lcd_line_length;
  59. int lcd_color_fg;
  60. int lcd_color_bg;
  61. /*
  62. * Frame buffer memory information
  63. */
  64. void *lcd_base; /* Start of framebuffer memory */
  65. void *lcd_console_address; /* Start of console buffer */
  66. short console_col = 0;
  67. short console_row = 0;
  68. /*
  69. * The device we use to communicate with PSoC
  70. */
  71. int serial_inited = 0;
  72. /*
  73. * Exported functions
  74. */
  75. void lcd_initcolregs (void);
  76. void lcd_ctrl_init (void *lcdbase);
  77. void lcd_enable (void);
  78. /*
  79. * Imported functions to support the PSoC protocol
  80. */
  81. extern int serial_init_dev (unsigned long dev_base);
  82. extern void serial_setrts_dev (unsigned long dev_base, int s);
  83. extern int serial_getcts_dev (unsigned long dev_base);
  84. extern void serial_putc_raw_dev(unsigned long dev_base, const char c);
  85. /*
  86. * Just stubs for our driver, needed for compiling compabilty with
  87. * the common LCD driver code.
  88. */
  89. void lcd_initcolregs (void)
  90. {
  91. }
  92. void lcd_ctrl_init (void *lcdbase)
  93. {
  94. }
  95. /*
  96. * Function sends the contents of the frame-buffer to the LCD
  97. */
  98. void lcd_enable (void)
  99. {
  100. int i, retries, fb_size;
  101. if (!serial_inited) {
  102. unsigned long baud;
  103. baud = gd->baudrate;
  104. gd->baudrate = PSOC_BAUD;
  105. serial_init_dev(PSOC_PSC);
  106. gd->baudrate = baud;
  107. serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
  108. serial_inited = 1;
  109. }
  110. /*
  111. * Implement PSoC communication protocol:
  112. * 1. Assert RTS, wait CTS assertion
  113. * 2. Transmit data
  114. * 3. Negate RTS, wait CTS negation
  115. */
  116. /* 1 */
  117. serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
  118. for (retries = PSOC_RETRIES; retries; retries--) {
  119. if (serial_getcts_dev(PSOC_PSC) == CTS_ASSERT)
  120. break;
  121. udelay (PSOC_WAIT_TIME);
  122. }
  123. if (!retries) {
  124. printf ("%s Error: PSoC doesn't respond on "
  125. "RTS ASSERT\n", __FUNCTION__);
  126. }
  127. /* 2 */
  128. fb_size = panel_info.vl_row * (panel_info.vl_col >> 3);
  129. #if !defined(SWAPPED_LCD)
  130. for (i=0; i<fb_size; i++) {
  131. serial_putc_raw_dev (PSOC_PSC, ((char *)lcd_base)[i]);
  132. }
  133. #else
  134. {
  135. int x, y, pwidth;
  136. char *p = (char *)lcd_base;
  137. pwidth = ((panel_info.vl_col+7) >> 3);
  138. for (y=0; y<panel_info.vl_row; y++) {
  139. i = y * pwidth;
  140. for (x=0; x<pwidth; x+=5) {
  141. serial_putc_raw_dev (PSOC_PSC, (p[i+x+2]<<4 & 0xF0) | (p[i+x+3]>>4 & 0x0F));
  142. serial_putc_raw_dev (PSOC_PSC, (p[i+x+3]<<4 & 0xF0) | (p[i+x+4]>>4 & 0x0F));
  143. serial_putc_raw_dev (PSOC_PSC, (p[i+x+4]<<4 & 0xF0) | (p[i+x]>>4 & 0x0F));
  144. serial_putc_raw_dev (PSOC_PSC, (p[i+x]<<4 & 0xF0) | (p[i+x+1]>>4 & 0x0F));
  145. serial_putc_raw_dev (PSOC_PSC, (p[i+x+1]<<4 & 0xF0) | (p[i+x+2]>>4 & 0x0F));
  146. }
  147. }
  148. }
  149. #endif
  150. /* 3 */
  151. serial_setrts_dev (PSOC_PSC, RTS_NEGATE);
  152. for (retries = PSOC_RETRIES; retries; retries--) {
  153. if (serial_getcts_dev(PSOC_PSC) == CTS_NEGATE)
  154. break;
  155. udelay (PSOC_WAIT_TIME);
  156. }
  157. return;
  158. }
  159. #ifdef CONFIG_PROGRESSBAR
  160. void show_progress (int size, int tot)
  161. {
  162. int cnt;
  163. int i;
  164. static int rc = 0;
  165. rc += size;
  166. cnt = ((LCD_WIDTH/FONT_WIDTH) * rc) / tot;
  167. rc -= (cnt * tot) / (LCD_WIDTH/FONT_WIDTH);
  168. for (i = 0; i < cnt; i++) {
  169. lcd_putc(0xdc);
  170. }
  171. if (cnt) {
  172. lcd_enable(); /* MCC200-specific - send the framebuffer to PSoC */
  173. }
  174. }
  175. #endif
  176. #endif /* CONFIG_LCD */