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