1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#include <common.h>
50#include <stdarg.h>
51#include <board/cogent/lcd.h>
52
53static char lines[2][LCD_LINE_LENGTH+1];
54static int curline;
55static int linepos;
56static int heartbeat_active;
57
58
59static char init_line0[LCD_LINE_LENGTH+1] = "U-Boot Cogent ";
60static char init_line1[LCD_LINE_LENGTH+1] = "mjj, 11 Aug 2000";
61
62static inline unsigned char
63lcd_read_status(cma_mb_lcd *clp)
64{
65
66 return (cma_mb_reg_read(&clp->lcd_bsr));
67}
68
69static inline void
70lcd_wait_not_busy(cma_mb_lcd *clp)
71{
72
73
74
75
76
77
78
79 while (lcd_read_status(clp) & LCD_STAT_BUSY)
80 ;
81
82 (void)lcd_read_status(clp);
83}
84
85static inline void
86lcd_write_command(cma_mb_lcd *clp, unsigned char cmd)
87{
88 lcd_wait_not_busy(clp);
89
90
91 cma_mb_reg_write(&clp->lcd_cmd, cmd);
92}
93
94static inline void
95lcd_write_data(cma_mb_lcd *clp, unsigned char data)
96{
97 lcd_wait_not_busy(clp);
98
99
100 cma_mb_reg_write(&clp->lcd_ccr, data);
101}
102
103static inline void
104lcd_dis(int addr, char *string)
105{
106 cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
107 int pos, linelen;
108
109 linelen = LCD_LINE_LENGTH;
110 if (heartbeat_active && addr == LCD_LINE0)
111 linelen--;
112
113 lcd_write_command(clp, LCD_CMD_ADD + addr);
114 for (pos = 0; *string != '\0' && pos < linelen; pos++)
115 lcd_write_data(clp, *string++);
116}
117
118void
119lcd_init(void)
120{
121 cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
122 int i;
123
124
125 lcd_write_command(clp, LCD_CMD_MODE);
126
127
128 lcd_write_command(clp, LCD_CMD_DON);
129
130 curline = 0;
131 linepos = 0;
132
133 for (i = 0; i < LCD_LINE_LENGTH; i++) {
134 lines[0][i] = init_line0[i];
135 lines[1][i] = init_line1[i];
136 }
137
138 lines[0][LCD_LINE_LENGTH] = lines[1][LCD_LINE_LENGTH] = 0;
139
140 lcd_dis(LCD_LINE0, lines[0]);
141 lcd_dis(LCD_LINE1, lines[1]);
142
143 printf("HD44780 2 line x %d char display\n", LCD_LINE_LENGTH);
144}
145
146void
147lcd_write_char(const char c)
148{
149 int i, linelen;
150
151
152 if (c == '\r')
153 return;
154
155 linelen = LCD_LINE_LENGTH;
156 if (heartbeat_active && curline == 0)
157 linelen--;
158
159 if (c == '\n') {
160 lcd_dis(LCD_LINE0, &lines[curline^1][0]);
161 lcd_dis(LCD_LINE1, &lines[curline][0]);
162
163
164 curline ^= 1;
165 linelen = LCD_LINE_LENGTH;
166 if (heartbeat_active && curline == 0)
167 linelen--;
168 linepos = 0;
169
170 for (i = 0; i < linelen; i++)
171 lines[curline][i] = ' ';
172
173 return;
174 }
175
176
177 if (linepos < linelen)
178 lines[curline][linepos++] = c;
179}
180
181void
182lcd_flush(void)
183{
184 lcd_dis(LCD_LINE1, &lines[curline][0]);
185}
186
187void
188lcd_write_string(const char *s)
189{
190 char *p;
191
192 for (p = (char *)s; *p != '\0'; p++)
193 lcd_write_char(*p);
194}
195
196void
197lcd_printf(const char *fmt, ...)
198{
199 va_list args;
200 char buf[CONFIG_SYS_PBSIZE];
201
202 va_start(args, fmt);
203 (void)vsprintf(buf, fmt, args);
204 va_end(args);
205
206 lcd_write_string(buf);
207}
208
209void
210lcd_heartbeat(void)
211{
212 cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
213#if 0
214 static char rotchars[] = { '|', '/', '-', '\\' };
215#else
216
217 static char rotchars[] = { '|', '/', '-', '\315' };
218#endif
219 static int rotator_index = 0;
220
221 heartbeat_active = 1;
222
223
224 lcd_write_command(clp, LCD_CMD_ADD + LCD_LINE0 + (LCD_LINE_LENGTH - 1));
225
226
227 lcd_write_data(clp, rotchars[rotator_index]);
228
229 if (++rotator_index >= (sizeof rotchars / sizeof rotchars[0]))
230 rotator_index = 0;
231}
232
233#ifdef CONFIG_SHOW_ACTIVITY
234void board_show_activity (ulong timestamp)
235{
236#ifdef CONFIG_STATUS_LED
237 if ((timestamp % (CONFIG_SYS_HZ / 2) == 0)
238 lcd_heartbeat ();
239#endif
240}
241
242void show_activity(int arg)
243{
244}
245#endif
246