3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #define LCD_DELAY_NORMAL_US 100
33 #define LCD_DELAY_NORMAL_MS 2
34 #define LCD_CMD_ADDR ((volatile char *)(CONFIG_SYS_EBC2_LCM_BASE))
35 #define LCD_DATA_ADDR ((volatile char *)(CONFIG_SYS_EBC2_LCM_BASE+1))
36 #define LCD_BLK_CTRL ((volatile char *)(CONFIG_SYS_EBC1_FPGA_BASE+0x2))
38 #define mdelay(t) ({unsigned long msec=(t); while (msec--) { udelay(1000);}})
40 static int g_lcd_init_b
= 0;
41 static char *amcc_logo
= " AMCC TAISHAN 440GX EvalBoard";
42 static char addr_flag
= 0x80;
44 static void lcd_bl_ctrl(char val
)
48 cpld_val
= *LCD_BLK_CTRL
;
49 *LCD_BLK_CTRL
= val
| cpld_val
;
52 static void lcd_putc(char val
)
58 if ((*LCD_CMD_ADDR
& 0x80) != 0x80) { /*BF = 1 ? */
59 udelay(LCD_DELAY_NORMAL_US
);
62 udelay(LCD_DELAY_NORMAL_US
);
65 if (*LCD_CMD_ADDR
& 0x80) {
66 printf("LCD is busy\n");
71 udelay(LCD_DELAY_NORMAL_US
);
72 if ((addr
!= 0) && (addr
% 0x10 == 0)) {
74 *LCD_CMD_ADDR
= addr_flag
;
77 udelay(LCD_DELAY_NORMAL_US
);
79 udelay(LCD_DELAY_NORMAL_US
);
82 static void lcd_puts(char *s
)
88 if ((*LCD_CMD_ADDR
& 0x80) != 0x80) { /*BF = 1 ? */
89 udelay(LCD_DELAY_NORMAL_US
);
92 udelay(LCD_DELAY_NORMAL_US
);
95 if (*LCD_CMD_ADDR
& 0x80) {
96 printf("LCD is busy\n");
104 static void lcd_put_logo(void)
110 if ((*LCD_CMD_ADDR
& 0x80) != 0x80) { /*BF = 1 ? */
111 udelay(LCD_DELAY_NORMAL_US
);
114 udelay(LCD_DELAY_NORMAL_US
);
117 if (*LCD_CMD_ADDR
& 0x80) {
118 printf("LCD is busy\n");
122 *LCD_CMD_ADDR
= 0x80;
129 if (g_lcd_init_b
== 0) {
131 mdelay(100); /* Waiting for the LCD initialize */
133 *LCD_CMD_ADDR
= 0x38; /*set function:8-bit,2-line,5x7 font type */
134 udelay(LCD_DELAY_NORMAL_US
);
136 *LCD_CMD_ADDR
= 0x0f; /*set display on,cursor on,blink on */
137 udelay(LCD_DELAY_NORMAL_US
);
139 *LCD_CMD_ADDR
= 0x01; /*display clear */
140 mdelay(LCD_DELAY_NORMAL_MS
);
142 *LCD_CMD_ADDR
= 0x06; /*set entry */
143 udelay(LCD_DELAY_NORMAL_US
);
155 static int do_lcd_test(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
161 static int do_lcd_clear(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
163 *LCD_CMD_ADDR
= 0x01;
164 mdelay(LCD_DELAY_NORMAL_MS
);
167 static int do_lcd_puts(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
170 printf("%s", cmdtp
->usage
);
176 static int do_lcd_putc(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
179 printf("%s", cmdtp
->usage
);
182 lcd_putc((char)argv
[1][0]);
185 static int do_lcd_cur(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
192 printf("%s", cmdtp
->usage
);
196 count
= simple_strtoul(argv
[1], NULL
, 16);
198 printf("unable to shift > 0x20\n");
202 dir
= simple_strtoul(argv
[2], NULL
, 16);
203 cur_addr
= *LCD_CMD_ADDR
;
204 udelay(LCD_DELAY_NORMAL_US
);
206 if (addr_flag
== 0x80) {
207 if (count
>= (cur_addr
& 0xf)) {
208 *LCD_CMD_ADDR
= 0x80;
209 udelay(LCD_DELAY_NORMAL_US
);
213 if (count
>= ((cur_addr
& 0x0f) + 0x0f)) {
214 *LCD_CMD_ADDR
= 0x80;
216 udelay(LCD_DELAY_NORMAL_US
);
218 } else if (count
>= (cur_addr
& 0xf)) {
219 count
-= cur_addr
& 0xf;
220 *LCD_CMD_ADDR
= 0x80 | 0xf;
222 udelay(LCD_DELAY_NORMAL_US
);
226 if (addr_flag
== 0x80) {
227 if (count
>= (0x1f - (cur_addr
& 0xf))) {
230 *LCD_CMD_ADDR
= 0xc0 | 0xf;
231 udelay(LCD_DELAY_NORMAL_US
);
232 } else if ((count
+ (cur_addr
& 0xf)) >= 0x0f) {
233 count
= count
+ (cur_addr
& 0xf) - 0x0f;
235 *LCD_CMD_ADDR
= 0xc0;
236 udelay(LCD_DELAY_NORMAL_US
);
238 } else if ((count
+ (cur_addr
& 0xf)) >= 0x0f) {
240 *LCD_CMD_ADDR
= 0xc0 | 0xf;
241 udelay(LCD_DELAY_NORMAL_US
);
247 *LCD_CMD_ADDR
= 0x10;
249 *LCD_CMD_ADDR
= 0x14;
251 udelay(LCD_DELAY_NORMAL_US
);
257 U_BOOT_CMD(lcd_test
, 1, 1, do_lcd_test
, "lcd_test - lcd test display\n", NULL
);
258 U_BOOT_CMD(lcd_cls
, 1, 1, do_lcd_clear
, "lcd_cls - lcd clear display\n", NULL
);
259 U_BOOT_CMD(lcd_puts
, 2, 1, do_lcd_puts
,
260 "lcd_puts - display string on lcd\n",
261 "<string> - <string> to be displayed\n");
262 U_BOOT_CMD(lcd_putc
, 2, 1, do_lcd_putc
,
263 "lcd_putc - display char on lcd\n",
264 "<char> - <char> to be displayed\n");
265 U_BOOT_CMD(lcd_cur
, 3, 1, do_lcd_cur
,
266 "lcd_cur - shift cursor on lcd\n",
267 "<count> <dir>- shift cursor on lcd <count> times, direction is <dir> \n"
268 " <count> - 0~31\n" " <dir> - 0,backward; 1, forward\n");
270 #if 0 /* test-only */
271 void set_phy_loopback_mode(void)
276 sprintf(devemac2
, "%s2", CONFIG_EMAC_DEV_NAME
);
277 sprintf(devemac3
, "%s3", CONFIG_EMAC_DEV_NAME
);
280 unsigned short reg_short
;
282 miiphy_read(devemac2
, 0x1, 1, ®_short
);
283 if (reg_short
& 0x04) {
285 * printf("EMAC2 link up,do nothing\n");
289 miiphy_write(devemac2
, 0x1, 0, 0x6000);
291 miiphy_read(devemac2
, 0x1, 0, ®_short
);
292 if (reg_short
!= 0x6000) {
294 ("\nEMAC2 error set LOOPBACK mode error,reg2[0]=%x\n",
299 miiphy_read(devemac3
, 0x3, 1, ®_short
);
300 if (reg_short
& 0x04) {
302 * printf("EMAC3 link up,do nothing\n");
306 miiphy_write(devemac3
, 0x3, 0, 0x6000);
308 miiphy_read(devemac3
, 0x3, 0, ®_short
);
309 if (reg_short
!= 0x6000) {
311 ("\nEMAC3 error set LOOPBACK mode error,reg2[0]=%x\n",
316 /* Set PHY as LOOPBACK MODE, for Linux emac initializing */
317 miiphy_write(devemac2
, CONFIG_PHY2_ADDR
, 0, 0x6000);
319 miiphy_write(devemac3
, CONFIG_PHY3_ADDR
, 0, 0x6000);
324 void set_phy_normal_mode(void)
328 unsigned short reg_short
;
330 sprintf(devemac2
, "%s2", CONFIG_EMAC_DEV_NAME
);
331 sprintf(devemac3
, "%s3", CONFIG_EMAC_DEV_NAME
);
333 /* Set phy of EMAC2 */
334 miiphy_read(devemac2
, CONFIG_PHY2_ADDR
, 0x16, ®_short
);
336 reg_short
|= 0x6; /* RGMII DLL Delay */
337 miiphy_write(devemac2
, CONFIG_PHY2_ADDR
, 0x16, reg_short
);
339 miiphy_read(devemac2
, CONFIG_PHY2_ADDR
, 0x17, ®_short
);
340 reg_short
&= ~(0x40);
341 miiphy_write(devemac2
, CONFIG_PHY2_ADDR
, 0x17, reg_short
);
343 miiphy_write(devemac2
, CONFIG_PHY2_ADDR
, 0x1c, 0x74f0);
345 /* Set phy of EMAC3 */
346 miiphy_read(devemac3
, CONFIG_PHY3_ADDR
, 0x16, ®_short
);
348 reg_short
|= 0x6; /* RGMII DLL Delay */
349 miiphy_write(devemac3
, CONFIG_PHY3_ADDR
, 0x16, reg_short
);
351 miiphy_read(devemac3
, CONFIG_PHY3_ADDR
, 0x17, ®_short
);
352 reg_short
&= ~(0x40);
353 miiphy_write(devemac3
, CONFIG_PHY3_ADDR
, 0x17, reg_short
);
355 miiphy_write(devemac3
, CONFIG_PHY3_ADDR
, 0x1c, 0x74f0);
357 #endif /* 0 - test only */
359 static int do_led_test_off(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
361 volatile unsigned int *GpioOr
=
362 (volatile unsigned int *)(CONFIG_SYS_PERIPHERAL_BASE
+ 0x700);
363 *GpioOr
|= 0x00300000;
367 static int do_led_test_on(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
369 volatile unsigned int *GpioOr
=
370 (volatile unsigned int *)(CONFIG_SYS_PERIPHERAL_BASE
+ 0x700);
371 *GpioOr
&= ~0x00300000;
375 U_BOOT_CMD(ledon
, 1, 1, do_led_test_on
,
376 "ledon - led test light on\n", NULL
);
378 U_BOOT_CMD(ledoff
, 1, 1, do_led_test_off
,
379 "ledoff - led test light off\n", NULL
);