Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 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 | |
| 21 | #include <common.h> |
| 22 | #include <lcd.h> |
| 23 | #include <mpc5xxx.h> |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 24 | #include <malloc.h> |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 25 | |
| 26 | #ifdef CONFIG_LCD |
| 27 | |
Sergei Poselenov | 638dd14 | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 28 | #undef SWAPPED_LCD /* For the previous h/w version */ |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 29 | /* |
| 30 | * The name of the device used for communication |
| 31 | * with the PSoC. |
| 32 | */ |
| 33 | #define PSOC_PSC MPC5XXX_PSC2 |
Sergei Poselenov | 638dd14 | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 34 | #define PSOC_BAUD 230400UL |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 35 | |
| 36 | #define RTS_ASSERT 1 |
| 37 | #define RTS_NEGATE 0 |
| 38 | #define CTS_ASSERT 1 |
| 39 | #define CTS_NEGATE 0 |
| 40 | |
| 41 | /* |
| 42 | * Dimensions in pixels |
| 43 | */ |
| 44 | #define LCD_WIDTH 160 |
| 45 | #define LCD_HEIGHT 100 |
| 46 | |
| 47 | /* |
| 48 | * Dimensions in bytes |
| 49 | */ |
| 50 | #define LCD_BUF_SIZE ((LCD_WIDTH*LCD_HEIGHT)>>3) |
| 51 | |
| 52 | #if LCD_BPP != LCD_MONOCHROME |
| 53 | #error "MCC200 support only monochrome displays (1 bpp)!" |
| 54 | #endif |
| 55 | |
| 56 | #define PSOC_RETRIES 10 /* each of PSOC_WAIT_TIME */ |
| 57 | #define PSOC_WAIT_TIME 10 /* usec */ |
| 58 | |
Che-Liang Chiou | d3983ee | 2011-10-21 17:04:21 +0800 | [diff] [blame] | 59 | #include <video_font.h> |
| 60 | #define FONT_WIDTH VIDEO_FONT_WIDTH |
| 61 | |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 62 | DECLARE_GLOBAL_DATA_PTR; |
| 63 | |
| 64 | /* |
| 65 | * LCD information |
| 66 | */ |
| 67 | vidinfo_t panel_info = { |
| 68 | LCD_WIDTH, LCD_HEIGHT, LCD_BPP |
| 69 | }; |
| 70 | |
| 71 | int lcd_line_length; |
| 72 | |
| 73 | int lcd_color_fg; |
| 74 | int lcd_color_bg; |
| 75 | |
| 76 | /* |
| 77 | * Frame buffer memory information |
| 78 | */ |
| 79 | void *lcd_base; /* Start of framebuffer memory */ |
| 80 | void *lcd_console_address; /* Start of console buffer */ |
| 81 | |
| 82 | short console_col = 0; |
| 83 | short console_row = 0; |
| 84 | |
| 85 | /* |
| 86 | * The device we use to communicate with PSoC |
| 87 | */ |
| 88 | int serial_inited = 0; |
| 89 | |
| 90 | /* |
| 91 | * Exported functions |
| 92 | */ |
| 93 | void lcd_initcolregs (void); |
| 94 | void lcd_ctrl_init (void *lcdbase); |
| 95 | void lcd_enable (void); |
| 96 | |
| 97 | /* |
| 98 | * Imported functions to support the PSoC protocol |
| 99 | */ |
| 100 | extern int serial_init_dev (unsigned long dev_base); |
| 101 | extern void serial_setrts_dev (unsigned long dev_base, int s); |
| 102 | extern int serial_getcts_dev (unsigned long dev_base); |
| 103 | extern void serial_putc_raw_dev(unsigned long dev_base, const char c); |
| 104 | |
| 105 | /* |
| 106 | * Just stubs for our driver, needed for compiling compabilty with |
| 107 | * the common LCD driver code. |
| 108 | */ |
| 109 | void lcd_initcolregs (void) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | void lcd_ctrl_init (void *lcdbase) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Function sends the contents of the frame-buffer to the LCD |
| 119 | */ |
| 120 | void lcd_enable (void) |
| 121 | { |
| 122 | int i, retries, fb_size; |
| 123 | |
| 124 | if (!serial_inited) { |
| 125 | unsigned long baud; |
| 126 | |
| 127 | baud = gd->baudrate; |
| 128 | gd->baudrate = PSOC_BAUD; |
| 129 | serial_init_dev(PSOC_PSC); |
| 130 | gd->baudrate = baud; |
| 131 | serial_setrts_dev (PSOC_PSC, RTS_ASSERT); |
| 132 | serial_inited = 1; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Implement PSoC communication protocol: |
| 137 | * 1. Assert RTS, wait CTS assertion |
| 138 | * 2. Transmit data |
| 139 | * 3. Negate RTS, wait CTS negation |
| 140 | */ |
| 141 | |
| 142 | /* 1 */ |
| 143 | serial_setrts_dev (PSOC_PSC, RTS_ASSERT); |
| 144 | for (retries = PSOC_RETRIES; retries; retries--) { |
| 145 | if (serial_getcts_dev(PSOC_PSC) == CTS_ASSERT) |
| 146 | break; |
| 147 | udelay (PSOC_WAIT_TIME); |
| 148 | } |
| 149 | if (!retries) { |
| 150 | printf ("%s Error: PSoC doesn't respond on " |
| 151 | "RTS ASSERT\n", __FUNCTION__); |
| 152 | } |
| 153 | |
| 154 | /* 2 */ |
| 155 | fb_size = panel_info.vl_row * (panel_info.vl_col >> 3); |
| 156 | |
| 157 | #if !defined(SWAPPED_LCD) |
| 158 | for (i=0; i<fb_size; i++) { |
| 159 | serial_putc_raw_dev (PSOC_PSC, ((char *)lcd_base)[i]); |
| 160 | } |
| 161 | #else |
| 162 | { |
| 163 | int x, y, pwidth; |
| 164 | char *p = (char *)lcd_base; |
| 165 | |
| 166 | pwidth = ((panel_info.vl_col+7) >> 3); |
| 167 | for (y=0; y<panel_info.vl_row; y++) { |
| 168 | i = y * pwidth; |
| 169 | for (x=0; x<pwidth; x+=5) { |
| 170 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+2]<<4 & 0xF0) | (p[i+x+3]>>4 & 0x0F)); |
| 171 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+3]<<4 & 0xF0) | (p[i+x+4]>>4 & 0x0F)); |
| 172 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+4]<<4 & 0xF0) | (p[i+x]>>4 & 0x0F)); |
| 173 | serial_putc_raw_dev (PSOC_PSC, (p[i+x]<<4 & 0xF0) | (p[i+x+1]>>4 & 0x0F)); |
| 174 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+1]<<4 & 0xF0) | (p[i+x+2]>>4 & 0x0F)); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | /* 3 */ |
| 181 | serial_setrts_dev (PSOC_PSC, RTS_NEGATE); |
| 182 | for (retries = PSOC_RETRIES; retries; retries--) { |
| 183 | if (serial_getcts_dev(PSOC_PSC) == CTS_NEGATE) |
| 184 | break; |
| 185 | udelay (PSOC_WAIT_TIME); |
| 186 | } |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 187 | |
| 188 | return; |
| 189 | } |
Sergei Poselenov | 638dd14 | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 190 | #ifdef CONFIG_PROGRESSBAR |
| 191 | |
Sergei Poselenov | 638dd14 | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 192 | void show_progress (int size, int tot) |
| 193 | { |
| 194 | int cnt; |
| 195 | int i; |
| 196 | static int rc = 0; |
| 197 | |
| 198 | rc += size; |
| 199 | |
| 200 | cnt = ((LCD_WIDTH/FONT_WIDTH) * rc) / tot; |
| 201 | |
| 202 | rc -= (cnt * tot) / (LCD_WIDTH/FONT_WIDTH); |
| 203 | |
| 204 | for (i = 0; i < cnt; i++) { |
| 205 | lcd_putc(0xdc); |
| 206 | } |
| 207 | |
| 208 | if (cnt) { |
| 209 | lcd_enable(); /* MCC200-specific - send the framebuffer to PSoC */ |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | #endif |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 214 | |
| 215 | int bmp_display(ulong addr, int x, int y) |
| 216 | { |
| 217 | int ret; |
| 218 | bmp_image_t *bmp = (bmp_image_t *)addr; |
| 219 | |
| 220 | if (!bmp) { |
| 221 | printf("There is no valid bmp file at the given address\n"); |
| 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | ret = lcd_display_bitmap((ulong)bmp, x, y); |
| 226 | |
| 227 | if ((unsigned long)bmp != addr) |
| 228 | free(bmp); |
| 229 | |
| 230 | return ret; |
| 231 | } |
| 232 | |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 233 | #endif /* CONFIG_LCD */ |