3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
16 #define LCD_DELAY_NORMAL_US 100
17 #define LCD_DELAY_NORMAL_MS 2
18 #define LCD_CMD_ADDR ((volatile char *)(CONFIG_SYS_EBC2_LCM_BASE))
19 #define LCD_DATA_ADDR ((volatile char *)(CONFIG_SYS_EBC2_LCM_BASE+1))
20 #define LCD_BLK_CTRL ((volatile char *)(CONFIG_SYS_EBC1_FPGA_BASE+0x2))
22 static int g_lcd_init_b = 0;
23 static char *amcc_logo = " AMCC TAISHAN 440GX EvalBoard";
24 static char addr_flag = 0x80;
26 static void lcd_bl_ctrl(char val)
30 cpld_val = *LCD_BLK_CTRL;
31 *LCD_BLK_CTRL = val | cpld_val;
34 static void lcd_putc(char val)
40 if ((*LCD_CMD_ADDR & 0x80) != 0x80) { /*BF = 1 ? */
41 udelay(LCD_DELAY_NORMAL_US);
44 udelay(LCD_DELAY_NORMAL_US);
47 if (*LCD_CMD_ADDR & 0x80) {
48 printf("LCD is busy\n");
53 udelay(LCD_DELAY_NORMAL_US);
54 if ((addr != 0) && (addr % 0x10 == 0)) {
56 *LCD_CMD_ADDR = addr_flag;
59 udelay(LCD_DELAY_NORMAL_US);
61 udelay(LCD_DELAY_NORMAL_US);
64 static void lcd_puts(char *s)
70 if ((*LCD_CMD_ADDR & 0x80) != 0x80) { /*BF = 1 ? */
71 udelay(LCD_DELAY_NORMAL_US);
74 udelay(LCD_DELAY_NORMAL_US);
77 if (*LCD_CMD_ADDR & 0x80) {
78 printf("LCD is busy\n");
86 static void lcd_put_logo(void)
92 if ((*LCD_CMD_ADDR & 0x80) != 0x80) { /*BF = 1 ? */
93 udelay(LCD_DELAY_NORMAL_US);
96 udelay(LCD_DELAY_NORMAL_US);
99 if (*LCD_CMD_ADDR & 0x80) {
100 printf("LCD is busy\n");
104 *LCD_CMD_ADDR = 0x80;
111 if (g_lcd_init_b == 0) {
113 mdelay(100); /* Waiting for the LCD initialize */
115 *LCD_CMD_ADDR = 0x38; /*set function:8-bit,2-line,5x7 font type */
116 udelay(LCD_DELAY_NORMAL_US);
118 *LCD_CMD_ADDR = 0x0f; /*set display on,cursor on,blink on */
119 udelay(LCD_DELAY_NORMAL_US);
121 *LCD_CMD_ADDR = 0x01; /*display clear */
122 mdelay(LCD_DELAY_NORMAL_MS);
124 *LCD_CMD_ADDR = 0x06; /*set entry */
125 udelay(LCD_DELAY_NORMAL_US);
137 static int do_lcd_test(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
143 static int do_lcd_clear(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
145 *LCD_CMD_ADDR = 0x01;
146 mdelay(LCD_DELAY_NORMAL_MS);
149 static int do_lcd_puts(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
152 return cmd_usage(cmdtp);
157 static int do_lcd_putc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
160 return cmd_usage(cmdtp);
162 lcd_putc((char)argv[1][0]);
165 static int do_lcd_cur(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
172 return cmd_usage(cmdtp);
174 count = simple_strtoul(argv[1], NULL, 16);
176 printf("unable to shift > 0x20\n");
180 dir = simple_strtoul(argv[2], NULL, 16);
181 cur_addr = *LCD_CMD_ADDR;
182 udelay(LCD_DELAY_NORMAL_US);
184 if (addr_flag == 0x80) {
185 if (count >= (cur_addr & 0xf)) {
186 *LCD_CMD_ADDR = 0x80;
187 udelay(LCD_DELAY_NORMAL_US);
191 if (count >= ((cur_addr & 0x0f) + 0x0f)) {
192 *LCD_CMD_ADDR = 0x80;
194 udelay(LCD_DELAY_NORMAL_US);
196 } else if (count >= (cur_addr & 0xf)) {
197 count -= cur_addr & 0xf;
198 *LCD_CMD_ADDR = 0x80 | 0xf;
200 udelay(LCD_DELAY_NORMAL_US);
204 if (addr_flag == 0x80) {
205 if (count >= (0x1f - (cur_addr & 0xf))) {
208 *LCD_CMD_ADDR = 0xc0 | 0xf;
209 udelay(LCD_DELAY_NORMAL_US);
210 } else if ((count + (cur_addr & 0xf)) >= 0x0f) {
211 count = count + (cur_addr & 0xf) - 0x0f;
213 *LCD_CMD_ADDR = 0xc0;
214 udelay(LCD_DELAY_NORMAL_US);
216 } else if ((count + (cur_addr & 0xf)) >= 0x0f) {
218 *LCD_CMD_ADDR = 0xc0 | 0xf;
219 udelay(LCD_DELAY_NORMAL_US);
225 *LCD_CMD_ADDR = 0x10;
227 *LCD_CMD_ADDR = 0x14;
229 udelay(LCD_DELAY_NORMAL_US);
235 U_BOOT_CMD(lcd_test, 1, 1, do_lcd_test, "lcd test display", "");
236 U_BOOT_CMD(lcd_cls, 1, 1, do_lcd_clear, "lcd clear display", "");
237 U_BOOT_CMD(lcd_puts, 2, 1, do_lcd_puts,
238 "display string on lcd",
239 "<string> - <string> to be displayed");
240 U_BOOT_CMD(lcd_putc, 2, 1, do_lcd_putc,
241 "display char on lcd",
242 "<char> - <char> to be displayed");
243 U_BOOT_CMD(lcd_cur, 3, 1, do_lcd_cur,
244 "shift cursor on lcd",
245 "<count> <dir>- shift cursor on lcd <count> times, direction is <dir> \n"
246 " <count> - 0~31\n" " <dir> - 0,backward; 1, forward");
248 #if 0 /* test-only */
249 void set_phy_loopback_mode(void)
254 sprintf(devemac2, "%s2", CONFIG_EMAC_DEV_NAME);
255 sprintf(devemac3, "%s3", CONFIG_EMAC_DEV_NAME);
258 unsigned short reg_short;
260 miiphy_read(devemac2, 0x1, 1, ®_short);
261 if (reg_short & 0x04) {
263 * printf("EMAC2 link up,do nothing\n");
267 miiphy_write(devemac2, 0x1, 0, 0x6000);
269 miiphy_read(devemac2, 0x1, 0, ®_short);
270 if (reg_short != 0x6000) {
272 ("\nEMAC2 error set LOOPBACK mode error,reg2[0]=%x\n",
277 miiphy_read(devemac3, 0x3, 1, ®_short);
278 if (reg_short & 0x04) {
280 * printf("EMAC3 link up,do nothing\n");
284 miiphy_write(devemac3, 0x3, 0, 0x6000);
286 miiphy_read(devemac3, 0x3, 0, ®_short);
287 if (reg_short != 0x6000) {
289 ("\nEMAC3 error set LOOPBACK mode error,reg2[0]=%x\n",
294 /* Set PHY as LOOPBACK MODE, for Linux emac initializing */
295 miiphy_write(devemac2, CONFIG_PHY2_ADDR, 0, 0x6000);
297 miiphy_write(devemac3, CONFIG_PHY3_ADDR, 0, 0x6000);
302 void set_phy_normal_mode(void)
306 unsigned short reg_short;
308 sprintf(devemac2, "%s2", CONFIG_EMAC_DEV_NAME);
309 sprintf(devemac3, "%s3", CONFIG_EMAC_DEV_NAME);
311 /* Set phy of EMAC2 */
312 miiphy_read(devemac2, CONFIG_PHY2_ADDR, 0x16, ®_short);
314 reg_short |= 0x6; /* RGMII DLL Delay */
315 miiphy_write(devemac2, CONFIG_PHY2_ADDR, 0x16, reg_short);
317 miiphy_read(devemac2, CONFIG_PHY2_ADDR, 0x17, ®_short);
318 reg_short &= ~(0x40);
319 miiphy_write(devemac2, CONFIG_PHY2_ADDR, 0x17, reg_short);
321 miiphy_write(devemac2, CONFIG_PHY2_ADDR, 0x1c, 0x74f0);
323 /* Set phy of EMAC3 */
324 miiphy_read(devemac3, CONFIG_PHY3_ADDR, 0x16, ®_short);
326 reg_short |= 0x6; /* RGMII DLL Delay */
327 miiphy_write(devemac3, CONFIG_PHY3_ADDR, 0x16, reg_short);
329 miiphy_read(devemac3, CONFIG_PHY3_ADDR, 0x17, ®_short);
330 reg_short &= ~(0x40);
331 miiphy_write(devemac3, CONFIG_PHY3_ADDR, 0x17, reg_short);
333 miiphy_write(devemac3, CONFIG_PHY3_ADDR, 0x1c, 0x74f0);
335 #endif /* 0 - test only */
337 static int do_led_test_off(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
339 volatile unsigned int *GpioOr =
340 (volatile unsigned int *)(CONFIG_SYS_PERIPHERAL_BASE + 0x700);
341 *GpioOr |= 0x00300000;
345 static int do_led_test_on(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
347 volatile unsigned int *GpioOr =
348 (volatile unsigned int *)(CONFIG_SYS_PERIPHERAL_BASE + 0x700);
349 *GpioOr &= ~0x00300000;
353 U_BOOT_CMD(ledon, 1, 1, do_led_test_on,
354 "led test light on", "");
356 U_BOOT_CMD(ledoff, 1, 1, do_led_test_off,
357 "led test light off", "");