blob: caf8d8b110b15d5cbffe92f56841c7d68fa38cc8 [file] [log] [blame]
Wolfgang Denke8143e72006-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 Kiryanovbfdcc652012-08-09 00:14:53 +000024#include <malloc.h>
Wolfgang Denke8143e72006-08-30 23:09:00 +020025
26#ifdef CONFIG_LCD
27
Sergei Poselenov638dd142007-02-27 12:40:16 +030028#undef SWAPPED_LCD /* For the previous h/w version */
Wolfgang Denke8143e72006-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 Poselenov638dd142007-02-27 12:40:16 +030034#define PSOC_BAUD 230400UL
Wolfgang Denke8143e72006-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 Chioud3983ee2011-10-21 17:04:21 +080059#include <video_font.h>
60#define FONT_WIDTH VIDEO_FONT_WIDTH
61
Wolfgang Denke8143e72006-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
Wolfgang Denke8143e72006-08-30 23:09:00 +020071/*
72 * Frame buffer memory information
73 */
74void *lcd_base; /* Start of framebuffer memory */
Wolfgang Denke8143e72006-08-30 23:09:00 +020075
76/*
77 * The device we use to communicate with PSoC
78 */
79int serial_inited = 0;
80
81/*
82 * Exported functions
83 */
84void lcd_initcolregs (void);
85void lcd_ctrl_init (void *lcdbase);
86void lcd_enable (void);
87
88/*
89 * Imported functions to support the PSoC protocol
90 */
91extern int serial_init_dev (unsigned long dev_base);
92extern void serial_setrts_dev (unsigned long dev_base, int s);
93extern int serial_getcts_dev (unsigned long dev_base);
94extern void serial_putc_raw_dev(unsigned long dev_base, const char c);
95
96/*
97 * Just stubs for our driver, needed for compiling compabilty with
98 * the common LCD driver code.
99 */
100void lcd_initcolregs (void)
101{
102}
103
104void lcd_ctrl_init (void *lcdbase)
105{
106}
107
108/*
109 * Function sends the contents of the frame-buffer to the LCD
110 */
111void lcd_enable (void)
112{
113 int i, retries, fb_size;
114
115 if (!serial_inited) {
116 unsigned long baud;
117
118 baud = gd->baudrate;
119 gd->baudrate = PSOC_BAUD;
120 serial_init_dev(PSOC_PSC);
121 gd->baudrate = baud;
122 serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
123 serial_inited = 1;
124 }
125
126 /*
127 * Implement PSoC communication protocol:
128 * 1. Assert RTS, wait CTS assertion
129 * 2. Transmit data
130 * 3. Negate RTS, wait CTS negation
131 */
132
133 /* 1 */
134 serial_setrts_dev (PSOC_PSC, RTS_ASSERT);
135 for (retries = PSOC_RETRIES; retries; retries--) {
136 if (serial_getcts_dev(PSOC_PSC) == CTS_ASSERT)
137 break;
138 udelay (PSOC_WAIT_TIME);
139 }
140 if (!retries) {
141 printf ("%s Error: PSoC doesn't respond on "
142 "RTS ASSERT\n", __FUNCTION__);
143 }
144
145 /* 2 */
146 fb_size = panel_info.vl_row * (panel_info.vl_col >> 3);
147
148#if !defined(SWAPPED_LCD)
149 for (i=0; i<fb_size; i++) {
150 serial_putc_raw_dev (PSOC_PSC, ((char *)lcd_base)[i]);
151 }
152#else
153 {
154 int x, y, pwidth;
155 char *p = (char *)lcd_base;
156
157 pwidth = ((panel_info.vl_col+7) >> 3);
158 for (y=0; y<panel_info.vl_row; y++) {
159 i = y * pwidth;
160 for (x=0; x<pwidth; x+=5) {
161 serial_putc_raw_dev (PSOC_PSC, (p[i+x+2]<<4 & 0xF0) | (p[i+x+3]>>4 & 0x0F));
162 serial_putc_raw_dev (PSOC_PSC, (p[i+x+3]<<4 & 0xF0) | (p[i+x+4]>>4 & 0x0F));
163 serial_putc_raw_dev (PSOC_PSC, (p[i+x+4]<<4 & 0xF0) | (p[i+x]>>4 & 0x0F));
164 serial_putc_raw_dev (PSOC_PSC, (p[i+x]<<4 & 0xF0) | (p[i+x+1]>>4 & 0x0F));
165 serial_putc_raw_dev (PSOC_PSC, (p[i+x+1]<<4 & 0xF0) | (p[i+x+2]>>4 & 0x0F));
166 }
167 }
168 }
169#endif
170
171 /* 3 */
172 serial_setrts_dev (PSOC_PSC, RTS_NEGATE);
173 for (retries = PSOC_RETRIES; retries; retries--) {
174 if (serial_getcts_dev(PSOC_PSC) == CTS_NEGATE)
175 break;
176 udelay (PSOC_WAIT_TIME);
177 }
Wolfgang Denke8143e72006-08-30 23:09:00 +0200178
179 return;
180}
Sergei Poselenov638dd142007-02-27 12:40:16 +0300181#ifdef CONFIG_PROGRESSBAR
182
Sergei Poselenov638dd142007-02-27 12:40:16 +0300183void show_progress (int size, int tot)
184{
185 int cnt;
186 int i;
187 static int rc = 0;
188
189 rc += size;
190
191 cnt = ((LCD_WIDTH/FONT_WIDTH) * rc) / tot;
192
193 rc -= (cnt * tot) / (LCD_WIDTH/FONT_WIDTH);
194
195 for (i = 0; i < cnt; i++) {
196 lcd_putc(0xdc);
197 }
198
199 if (cnt) {
200 lcd_enable(); /* MCC200-specific - send the framebuffer to PSoC */
201 }
202}
203
204#endif
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000205
206int bmp_display(ulong addr, int x, int y)
207{
208 int ret;
209 bmp_image_t *bmp = (bmp_image_t *)addr;
210
211 if (!bmp) {
212 printf("There is no valid bmp file at the given address\n");
213 return 1;
214 }
215
216 ret = lcd_display_bitmap((ulong)bmp, x, y);
217
218 if ((unsigned long)bmp != addr)
219 free(bmp);
220
221 return ret;
222}
223
Wolfgang Denke8143e72006-08-30 23:09:00 +0200224#endif /* CONFIG_LCD */