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