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