blob: 15cfcb0c839dbd57a8ba011caee6926755276618 [file] [log] [blame]
John Otken9aa36772007-07-26 17:49:11 +02001/*
2 * See file CREDITS for list of people who contributed to this
3 * project.
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 <config.h>
22#include <common.h>
23#include <command.h>
24#include <asm/io.h>
Stefan Roesede21eab2010-09-16 14:30:37 +020025#include <asm/ppc4xx-gpio.h>
John Otken9aa36772007-07-26 17:49:11 +020026
27#define LCD_CMD_ADDR 0x50100002
28#define LCD_DATA_ADDR 0x50100003
29#define LCD_BLK_CTRL CPLD_REG1_ADDR
30
31static char *amcc_logo = "AMCC 405EP TAIHU EVALUATION KIT";
32static int addr_flag = 0x80;
33
34static void lcd_bl_ctrl(char val)
35{
36 out_8((u8 *) LCD_BLK_CTRL, in_8((u8 *) LCD_BLK_CTRL) | val);
37}
38
39static void lcd_putc(int val)
40{
41 int i = 100;
42 char addr;
43
44 while (i--) {
45 if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
46 udelay(50);
47 break;
48 }
49 udelay(50);
50 }
51
52 if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
53 printf("LCD is busy\n");
54 return;
55 }
56
57 addr = in_8((u8 *) LCD_CMD_ADDR);
58 udelay(50);
59 if ((addr != 0) && (addr % 0x10 == 0)) {
60 addr_flag ^= 0x40;
61 out_8((u8 *) LCD_CMD_ADDR, addr_flag);
62 }
63
64 udelay(50);
65 out_8((u8 *) LCD_DATA_ADDR, val);
66 udelay(50);
67}
68
69static void lcd_puts(char *s)
70{
71 char *p = s;
72 int i = 100;
73
74 while (i--) {
75 if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
76 udelay(50);
77 break;
78 }
79 udelay(50);
80 }
81
82 if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
83 printf("LCD is busy\n");
84 return;
85 }
86
87 while (*p)
88 lcd_putc(*p++);
89}
90
91static void lcd_put_logo(void)
92{
93 int i = 100;
94 char *p = amcc_logo;
95
96 while (i--) {
97 if ((in_8((u8 *) LCD_CMD_ADDR) & 0x80) != 0x80) { /*BF = 1 ?*/
98 udelay(50);
99 break;
100 }
101 udelay(50);
102 }
103
104 if (in_8((u8 *) LCD_CMD_ADDR) & 0x80) {
105 printf("LCD is busy\n");
106 return;
107 }
108
109 out_8((u8 *) LCD_CMD_ADDR, 0x80);
110 while (*p)
111 lcd_putc(*p++);
112}
113
114int lcd_init(void)
115{
116 puts("LCD: ");
117 out_8((u8 *) LCD_CMD_ADDR, 0x38); /* set function:8-bit,2-line,5x7 font type */
118 udelay(50);
119 out_8((u8 *) LCD_CMD_ADDR, 0x0f); /* set display on,cursor on,blink on */
120 udelay(50);
121 out_8((u8 *) LCD_CMD_ADDR, 0x01); /* display clear */
122 udelay(2000);
123 out_8((u8 *) LCD_CMD_ADDR, 0x06); /* set entry */
124 udelay(50);
125 lcd_bl_ctrl(0x02); /* set backlight on */
126 lcd_put_logo();
127 puts("ready\n");
128
129 return 0;
130}
131
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200132static int do_lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +0200133{
134 out_8((u8 *) LCD_CMD_ADDR, 0x01);
135 udelay(2000);
136
137 return 0;
138}
139
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200140static int do_lcd_puts (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +0200141{
Wolfgang Denk3b683112010-07-17 01:06:04 +0200142 if (argc < 2)
143 return cmd_usage(cmdtp);
144
John Otken9aa36772007-07-26 17:49:11 +0200145 lcd_puts(argv[1]);
146
147 return 0;
148}
149
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200150static int do_lcd_putc (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +0200151{
Wolfgang Denk3b683112010-07-17 01:06:04 +0200152 if (argc < 2)
153 return cmd_usage(cmdtp);
154
John Otken9aa36772007-07-26 17:49:11 +0200155 lcd_putc((char)argv[1][0]);
156
157 return 0;
158}
159
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200160static int do_lcd_cur (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
John Otken9aa36772007-07-26 17:49:11 +0200161{
162 ulong count;
163 ulong dir;
164 char cur_addr;
165
Wolfgang Denk3b683112010-07-17 01:06:04 +0200166 if (argc < 3)
167 return cmd_usage(cmdtp);
John Otken9aa36772007-07-26 17:49:11 +0200168
169 count = simple_strtoul(argv[1], NULL, 16);
170 if (count > 31) {
171 printf("unable to shift > 0x20\n");
172 count = 0;
173 }
174
175 dir = simple_strtoul(argv[2], NULL, 16);
176 cur_addr = in_8((u8 *) LCD_CMD_ADDR);
177 udelay(50);
178
179 if (dir == 0x0) {
180 if (addr_flag == 0x80) {
181 if (count >= (cur_addr & 0xf)) {
182 out_8((u8 *) LCD_CMD_ADDR, 0x80);
183 udelay(50);
184 count = 0;
185 }
186 } else {
187 if (count >= ((cur_addr & 0x0f) + 0x0f)) {
188 out_8((u8 *) LCD_CMD_ADDR, 0x80);
189 addr_flag = 0x80;
190 udelay(50);
191 count = 0x0;
192 } else if (count >= ( cur_addr & 0xf)) {
193 count -= cur_addr & 0xf ;
194 out_8((u8 *) LCD_CMD_ADDR, 0x80 | 0xf);
195 addr_flag = 0x80;
196 udelay(50);
197 }
198 }
199 } else {
200 if (addr_flag == 0x80) {
201 if (count >= (0x1f - (cur_addr & 0xf))) {
202 count = 0x0;
203 addr_flag = 0xc0;
204 out_8((u8 *) LCD_CMD_ADDR, 0xc0 | 0xf);
205 udelay(50);
206 } else if ((count + (cur_addr & 0xf ))>= 0x0f) {
207 count = count + (cur_addr & 0xf) - 0x0f;
208 addr_flag = 0xc0;
209 out_8((u8 *) LCD_CMD_ADDR, 0xc0);
210 udelay(50);
211 }
212 } else if ((count + (cur_addr & 0xf )) >= 0x0f) {
213 count = 0x0;
214 out_8((u8 *) LCD_CMD_ADDR, 0xC0 | 0x0F);
215 udelay(50);
216 }
217 }
218 while (count--) {
219 if (dir == 0)
220 out_8((u8 *) LCD_CMD_ADDR, 0x10);
221 else
222 out_8((u8 *) LCD_CMD_ADDR, 0x14);
223 udelay(50);
224 }
225
226 return 0;
227}
228
229U_BOOT_CMD(
230 lcd_cls, 1, 1, do_lcd_clear,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600231 "lcd clear display",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200232 ""
233);
John Otken9aa36772007-07-26 17:49:11 +0200234
235U_BOOT_CMD(
236 lcd_puts, 2, 1, do_lcd_puts,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600237 "display string on lcd",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200238 "<string> - <string> to be displayed"
239);
John Otken9aa36772007-07-26 17:49:11 +0200240
241U_BOOT_CMD(
242 lcd_putc, 2, 1, do_lcd_putc,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600243 "display char on lcd",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200244 "<char> - <char> to be displayed"
245);
John Otken9aa36772007-07-26 17:49:11 +0200246
247U_BOOT_CMD(
248 lcd_cur, 3, 1, do_lcd_cur,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600249 "shift cursor on lcd",
John Otken9aa36772007-07-26 17:49:11 +0200250 "<count> <dir> - shift cursor on lcd <count> times, direction is <dir> \n"
251 " <count> - 0..31\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200252 " <dir> - 0=backward 1=forward"
253);