blob: 893f4b7cb8d1462e6cbeea3ffa1807fd69dc0940 [file] [log] [blame]
Wolfgang Denkd4321d32006-08-30 23:09:00 +02001/*
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 Kiryanovb4571182012-08-09 00:14:53 +000024#include <malloc.h>
Wolfgang Denkd4321d32006-08-30 23:09:00 +020025
26#ifdef CONFIG_LCD
27
Sergei Poselenov91904cd2007-02-27 12:40:16 +030028#undef SWAPPED_LCD /* For the previous h/w version */
Wolfgang Denkd4321d32006-08-30 23:09:00 +020029/*
30 * The name of the device used for communication
31 * with the PSoC.
32 */
33#define PSOC_PSC MPC5XXX_PSC2
Sergei Poselenov91904cd2007-02-27 12:40:16 +030034#define PSOC_BAUD 230400UL
Wolfgang Denkd4321d32006-08-30 23:09:00 +020035
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 Chiou41132c02011-10-21 17:04:21 +080059#include <video_font.h>
60#define FONT_WIDTH VIDEO_FONT_WIDTH
61
Wolfgang Denkd4321d32006-08-30 23:09:00 +020062DECLARE_GLOBAL_DATA_PTR;
63
64/*
65 * LCD information
66 */
67vidinfo_t panel_info = {
68 LCD_WIDTH, LCD_HEIGHT, LCD_BPP
69};
70
71int lcd_line_length;
72
73int lcd_color_fg;
74int lcd_color_bg;
75
76/*
77 * Frame buffer memory information
78 */
79void *lcd_base; /* Start of framebuffer memory */
80void *lcd_console_address; /* Start of console buffer */
81
82short console_col = 0;
83short console_row = 0;
84
85/*
86 * The device we use to communicate with PSoC
87 */
88int serial_inited = 0;
89
90/*
91 * Exported functions
92 */
93void lcd_initcolregs (void);
94void lcd_ctrl_init (void *lcdbase);
95void lcd_enable (void);
96
97/*
98 * Imported functions to support the PSoC protocol
99 */
100extern int serial_init_dev (unsigned long dev_base);
101extern void serial_setrts_dev (unsigned long dev_base, int s);
102extern int serial_getcts_dev (unsigned long dev_base);
103extern 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 */
109void lcd_initcolregs (void)
110{
111}
112
113void lcd_ctrl_init (void *lcdbase)
114{
115}
116
117/*
118 * Function sends the contents of the frame-buffer to the LCD
119 */
120void 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 Denkd4321d32006-08-30 23:09:00 +0200187
188 return;
189}
Sergei Poselenov91904cd2007-02-27 12:40:16 +0300190#ifdef CONFIG_PROGRESSBAR
191
Sergei Poselenov91904cd2007-02-27 12:40:16 +0300192void 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 Kiryanovb4571182012-08-09 00:14:53 +0000214
215int 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 Denkd4321d32006-08-30 23:09:00 +0200233#endif /* CONFIG_LCD */