blob: c911445d97c3cb0216b0e5bb7f96ddfbf2ae0262 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denke8143e72006-08-30 23:09:00 +02006 */
7
8#include <common.h>
9#include <lcd.h>
10#include <mpc5xxx.h>
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +000011#include <malloc.h>
Wolfgang Denke8143e72006-08-30 23:09:00 +020012
13#ifdef CONFIG_LCD
14
Sergei Poselenov638dd142007-02-27 12:40:16 +030015#undef SWAPPED_LCD /* For the previous h/w version */
Wolfgang Denke8143e72006-08-30 23:09:00 +020016/*
17 * The name of the device used for communication
18 * with the PSoC.
19 */
20#define PSOC_PSC MPC5XXX_PSC2
Sergei Poselenov638dd142007-02-27 12:40:16 +030021#define PSOC_BAUD 230400UL
Wolfgang Denke8143e72006-08-30 23:09:00 +020022
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 Chioud3983ee2011-10-21 17:04:21 +080046#include <video_font.h>
47#define FONT_WIDTH VIDEO_FONT_WIDTH
48
Wolfgang Denke8143e72006-08-30 23:09:00 +020049DECLARE_GLOBAL_DATA_PTR;
50
51/*
52 * LCD information
53 */
54vidinfo_t panel_info = {
55 LCD_WIDTH, LCD_HEIGHT, LCD_BPP
56};
57
Wolfgang Denke8143e72006-08-30 23:09:00 +020058
59/*
60 * The device we use to communicate with PSoC
61 */
62int serial_inited = 0;
63
64/*
Wolfgang Denke8143e72006-08-30 23:09:00 +020065 * Imported functions to support the PSoC protocol
66 */
67extern int serial_init_dev (unsigned long dev_base);
68extern void serial_setrts_dev (unsigned long dev_base, int s);
69extern int serial_getcts_dev (unsigned long dev_base);
70extern 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 */
76void lcd_initcolregs (void)
77{
78}
79
80void lcd_ctrl_init (void *lcdbase)
81{
82}
83
84/*
85 * Function sends the contents of the frame-buffer to the LCD
86 */
87void 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 Hofstee00a0ca52013-01-22 10:44:12 +0000126 serial_putc_raw_dev(PSOC_PSC, ((char *)gd->fb_base)[i]);
Wolfgang Denke8143e72006-08-30 23:09:00 +0200127 }
128#else
129 {
130 int x, y, pwidth;
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000131 char *p = (char *)gd->fb_base;
Wolfgang Denke8143e72006-08-30 23:09:00 +0200132
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 Denke8143e72006-08-30 23:09:00 +0200154
155 return;
156}
Sergei Poselenov638dd142007-02-27 12:40:16 +0300157#ifdef CONFIG_PROGRESSBAR
158
Sergei Poselenov638dd142007-02-27 12:40:16 +0300159void 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 Kiryanovbfdcc652012-08-09 00:14:53 +0000181
182int 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 Denke8143e72006-08-30 23:09:00 +0200200#endif /* CONFIG_LCD */