Wolfgang Denk | d4321d3 | 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 | b457118 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 24 | #include <malloc.h> |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 25 | |
| 26 | #ifdef CONFIG_LCD |
| 27 | |
Sergei Poselenov | 91904cd | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 28 | #undef SWAPPED_LCD /* For the previous h/w version */ |
Wolfgang Denk | d4321d3 | 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 | 91904cd | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 34 | #define PSOC_BAUD 230400UL |
Wolfgang Denk | d4321d3 | 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 | 41132c0 | 2011-10-21 17:04:21 +0800 | [diff] [blame] | 59 | #include <video_font.h> |
| 60 | #define FONT_WIDTH VIDEO_FONT_WIDTH |
| 61 | |
Wolfgang Denk | d4321d3 | 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 | |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * The device we use to communicate with PSoC |
| 74 | */ |
| 75 | int serial_inited = 0; |
| 76 | |
| 77 | /* |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 78 | * Imported functions to support the PSoC protocol |
| 79 | */ |
| 80 | extern int serial_init_dev (unsigned long dev_base); |
| 81 | extern void serial_setrts_dev (unsigned long dev_base, int s); |
| 82 | extern int serial_getcts_dev (unsigned long dev_base); |
| 83 | extern void serial_putc_raw_dev(unsigned long dev_base, const char c); |
| 84 | |
| 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 | |
| 93 | void lcd_ctrl_init (void *lcdbase) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Function sends the contents of the frame-buffer to the LCD |
| 99 | */ |
| 100 | void lcd_enable (void) |
| 101 | { |
| 102 | int i, retries, fb_size; |
| 103 | |
| 104 | if (!serial_inited) { |
| 105 | unsigned long baud; |
| 106 | |
| 107 | baud = gd->baudrate; |
| 108 | gd->baudrate = PSOC_BAUD; |
| 109 | serial_init_dev(PSOC_PSC); |
| 110 | gd->baudrate = baud; |
| 111 | serial_setrts_dev (PSOC_PSC, RTS_ASSERT); |
| 112 | serial_inited = 1; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Implement PSoC communication protocol: |
| 117 | * 1. Assert RTS, wait CTS assertion |
| 118 | * 2. Transmit data |
| 119 | * 3. Negate RTS, wait CTS negation |
| 120 | */ |
| 121 | |
| 122 | /* 1 */ |
| 123 | serial_setrts_dev (PSOC_PSC, RTS_ASSERT); |
| 124 | for (retries = PSOC_RETRIES; retries; retries--) { |
| 125 | if (serial_getcts_dev(PSOC_PSC) == CTS_ASSERT) |
| 126 | break; |
| 127 | udelay (PSOC_WAIT_TIME); |
| 128 | } |
| 129 | if (!retries) { |
| 130 | printf ("%s Error: PSoC doesn't respond on " |
| 131 | "RTS ASSERT\n", __FUNCTION__); |
| 132 | } |
| 133 | |
| 134 | /* 2 */ |
| 135 | fb_size = panel_info.vl_row * (panel_info.vl_col >> 3); |
| 136 | |
| 137 | #if !defined(SWAPPED_LCD) |
| 138 | for (i=0; i<fb_size; i++) { |
Jeroen Hofstee | 881c4ec | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 139 | serial_putc_raw_dev(PSOC_PSC, ((char *)gd->fb_base)[i]); |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 140 | } |
| 141 | #else |
| 142 | { |
| 143 | int x, y, pwidth; |
Jeroen Hofstee | 881c4ec | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 144 | char *p = (char *)gd->fb_base; |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 145 | |
| 146 | pwidth = ((panel_info.vl_col+7) >> 3); |
| 147 | for (y=0; y<panel_info.vl_row; y++) { |
| 148 | i = y * pwidth; |
| 149 | for (x=0; x<pwidth; x+=5) { |
| 150 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+2]<<4 & 0xF0) | (p[i+x+3]>>4 & 0x0F)); |
| 151 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+3]<<4 & 0xF0) | (p[i+x+4]>>4 & 0x0F)); |
| 152 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+4]<<4 & 0xF0) | (p[i+x]>>4 & 0x0F)); |
| 153 | serial_putc_raw_dev (PSOC_PSC, (p[i+x]<<4 & 0xF0) | (p[i+x+1]>>4 & 0x0F)); |
| 154 | serial_putc_raw_dev (PSOC_PSC, (p[i+x+1]<<4 & 0xF0) | (p[i+x+2]>>4 & 0x0F)); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | #endif |
| 159 | |
| 160 | /* 3 */ |
| 161 | serial_setrts_dev (PSOC_PSC, RTS_NEGATE); |
| 162 | for (retries = PSOC_RETRIES; retries; retries--) { |
| 163 | if (serial_getcts_dev(PSOC_PSC) == CTS_NEGATE) |
| 164 | break; |
| 165 | udelay (PSOC_WAIT_TIME); |
| 166 | } |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 167 | |
| 168 | return; |
| 169 | } |
Sergei Poselenov | 91904cd | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 170 | #ifdef CONFIG_PROGRESSBAR |
| 171 | |
Sergei Poselenov | 91904cd | 2007-02-27 12:40:16 +0300 | [diff] [blame] | 172 | void show_progress (int size, int tot) |
| 173 | { |
| 174 | int cnt; |
| 175 | int i; |
| 176 | static int rc = 0; |
| 177 | |
| 178 | rc += size; |
| 179 | |
| 180 | cnt = ((LCD_WIDTH/FONT_WIDTH) * rc) / tot; |
| 181 | |
| 182 | rc -= (cnt * tot) / (LCD_WIDTH/FONT_WIDTH); |
| 183 | |
| 184 | for (i = 0; i < cnt; i++) { |
| 185 | lcd_putc(0xdc); |
| 186 | } |
| 187 | |
| 188 | if (cnt) { |
| 189 | lcd_enable(); /* MCC200-specific - send the framebuffer to PSoC */ |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | #endif |
Nikita Kiryanov | b457118 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 194 | |
| 195 | int bmp_display(ulong addr, int x, int y) |
| 196 | { |
| 197 | int ret; |
| 198 | bmp_image_t *bmp = (bmp_image_t *)addr; |
| 199 | |
| 200 | if (!bmp) { |
| 201 | printf("There is no valid bmp file at the given address\n"); |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | ret = lcd_display_bitmap((ulong)bmp, x, y); |
| 206 | |
| 207 | if ((unsigned long)bmp != addr) |
| 208 | free(bmp); |
| 209 | |
| 210 | return ret; |
| 211 | } |
| 212 | |
Wolfgang Denk | d4321d3 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 213 | #endif /* CONFIG_LCD */ |